ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
RevisionRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
20 
21 require_once(__DIR__ . "/../AbstractTestBase.php");
22 
27 
33 {
37  public $resource;
41  private $info_resolver;
42 
43  protected function setUp(): void
44  {
45  parent::setUp();
46  $this->info_resolver = $this->createMock(InfoResolver::class);
47  $this->resource = new StorableFileResource($this->id_generator->getUniqueResourceIdentification());
48  }
49 
50  public function testUpload(): void
51  {
52  $upload_result = $this->getDummyUploadResult(
53  'info.xml',
54  'text/xml',
55  128
56  );
57 
58  $this->info_resolver->expects($this->once())
59  ->method('getNextVersionNumber')
60  ->willReturn(100);
61 
62  $ar_revision_repo = new RevisionDBRepository($this->db_mock);
63  $revision = $ar_revision_repo->blankFromUpload(
64  $this->info_resolver,
65  $this->resource,
66  $upload_result,
68  );
69 
70  $this->assertEquals(100, $revision->getVersionNumber());
71  $this->assertEquals(RevisionStatus::DRAFT, $revision->getStatus());
72  }
73 
74  public function testStream(): void
75  {
76  $stream = $this->getDummyStream();
77  $i = random_int(0, mt_getrandmax());
78 
79  $this->info_resolver->expects($this->once())
80  ->method('getNextVersionNumber')
81  ->willReturn($i);
82 
83  $ar_revision_repo = new RevisionDBRepository($this->db_mock);
84  $revision = $ar_revision_repo->blankFromStream(
85  $this->info_resolver,
86  $this->resource,
87  $stream,
88  RevisionStatus::PUBLISHED
89  );
90 
91  $this->assertEquals($i, $revision->getVersionNumber());
92  }
93 
94  public function testClone(): void
95  {
96  $revision = $this->getDummyFileRevision($this->id_generator->getUniqueResourceIdentification());
97  $old_revisions_id = 99;
98  $revision->setVersionNumber($old_revisions_id);
99 
100  $i = 50;
101  $this->info_resolver->expects($this->once())
102  ->method('getNextVersionNumber')
103  ->willReturn($i);
104 
105  $ar_revision_repo = new RevisionDBRepository($this->db_mock);
106  $revision = $ar_revision_repo->blankFromClone(
107  $this->info_resolver,
108  $this->resource,
109  $revision
110  );
111 
112  $this->assertEquals($i, $revision->getVersionNumber());
113  $this->assertNotEquals($old_revisions_id, $revision->getVersionNumber());
114  }
115 }
getDummyUploadResult(string $file_name, string $mime_type, int $size)
getDummyFileRevision(ResourceIdentification $id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...