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