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