ILIAS  release_8 Revision v8.24
RevisionRepositoryTest.php
Go to the documentation of this file.
1<?php
2
20
25
31{
35 public $resource;
39 private \PHPUnit\Framework\MockObject\MockObject $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
65 );
66
67 $this->assertEquals(100, $revision->getVersionNumber());
68 }
69
70 public function testStream(): void
71 {
72 $stream = $this->getDummyStream();
73 $i = random_int(0, mt_getrandmax());
74
75 $this->info_resolver->expects($this->once())
76 ->method('getNextVersionNumber')
77 ->willReturn($i);
78
79 $ar_revision_repo = new RevisionDBRepository($this->db_mock);
80 $revision = $ar_revision_repo->blankFromStream(
81 $this->info_resolver,
82 $this->resource,
83 $stream
84 );
85
86 $this->assertEquals($i, $revision->getVersionNumber());
87 }
88
89 public function testClone(): void
90 {
91 $revision = $this->getDummyFileRevision($this->id_generator->getUniqueResourceIdentification());
92 $old_revisions_id = 99;
93 $revision->setVersionNumber($old_revisions_id);
94
95 $i = 50;
96 $this->info_resolver->expects($this->once())
97 ->method('getNextVersionNumber')
98 ->willReturn($i);
99
100 $ar_revision_repo = new RevisionDBRepository($this->db_mock);
101 $revision = $ar_revision_repo->blankFromClone(
102 $this->info_resolver,
103 $this->resource,
104 $revision
105 );
106
107 $this->assertEquals($i, $revision->getVersionNumber());
108 $this->assertNotEquals($old_revisions_id, $revision->getVersionNumber());
109 }
110}
getDummyUploadResult(string $file_name, string $mime_type, int $size)
getDummyFileRevision(ResourceIdentification $id)
PHPUnit Framework MockObject MockObject $info_resolver
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...