ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
GlyphTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
29use ILIAS\Data\Factory as DataFactory;
31use PHPUnit\Framework\Attributes\DataProvider;
32
37{
38 use LanguageStubs;
39
40 public function getGlyphFactory(): G\Factory
41 {
42 return new I\Symbol\Glyph\Factory($this->createRelayArgumentLanguageStub());
43 }
44
45 public function getCounterFactory(): C\Factory
46 {
47 return new I\Counter\Factory();
48 }
49
50 public static array $canonical_css_classes = array(
51 G\Glyph::SETTINGS => "glyphicon glyphicon-cog",
52 G\Glyph::EXPAND => "glyphicon glyphicon-triangle-right",
53 G\Glyph::COLLAPSE => "glyphicon glyphicon-triangle-bottom",
54 G\Glyph::ADD => "glyphicon glyphicon-plus-sign",
55 G\Glyph::REMOVE => "glyphicon glyphicon-minus-sign",
56 G\Glyph::UP => "glyphicon glyphicon-circle-arrow-up",
57 G\Glyph::DOWN => "glyphicon glyphicon-circle-arrow-down",
58 G\Glyph::BACK => "glyphicon glyphicon-chevron-left",
59 G\Glyph::NEXT => "glyphicon glyphicon-chevron-right",
60 G\Glyph::SORT_ASCENDING => "glyphicon glyphicon-arrow-up",
61 G\Glyph::SORT_DESCENDING => "glyphicon glyphicon-arrow-down",
62 G\Glyph::USER => "glyphicon glyphicon-user",
63 G\Glyph::MAIL => "glyphicon glyphicon-envelope",
64 G\Glyph::NOTIFICATION => "glyphicon glyphicon-bell",
65 G\Glyph::TAG => "glyphicon glyphicon-tag",
66 G\Glyph::NOTE => "glyphicon glyphicon-pushpin",
67 G\Glyph::COMMENT => "glyphicon glyphicon-comment",
68 G\Glyph::BRIEFCASE => "glyphicon glyphicon-briefcase",
69 G\Glyph::LIKE => "glyphicon il-glyphicon-like",
70 G\Glyph::LOVE => "glyphicon il-glyphicon-love",
71 G\Glyph::DISLIKE => "glyphicon il-glyphicon-dislike",
72 G\Glyph::LAUGH => "glyphicon il-glyphicon-laugh",
73 G\Glyph::ASTOUNDED => "glyphicon il-glyphicon-astounded",
74 G\Glyph::SAD => "glyphicon il-glyphicon-sad",
75 G\Glyph::ANGRY => "glyphicon il-glyphicon-angry",
76 G\Glyph::EYEOPEN => "glyphicon glyphicon-eye-open",
77 G\Glyph::EYECLOSED => "glyphicon glyphicon-eye-close",
78 G\Glyph::ATTACHMENT => "glyphicon glyphicon-paperclip",
79 G\Glyph::RESET => "glyphicon glyphicon-reset",
80 G\Glyph::APPLY => "glyphicon glyphicon-apply",
81 G\Glyph::SEARCH => "glyphicon glyphicon-search",
82 G\Glyph::HELP => "glyphicon glyphicon-question-sign",
83 G\Glyph::CALENDAR => "glyphicon glyphicon-calendar",
84 G\Glyph::TIME => "glyphicon glyphicon-time",
85 G\Glyph::CLOSE => "glyphicon glyphicon-remove",
86 G\Glyph::MORE => "glyphicon glyphicon-option-horizontal",
87 G\Glyph::DISCLOSURE => "glyphicon glyphicon-option-vertical",
88 G\Glyph::LANGUAGE => "glyphicon glyphicon-lang",
89 G\Glyph::LOGIN => "glyphicon glyphicon-login",
90 G\Glyph::LOGOUT => "glyphicon glyphicon-logout",
91 G\Glyph::BULLETLIST => "glyphicon glyphicon-bulletlist",
92 G\Glyph::NUMBEREDLIST => "glyphicon glyphicon-numberedlist",
93 G\Glyph::LISTINDENT => "glyphicon glyphicon-listindent",
94 G\Glyph::LISTOUTDENT => "glyphicon glyphicon-listoutdent",
95 G\Glyph::FILTER => "glyphicon glyphicon-filter",
96 G\Glyph::COLLAPSE_HORIZONTAL => "glyphicon glyphicon-triangle-left",
97 G\Glyph::HEADER => "glyphicon glyphicon-header",
98 G\Glyph::ITALIC => "glyphicon glyphicon-italic",
99 G\Glyph::BOLD => "glyphicon glyphicon-bold",
100 G\Glyph::LINK => "glyphicon glyphicon-link",
101 G\Glyph::LAUNCH => "glyphicon glyphicon-launch",
102 G\Glyph::ENLARGE => "glyphicon glyphicon-enlarge",
103 G\Glyph::LIST_VIEW => "glyphicon glyphicon-listView",
104 G\Glyph::PREVIEW => "glyphicon glyphicon-preview",
105 G\Glyph::SORT => "glyphicon glyphicon-sort",
106 G\Glyph::COLUMN_SELECTION => "glyphicon glyphicon-columnSelection",
107 G\Glyph::TILE_VIEW => "glyphicon glyphicon-tileView",
108 G\Glyph::DRAG_HANDLE => "glyphicon glyphicon-dragHandle",
109 G\Glyph::CHECKED => "glyphicon glyphicon-checked",
110 G\Glyph::UNCHECKED => "glyphicon glyphicon-unchecked",
111 G\Glyph::PRESENTER => "glyphicon glyphicon-presenter",
112 G\Glyph::OWNER => "glyphicon glyphicon-owner",
113 G\Glyph::DATE => "glyphicon glyphicon-date",
114 G\Glyph::LOCATION => "glyphicon glyphicon-location",
115 G\Glyph::COPY => "glyphicon glyphicon-copy",
116 G\Glyph::QR_CODE => "glyphicon glyphicon-qrcode",
117 G\Glyph::SHARE => "glyphicon glyphicon-share",
118 );
119
120 public static array $aria_labels = array(
121 G\Glyph::SETTINGS => "settings",
122 G\Glyph::EXPAND => "expand_content",
123 G\Glyph::COLLAPSE => "collapse_content",
124 G\Glyph::ADD => "add",
125 G\Glyph::REMOVE => "remove",
126 G\Glyph::UP => "up",
127 G\Glyph::DOWN => "down",
128 G\Glyph::BACK => "back",
129 G\Glyph::NEXT => "next",
130 G\Glyph::SORT_ASCENDING => "sort_ascending",
131 G\Glyph::SORT_DESCENDING => "sort_descending",
132 G\Glyph::USER => "show_who_is_online",
133 G\Glyph::MAIL => "mail",
134 G\Glyph::NOTIFICATION => "notifications",
135 G\Glyph::TAG => "tags",
136 G\Glyph::NOTE => "notes",
137 G\Glyph::COMMENT => "comments",
138 G\Glyph::BRIEFCASE => "briefcase",
139 G\Glyph::LIKE => "like",
140 G\Glyph::LOVE => "love",
141 G\Glyph::DISLIKE => "dislike",
142 G\Glyph::LAUGH => "laugh",
143 G\Glyph::ASTOUNDED => "astounded",
144 G\Glyph::SAD => "sad",
145 G\Glyph::ANGRY => "angry",
146 G\Glyph::EYEOPEN => "eyeopened",
147 G\Glyph::EYECLOSED => "eyeclosed",
148 G\Glyph::ATTACHMENT => "attachment",
149 G\Glyph::RESET => "reset",
150 G\Glyph::APPLY => "apply",
151 G\Glyph::SEARCH => "search",
152 G\Glyph::HELP => "help",
153 G\Glyph::CALENDAR => "calendar",
154 G\Glyph::TIME => "time",
155 G\Glyph::CLOSE => "close",
156 G\Glyph::MORE => "show_more",
157 G\Glyph::DISCLOSURE => "disclose",
158 G\Glyph::LANGUAGE => "switch_language",
159 G\Glyph::LOGIN => "log_in",
160 G\Glyph::LOGOUT => "log_out",
161 G\Glyph::BULLETLIST => "bulletlist_action",
162 G\Glyph::NUMBEREDLIST => "numberedlist_action",
163 G\Glyph::LISTINDENT => "listindent",
164 G\Glyph::LISTOUTDENT => "listoutdent",
165 G\Glyph::FILTER => "filter",
166 G\Glyph::COLLAPSE_HORIZONTAL => "collapse/back",
167 G\Glyph::HEADER => "header_action",
168 G\Glyph::ITALIC => "italic_action",
169 G\Glyph::BOLD => "bold_action",
170 G\Glyph::LINK => "link_action",
171 G\Glyph::LAUNCH => "launch",
172 G\Glyph::ENLARGE => "enlarge",
173 G\Glyph::LIST_VIEW => "list_view",
174 G\Glyph::PREVIEW => "preview",
175 G\Glyph::SORT => "sort",
176 G\Glyph::COLUMN_SELECTION => "column_selection",
177 G\Glyph::TILE_VIEW => "tile_view",
178 G\Glyph::DRAG_HANDLE => "drag_handle",
179 G\Glyph::CHECKED => "checked",
180 G\Glyph::UNCHECKED => "unchecked",
181 G\Glyph::PRESENTER => "presenter",
182 G\Glyph::OWNER => "owner",
183 G\Glyph::DATE => "date",
184 G\Glyph::LOCATION => "location",
185 G\Glyph::COPY => "copy",
186 G\Glyph::QR_CODE => "show_qr_code",
187 G\Glyph::SHARE => "share",
188 );
189
190 #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
191 public function testImplementsFactoryInterface(string $factory_method): void
192 {
193 $f = $this->getGlyphFactory();
194
195 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Factory", $f);
196 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph", $f->$factory_method());
197 }
198
199 #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
200 public function testGlyphTypes(string $factory_method): void
201 {
202 $f = $this->getGlyphFactory();
203 $g = $f->$factory_method();
204
205 $this->assertNotNull($g);
206 $this->assertEquals($factory_method, $g->getType());
207 }
208
209 #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
210 public function testGlyphNoAction(string $factory_method): void
211 {
212 $f = $this->getGlyphFactory();
213 $g = $f->$factory_method();
214
215 $this->assertNotNull($g);
216 }
217
218 public function testWithHighlight(): void
219 {
220 $gf = $this->getGlyphFactory();
221
222 $g = $gf->mail();
223 $g2 = $g->withHighlight();
224
225 $this->assertFalse($g->isHighlighted());
226 $this->assertTrue($g2->isHighlighted());
227 }
228
229 #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
230 public function testNoCounter(string $factory_method): void
231 {
232 $f = $this->getGlyphFactory();
233 $g = $f->$factory_method();
234
235 $this->assertCount(0, $g->getCounters());
236 }
237
238 #[\PHPUnit\Framework\Attributes\DataProvider('getCounterTypeProvider')]
239 public function testOneCounter(string $counter_type): void
240 {
241 $gf = $this->getGlyphFactory();
242 $cf = $this->getCounterFactory();
243 $number = 1;
244
245 $g = $gf
246 ->mail()
247 ->withCounter(
248 $cf->$counter_type($number)
249 );
250
251 $counters = $g->getCounters();
252 $this->assertCount(1, $counters);
253 $c = $counters[0];
254 $this->assertEquals($counter_type, $c->getType());
255 $this->assertEquals($number, $c->getNumber());
256 }
257
258 public function testTwoCounters(): void
259 {
260 $gf = $this->getGlyphFactory();
261 $cf = $this->getCounterFactory();
262 $number_s = 1;
263 $number_n = 2;
264
265 $g = $gf
266 ->mail()
267 ->withCounter(
268 $cf->status($number_s)
269 )
270 ->withCounter(
271 $cf->novelty($number_n)
272 );
273
274 $counters = $g->getCounters();
275 $this->assertCount(2, $counters);
276 $vals = array_map(function ($c) {
277 return array($c->getType(), $c->getNumber());
278 }, $counters);
279 $this->assertContains(array("status", $number_s), $vals);
280 $this->assertContains(array("novelty", $number_n), $vals);
281 }
282
283 public function testOnlyTwoCounters(): void
284 {
285 $gf = $this->getGlyphFactory();
286 $cf = $this->getCounterFactory();
287 $number_s = 1;
288 $number_n1 = 2;
289 $number_n2 = 2;
290
291 $g = $gf
292 ->mail()
293 ->withCounter(
294 $cf->status($number_s)
295 )
296 ->withCounter(
297 $cf->novelty($number_n1)
298 )
299 ->withCounter(
300 $cf->novelty($number_n2)
301 );
302
303 $counters = $g->getCounters();
304 $this->assertCount(2, $counters);
305 $vals = array_map(function ($c) {
306 return array($c->getType(), $c->getNumber());
307 }, $counters);
308 $this->assertContains(array("status", $number_s), $vals);
309 $this->assertContains(array("novelty", $number_n2), $vals);
310 }
311
312 public function testImmutabilityWithCounter(): void
313 {
314 $gf = $this->getGlyphFactory();
315 $cf = $this->getCounterFactory();
316
317 $g = $gf->mail();
318 $g
319 ->withCounter(
320 $cf->novelty(0)
321 );
322
323 $counters = $g->getCounters();
324 $this->assertCount(0, $counters);
325 }
326
327 public function testKnownGlyphsOnly(): void
328 {
329 $this->expectException(InvalidArgumentException::class);
330 new Glyph("FOO", "FAA");
331 }
332
333 public static function getGlyphTypeProvider(): array
334 {
335 $glyph_reflection = new ReflectionClass(G\Glyph::class);
336 $constant_values = array_values($glyph_reflection->getConstants());
337 return array_map(function ($val) {
338 return [$val];
339 }, $constant_values);
340 }
341
342 public static function getCounterTypeProvider(): array
343 {
344 return [
345 ["status"],
346 ["novelty"]
347 ];
348 }
349
350 #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
351 public function testRenderSimple(string $type): void
352 {
353 $f = $this->getGlyphFactory();
354 $r = $this->getDefaultRenderer();
355 $c = $f->$type();
356
357 $html = $this->normalizeHTML($r->render($c));
358
359 $css_classes = self::$canonical_css_classes[$type];
360 $aria_label = self::$aria_labels[$type];
361
362 $expected = '<span class="glyph" aria-label="' . $aria_label . '" role="img"><span class="' . $css_classes . '" aria-hidden="true"></span></span>';
363 $this->assertEquals($expected, $html);
364 }
365
366 #[\PHPUnit\Framework\Attributes\DataProvider('getCounterTypeProvider')]
367 public function testRenderWithCounter(string $type): void
368 {
369 $fg = $this->getGlyphFactory();
370 $fc = $this->getCounterFactory();
371 $r = $this->getDefaultRenderer();
372 $c = $fg->mail()->withCounter($fc->$type(42));
373
374 $html = $this->normalizeHTML($r->render($c));
375
376 $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
377 $aria_label = self::$aria_labels[G\Glyph::MAIL];
378
379 $expected = '
380 <span class="glyph" aria-label="' . $aria_label . '" role="img">
381 <span class="' . $css_classes . '" aria-hidden="true"></span>
382 <span class="il-counter"><span class="badge badge-notify il-counter-' . $type . '">42</span></span>
383 <span class="il-counter-spacer">42</span>
384 </span>';
385 $this->assertHTMLEquals($expected, $html);
386 }
387
388 public function testRenderWithTwoCounters(): void
389 {
390 $fg = $this->getGlyphFactory();
391 $fc = $this->getCounterFactory();
392 $r = $this->getDefaultRenderer();
393 $c = $fg->mail()
394 ->withCounter($fc->novelty(42))
395 ->withCounter($fc->status(7));
396
397 $html = $this->normalizeHTML($r->render($c));
398
399 $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
400 $aria_label = self::$aria_labels[G\Glyph::MAIL];
401 $expected = '<span class="glyph" aria-label="' . $aria_label . '" role="img">' .
402 '<span class="' . $css_classes . '" aria-hidden="true"></span>' .
403 '<span class="il-counter"><span class="badge badge-notify il-counter-status">7</span></span>' .
404 '<span class="il-counter"><span class="badge badge-notify il-counter-novelty">42</span></span>' .
405 '<span class="il-counter-spacer">42</span>' .
406 '</span>';
407 $this->assertHTMLEquals($expected, $html);
408 }
409
410 public function testDontRenderCounter(): void
411 {
412 $this->expectException(\LogicException::class);
413 $r = new Renderer(
414 $this->getUIFactory(),
415 $this->getTemplateFactory(),
416 $this->getLanguage(),
417 $this->getJavaScriptBinding(),
419 $this->createMock(DataFactory::class),
420 $this->createMock(HelpTextRetriever::class),
421 $this->getUploadLimitResolver(),
422 $this->getRefinery(),
423 );
424 $f = $this->getCounterFactory();
425
426 $r->render($f->status(0), $this->getDefaultRenderer());
427 }
428
429 #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
430 public function testRenderWithOnLoadCode(string $type): void
431 {
432 $f = $this->getGlyphFactory();
433 $r = $this->getDefaultRenderer();
434 $ids = array();
435 $c = $f->$type()
436 ->withOnLoadCode(function ($id) use (&$ids): string {
437 $ids[] = $id;
438 return "";
439 });
440
441 $html = $this->normalizeHTML($r->render($c));
442
443 $this->assertCount(1, $ids);
444
445 $css_classes = self::$canonical_css_classes[$type];
446 $aria_label = self::$aria_labels[$type];
447
448 $id = $ids[0];
449 $expected = '<span class="glyph" aria-label="' . $aria_label . '" role="img" id="' . $id . '"><span class="' . $css_classes . '" aria-hidden="true"></span></span>';
450 $this->assertEquals($expected, $html);
451 }
452}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Test on glyph implementation.
Definition: GlyphTest.php:37
testGlyphTypes(string $factory_method)
Definition: GlyphTest.php:200
testGlyphNoAction(string $factory_method)
Definition: GlyphTest.php:210
testNoCounter(string $factory_method)
Definition: GlyphTest.php:230
testRenderWithTwoCounters()
Definition: GlyphTest.php:388
testImplementsFactoryInterface(string $factory_method)
Definition: GlyphTest.php:191
getCounterFactory()
Definition: GlyphTest.php:45
static getCounterTypeProvider()
Definition: GlyphTest.php:342
static array $canonical_css_classes
Definition: GlyphTest.php:50
testRenderWithOnLoadCode(string $type)
Definition: GlyphTest.php:430
testOneCounter(string $counter_type)
Definition: GlyphTest.php:239
testDontRenderCounter()
Definition: GlyphTest.php:410
testRenderSimple(string $type)
Definition: GlyphTest.php:351
getGlyphFactory()
Definition: GlyphTest.php:40
testWithHighlight()
Definition: GlyphTest.php:218
testRenderWithCounter(string $type)
Definition: GlyphTest.php:367
testTwoCounters()
Definition: GlyphTest.php:258
testImmutabilityWithCounter()
Definition: GlyphTest.php:312
static array $aria_labels
Definition: GlyphTest.php:120
static getGlyphTypeProvider()
Definition: GlyphTest.php:333
testKnownGlyphsOnly()
Definition: GlyphTest.php:327
testOnlyTwoCounters()
Definition: GlyphTest.php:283
Builds data types.
Definition: Factory.php:36
Provides common functionality for UI tests.
Definition: Base.php:346
This describes a facility that the UI framework can use to retrieve some help text.
@ QR_CODE
Transfer information by copying its contents to the computers clipboard.
getLanguage()