ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CopyrightTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
32use PHPUnit\Framework\MockObject\MockObject;
35use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount;
37
38class CopyrightTest extends TestCase
39{
40 protected function getLegacyComponent(): MockObject|Content
41 {
42 return $this->getMockBuilder(ILegacy::class)
43 ->disableOriginalConstructor()
44 ->getMock();
45 }
46
47 protected function getRenderer(): RendererInterface
48 {
49 $legacy_component = $this->getLegacyComponent();
50 return new class ($legacy_component, $this->any()) extends NullRenderer {
51 public ?string $exposed_copyright_data = null;
52
53 public function __construct(
54 protected MockObject|Content $legacy,
55 protected AnyInvokedCount $any
56 ) {
57 }
58
59 public function toUIComponents(CopyrightDataInterface $copyright): array
60 {
61 $this->exposed_copyright_data = $copyright->exposed_data;
62 return [$this->legacy];
63 }
64
65 public function toString(CopyrightDataInterface $copyright): string
66 {
67 return $copyright->exposed_data;
68 }
69 };
70 }
71
72 protected function getIdentifierHandler(): IdentifierHandler
73 {
74 return new class () extends NullHandler {
75 public function buildIdentifierFromEntryID(int $entry_id): string
76 {
77 return 'identifier_' . $entry_id;
78 }
79 };
80 }
81
82 protected function getEntry(
83 bool $is_default,
84 bool $is_outdated,
85 int $id,
86 string $title,
87 string $description,
88 string $cp_data
90 return new class ($is_default, $is_outdated, $id, $title, $description, $cp_data) extends NullEntry {
91 public function __construct(
92 protected bool $is_default,
93 protected bool $is_outdated,
94 protected int $id,
95 protected string $title,
96 protected string $description,
97 protected string $cp_data
98 ) {
99 }
100
101 public function id(): int
102 {
103 return $this->id;
104 }
105
106 public function title(): string
107 {
108 return $this->title;
109 }
110
111 public function description(): string
112 {
113 return $this->description;
114 }
115
116 public function isDefault(): bool
117 {
118 return $this->is_default;
119 }
120
121 public function isOutdated(): bool
122 {
123 return $this->is_outdated;
124 }
125
126 public function copyrightData(): CopyrightDataInterface
127 {
128 return new class ($this->cp_data) extends NullCopyrightData {
129 public function __construct(public string $exposed_data)
130 {
131 }
132 };
133 }
134 };
135 }
136
137 public function testIsDefaultTrue(): void
138 {
139 $copyright = new Copyright(
140 $this->getRenderer(),
141 $this->getIdentifierHandler(),
142 $this->getEntry(
143 true,
144 false,
145 35,
146 'cp title',
147 'cp description',
148 'data of copyright'
149 )
150 );
151
152 $this->assertTrue($copyright->isDefault());
153 }
154
155 public function testIsDefaultFalse(): void
156 {
157 $copyright = new Copyright(
158 $this->getRenderer(),
159 $this->getIdentifierHandler(),
160 $this->getEntry(
161 false,
162 false,
163 35,
164 'cp title',
165 'cp description',
166 'data of copyright'
167 )
168 );
169
170 $this->assertFalse($copyright->isDefault());
171 }
172
173 public function testIsOutdatedTrue(): void
174 {
175 $copyright = new Copyright(
176 $this->getRenderer(),
177 $this->getIdentifierHandler(),
178 $this->getEntry(
179 false,
180 true,
181 35,
182 'cp title',
183 'cp description',
184 'data of copyright'
185 )
186 );
187
188 $this->assertTrue($copyright->isOutdated());
189 }
190
191 public function testIsOutdatedFalse(): void
192 {
193 $copyright = new Copyright(
194 $this->getRenderer(),
195 $this->getIdentifierHandler(),
196 $this->getEntry(
197 false,
198 false,
199 35,
200 'cp title',
201 'cp description',
202 'data of copyright'
203 )
204 );
205
206 $this->assertFalse($copyright->isOutdated());
207 }
208
209 public function testIdentifier(): void
210 {
211 $copyright = new Copyright(
212 $this->getRenderer(),
213 $this->getIdentifierHandler(),
214 $this->getEntry(
215 false,
216 false,
217 35,
218 'cp title',
219 'cp description',
220 'data of copyright'
221 )
222 );
223
224 $this->assertSame('identifier_35', $copyright->identifier());
225 }
226
227 public function testTitle(): void
228 {
229 $copyright = new Copyright(
230 $this->getRenderer(),
231 $this->getIdentifierHandler(),
232 $this->getEntry(
233 false,
234 false,
235 35,
236 'cp title',
237 'cp description',
238 'data of copyright'
239 )
240 );
241
242 $this->assertSame('cp title', $copyright->title());
243 }
244
245 public function testDescription(): void
246 {
247 $copyright = new Copyright(
248 $this->getRenderer(),
249 $this->getIdentifierHandler(),
250 $this->getEntry(
251 false,
252 false,
253 35,
254 'cp title',
255 'cp description',
256 'data of copyright'
257 )
258 );
259
260 $this->assertSame('cp description', $copyright->description());
261 }
262
263 public function testPresentAsUIComponents(): void
264 {
265 $renderer = $this->getRenderer();
266 $copyright = new Copyright(
267 $renderer,
268 $this->getIdentifierHandler(),
269 $this->getEntry(
270 false,
271 false,
272 35,
273 'cp title',
274 'cp description',
275 'data of copyright'
276 )
277 );
278
279 $components = $copyright->presentAsUIComponents();
280
281 $this->assertCount(1, $components);
283 $this->assertSame('data of copyright', $renderer->exposed_copyright_data);
284 }
285
286 public function testPresentAsString(): void
287 {
288 $copyright = new Copyright(
289 $this->getRenderer(),
290 $this->getIdentifierHandler(),
291 $this->getEntry(
292 false,
293 false,
294 35,
295 'cp title',
296 'cp description',
297 'data of copyright'
298 )
299 );
300
301 $this->assertSame('data of copyright', $copyright->presentAsString());
302 }
303}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
$renderer
__construct(SettingsInterface $settings, PathFactory $path_factory, CopyrightRepository $copyright_repo, IdentifierHandler $identifier_handler, RendererInterface $renderer, SearchClauseFactory $search_clause_factory)
getEntry(bool $is_default, bool $is_outdated, int $id, string $title, string $description, string $cp_data)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...