ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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;
40
41class CopyrightTest extends TestCase
42{
43 protected function getIcon(): Icon
44 {
45 return $this->getMockBuilder(IIcon::class)
46 ->disableOriginalConstructor()
47 ->getMock();
48 }
49
50 protected function getLink(): Link
51 {
52 return $this->getMockBuilder(ILink::class)
53 ->disableOriginalConstructor()
54 ->getMock();
55 }
56
57 protected function getRenderer(
58 ?Icon $icon = null,
59 ?Link $link = null
61 return new class ($icon, $link) extends NullRenderer {
62 public ?string $exposed_copyright_data = null;
63
64 public function __construct(
65 protected ?Icon $icon,
66 protected ?Link $link
67 ) {
68 }
69
70 public function toUIComponents(CopyrightDataInterface $copyright): array
71 {
72 $this->exposed_copyright_data = $copyright->exposed_data;
73 $res = [];
74 if ($this->icon !== null) {
75 $res[] = $this->icon;
76 }
77 if ($this->link !== null) {
78 $res[] = $this->link;
79 }
80 return $res;
81 }
82
83 public function toImageOnly(CopyrightDataInterface $copyright): ?Icon
84 {
85 $this->exposed_copyright_data = $copyright->exposed_data;
86 return $this->icon;
87 }
88
89 public function toLinkOnly(CopyrightDataInterface $copyright): ?Link
90 {
91 $this->exposed_copyright_data = $copyright->exposed_data;
92 return $this->link;
93 }
94
95 public function toString(CopyrightDataInterface $copyright): string
96 {
97 return $copyright->exposed_data;
98 }
99 };
100 }
101
102 protected function getIdentifierHandler(): IdentifierHandler
103 {
104 return new class () extends NullHandler {
105 public function buildIdentifierFromEntryID(int $entry_id): string
106 {
107 return 'identifier_' . $entry_id;
108 }
109 };
110 }
111
112 protected function getEntry(
113 bool $is_default,
114 bool $is_outdated,
115 int $id,
116 string $title,
117 string $description,
118 string $cp_data
119 ): EntryInterface {
120 return new class ($is_default, $is_outdated, $id, $title, $description, $cp_data) extends NullEntry {
121 public function __construct(
122 protected bool $is_default,
123 protected bool $is_outdated,
124 protected int $id,
125 protected string $title,
126 protected string $description,
127 protected string $cp_data
128 ) {
129 }
130
131 public function id(): int
132 {
133 return $this->id;
134 }
135
136 public function title(): string
137 {
138 return $this->title;
139 }
140
141 public function description(): string
142 {
143 return $this->description;
144 }
145
146 public function isDefault(): bool
147 {
148 return $this->is_default;
149 }
150
151 public function isOutdated(): bool
152 {
153 return $this->is_outdated;
154 }
155
156 public function copyrightData(): CopyrightDataInterface
157 {
158 return new class ($this->cp_data) extends NullCopyrightData {
159 public function __construct(public string $exposed_data)
160 {
161 }
162 };
163 }
164 };
165 }
166
167 public function testIsDefaultTrue(): void
168 {
169 $copyright = new Copyright(
170 $this->getRenderer(),
171 $this->getIdentifierHandler(),
172 $this->getEntry(
173 true,
174 false,
175 35,
176 'cp title',
177 'cp description',
178 'data of copyright'
179 )
180 );
181
182 $this->assertTrue($copyright->isDefault());
183 }
184
185 public function testIsDefaultFalse(): void
186 {
187 $copyright = new Copyright(
188 $this->getRenderer(),
189 $this->getIdentifierHandler(),
190 $this->getEntry(
191 false,
192 false,
193 35,
194 'cp title',
195 'cp description',
196 'data of copyright'
197 )
198 );
199
200 $this->assertFalse($copyright->isDefault());
201 }
202
203 public function testIsOutdatedTrue(): void
204 {
205 $copyright = new Copyright(
206 $this->getRenderer(),
207 $this->getIdentifierHandler(),
208 $this->getEntry(
209 false,
210 true,
211 35,
212 'cp title',
213 'cp description',
214 'data of copyright'
215 )
216 );
217
218 $this->assertTrue($copyright->isOutdated());
219 }
220
221 public function testIsOutdatedFalse(): void
222 {
223 $copyright = new Copyright(
224 $this->getRenderer(),
225 $this->getIdentifierHandler(),
226 $this->getEntry(
227 false,
228 false,
229 35,
230 'cp title',
231 'cp description',
232 'data of copyright'
233 )
234 );
235
236 $this->assertFalse($copyright->isOutdated());
237 }
238
239 public function testIdentifier(): void
240 {
241 $copyright = new Copyright(
242 $this->getRenderer(),
243 $this->getIdentifierHandler(),
244 $this->getEntry(
245 false,
246 false,
247 35,
248 'cp title',
249 'cp description',
250 'data of copyright'
251 )
252 );
253
254 $this->assertSame('identifier_35', $copyright->identifier());
255 }
256
257 public function testTitle(): void
258 {
259 $copyright = new Copyright(
260 $this->getRenderer(),
261 $this->getIdentifierHandler(),
262 $this->getEntry(
263 false,
264 false,
265 35,
266 'cp title',
267 'cp description',
268 'data of copyright'
269 )
270 );
271
272 $this->assertSame('cp title', $copyright->title());
273 }
274
275 public function testDescription(): void
276 {
277 $copyright = new Copyright(
278 $this->getRenderer(),
279 $this->getIdentifierHandler(),
280 $this->getEntry(
281 false,
282 false,
283 35,
284 'cp title',
285 'cp description',
286 'data of copyright'
287 )
288 );
289
290 $this->assertSame('cp description', $copyright->description());
291 }
292
293 public function testPresentAsUIComponents(): void
294 {
295 $icon = $this->getIcon();
296 $link = $this->getLink();
297 $renderer = $this->getRenderer($icon, $link);
298 $copyright = new Copyright(
299 $renderer,
300 $this->getIdentifierHandler(),
301 $this->getEntry(
302 false,
303 false,
304 35,
305 'cp title',
306 'cp description',
307 'data of copyright'
308 )
309 );
310
311 $components = $copyright->presentAsUIComponents();
312
313 $this->assertCount(2, $components);
314 $this->assertSame($icon, $components[0] ?? null);
315 $this->assertSame($link, $components[1] ?? null);
316 $this->assertSame('data of copyright', $renderer->exposed_copyright_data);
317 }
318
319 public function testPresentAsImageOnly(): void
320 {
321 $icon = $this->getIcon();
322 $renderer = $this->getRenderer($icon);
323 $copyright = new Copyright(
324 $renderer,
325 $this->getIdentifierHandler(),
326 $this->getEntry(
327 false,
328 false,
329 35,
330 'cp title',
331 'cp description',
332 'data of copyright'
333 )
334 );
335
336 $image = $copyright->presentAsImageOnly();
337
338 $this->assertSame($icon, $image);
339 $this->assertSame('data of copyright', $renderer->exposed_copyright_data);
340 }
341
342 public function testPresentAsLinkOnly(): void
343 {
344 $link = $this->getLink();
345 $renderer = $this->getRenderer(null, $link);
346 $copyright = new Copyright(
347 $renderer,
348 $this->getIdentifierHandler(),
349 $this->getEntry(
350 false,
351 false,
352 35,
353 'cp title',
354 'cp description',
355 'data of copyright'
356 )
357 );
358
359 $res_link = $copyright->presentAsLinkOnly();
360
361 $this->assertSame($link, $res_link);
362 $this->assertSame('data of copyright', $renderer->exposed_copyright_data);
363 }
364
365 public function testPresentAsString(): void
366 {
367 $copyright = new Copyright(
368 $this->getRenderer(),
369 $this->getIdentifierHandler(),
370 $this->getEntry(
371 false,
372 false,
373 35,
374 'cp title',
375 'cp description',
376 'data of copyright'
377 )
378 );
379
380 $this->assertSame('data of copyright', $copyright->presentAsString());
381 }
382}
$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)
getRenderer(?Icon $icon=null, ?Link $link=null)
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...
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
link(string $caption, string $href, bool $new_viewport=false)