ILIAS  release_7 Revision v7.30-3-g800a261c036
RevisionRepositoryTest.php
Go to the documentation of this file.
1<?php
2
4
9
15{
20
21 protected function setUp() : void
22 {
23 parent::setUp();
24 $this->info_resolver = $this->createMock(InfoResolver::class);
25 $this->resource = new StorableFileResource($this->id_generator->getUniqueResourceIdentification());
26 }
27
28 public function testUpload() : void
29 {
30 $upload_result = $this->getDummyUploadResult(
31 'info.xml',
32 'text/xml',
33 128
34 );
35
36 $this->info_resolver->expects($this->once())
37 ->method('getNextVersionNumber')
38 ->willReturn(100);
39
40 $ar_revision_repo = new RevisionDBRepository($this->db_mock);
41 $revision = $ar_revision_repo->blankFromUpload(
42 $this->info_resolver,
43 $this->resource,
44 $upload_result
45 );
46
47 $this->assertEquals(100, $revision->getVersionNumber());
48 }
49
50 public function testStream() : void
51 {
52 $stream = $this->getDummyStream();
53 $i = rand();
54
55 $this->info_resolver->expects($this->once())
56 ->method('getNextVersionNumber')
57 ->willReturn($i);
58
59 $ar_revision_repo = new RevisionDBRepository($this->db_mock);
60 $revision = $ar_revision_repo->blankFromStream(
61 $this->info_resolver,
62 $this->resource,
63 $stream
64 );
65
66 $this->assertEquals($i, $revision->getVersionNumber());
67 }
68
69 public function testClone() : void
70 {
71 $revision = $this->getDummyFileRevision($this->id_generator->getUniqueResourceIdentification());
72 $old_revisions_id = 99;
73 $revision->setVersionNumber($old_revisions_id);
74
75 $i = 50;
76 $this->info_resolver->expects($this->once())
77 ->method('getNextVersionNumber')
78 ->willReturn($i);
79
80 $ar_revision_repo = new RevisionDBRepository($this->db_mock);
81 $revision = $ar_revision_repo->blankFromClone(
82 $this->info_resolver,
83 $this->resource,
84 $revision
85 );
86
87 $this->assertEquals($i, $revision->getVersionNumber());
88 $this->assertNotEquals($old_revisions_id, $revision->getVersionNumber());
89 }
90}
91
An exception for terminatinating execution or to throw for unit testing.
getDummyUploadResult(string $file_name, string $mime_type, int $size)
getDummyFileRevision(ResourceIdentification $id)
$i
Definition: metadata.php:24