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