ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
GlyphTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 
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  $this->assertEquals(null, $g->getAction());
201  }
202 
203  #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
204  public function testWithUnavailableAction(string $factory_method): void
205  {
206  $f = $this->getGlyphFactory();
207  $g = $f->$factory_method();
208  $g2 = $f->$factory_method()->withUnavailableAction();
209 
210  $this->assertTrue($g->isActive());
211  $this->assertFalse($g2->isActive());
212  }
213 
214  public function testWithHighlight(): void
215  {
216  $gf = $this->getGlyphFactory();
217 
218  $g = $gf->mail();
219  $g2 = $g->withHighlight();
220 
221  $this->assertFalse($g->isHighlighted());
222  $this->assertTrue($g2->isHighlighted());
223  }
224 
225  #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
226  public function testNoCounter(string $factory_method): void
227  {
228  $f = $this->getGlyphFactory();
229  $g = $f->$factory_method();
230 
231  $this->assertCount(0, $g->getCounters());
232  }
233 
234  #[\PHPUnit\Framework\Attributes\DataProvider('getCounterTypeProvider')]
235  public function testOneCounter(string $counter_type): void
236  {
237  $gf = $this->getGlyphFactory();
238  $cf = $this->getCounterFactory();
239  $number = 1;
240 
241  $g = $gf
242  ->mail()
243  ->withCounter(
244  $cf->$counter_type($number)
245  );
246 
247  $counters = $g->getCounters();
248  $this->assertCount(1, $counters);
249  $c = $counters[0];
250  $this->assertEquals($counter_type, $c->getType());
251  $this->assertEquals($number, $c->getNumber());
252  }
253 
254  public function testTwoCounters(): void
255  {
256  $gf = $this->getGlyphFactory();
257  $cf = $this->getCounterFactory();
258  $number_s = 1;
259  $number_n = 2;
260 
261  $g = $gf
262  ->mail()
263  ->withCounter(
264  $cf->status($number_s)
265  )
266  ->withCounter(
267  $cf->novelty($number_n)
268  );
269 
270  $counters = $g->getCounters();
271  $this->assertCount(2, $counters);
272  $vals = array_map(function ($c) {
273  return array($c->getType(), $c->getNumber());
274  }, $counters);
275  $this->assertContains(array("status", $number_s), $vals);
276  $this->assertContains(array("novelty", $number_n), $vals);
277  }
278 
279  public function testOnlyTwoCounters(): void
280  {
281  $gf = $this->getGlyphFactory();
282  $cf = $this->getCounterFactory();
283  $number_s = 1;
284  $number_n1 = 2;
285  $number_n2 = 2;
286 
287  $g = $gf
288  ->mail()
289  ->withCounter(
290  $cf->status($number_s)
291  )
292  ->withCounter(
293  $cf->novelty($number_n1)
294  )
295  ->withCounter(
296  $cf->novelty($number_n2)
297  );
298 
299  $counters = $g->getCounters();
300  $this->assertCount(2, $counters);
301  $vals = array_map(function ($c) {
302  return array($c->getType(), $c->getNumber());
303  }, $counters);
304  $this->assertContains(array("status", $number_s), $vals);
305  $this->assertContains(array("novelty", $number_n2), $vals);
306  }
307 
308  public function testImmutabilityWithCounter(): void
309  {
310  $gf = $this->getGlyphFactory();
311  $cf = $this->getCounterFactory();
312 
313  $g = $gf->mail();
314  $g
315  ->withCounter(
316  $cf->novelty(0)
317  );
318 
319  $counters = $g->getCounters();
320  $this->assertCount(0, $counters);
321  }
322 
323  public function testKnownGlyphsOnly(): void
324  {
325  $this->expectException(InvalidArgumentException::class);
326  new Glyph("FOO", "FAA");
327  }
328 
329  public static function getGlyphTypeProvider(): array
330  {
331  $glyph_reflection = new ReflectionClass(G\Glyph::class);
332  $constant_values = array_values($glyph_reflection->getConstants());
333  return array_map(function ($val) {
334  return [$val];
335  }, $constant_values);
336  }
337 
338  public static function getCounterTypeProvider(): array
339  {
340  return [
341  ["status"],
342  ["novelty"]
343  ];
344  }
345 
346  #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
347  public function testRenderSimple(string $type): void
348  {
349  $f = $this->getGlyphFactory();
350  $r = $this->getDefaultRenderer();
351  $c = $f->$type();
352 
353  $html = $this->normalizeHTML($r->render($c));
354 
355  $css_classes = self::$canonical_css_classes[$type];
356  $aria_label = self::$aria_labels[$type];
357 
358  $expected = '<a class="glyph" aria-label="' . $aria_label . '"><span class="' . $css_classes . '" aria-hidden="true"></span></a>';
359  $this->assertEquals($expected, $html);
360  }
361 
362  #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
363  public function testRenderWithUnavailableAction(string $type): void
364  {
365  $f = $this->getGlyphFactory();
366  $r = $this->getDefaultRenderer();
367  $c = $f->$type()->withUnavailableAction();
368 
369  $html = $this->normalizeHTML($r->render($c));
370 
371  $css_classes = self::$canonical_css_classes[$type];
372  $aria_label = self::$aria_labels[$type];
373 
374  $expected = '
375  <a class="glyph disabled" aria-label="' . $aria_label . '" aria-disabled="true">
376  <span class="' . $css_classes . '" aria-hidden="true"></span>
377  </a>';
378  $this->assertEquals($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($html));
379  }
380 
381  #[\PHPUnit\Framework\Attributes\DataProvider('getCounterTypeProvider')]
382  public function testRenderWithCounter(string $type): void
383  {
384  $fg = $this->getGlyphFactory();
385  $fc = $this->getCounterFactory();
386  $r = $this->getDefaultRenderer();
387  $c = $fg->mail()->withCounter($fc->$type(42));
388 
389  $html = $this->normalizeHTML($r->render($c));
390 
391  $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
392  $aria_label = self::$aria_labels[G\Glyph::MAIL];
393 
394  $expected = '
395  <a class="glyph" aria-label="' . $aria_label . '">
396  <span class="' . $css_classes . '" aria-hidden="true"></span>
397  <span class="il-counter"><span class="badge badge-notify il-counter-' . $type . '">42</span></span>
398  <span class="il-counter-spacer">42</span>
399  </a>';
400  $this->assertHTMLEquals($expected, $html);
401  }
402 
403  public function testRenderWithTwoCounters(): void
404  {
405  $fg = $this->getGlyphFactory();
406  $fc = $this->getCounterFactory();
407  $r = $this->getDefaultRenderer();
408  $c = $fg->mail()
409  ->withCounter($fc->novelty(42))
410  ->withCounter($fc->status(7));
411 
412  $html = $this->normalizeHTML($r->render($c));
413 
414  $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
415  $aria_label = self::$aria_labels[G\Glyph::MAIL];
416  $expected = '<a class="glyph" aria-label="' . $aria_label . '">' .
417  '<span class="' . $css_classes . '" aria-hidden="true"></span>' .
418  '<span class="il-counter"><span class="badge badge-notify il-counter-status">7</span></span>' .
419  '<span class="il-counter"><span class="badge badge-notify il-counter-novelty">42</span></span>' .
420  '<span class="il-counter-spacer">42</span>' .
421  '</a>';
422  $this->assertHTMLEquals($expected, $html);
423  }
424 
425  public function testDontRenderCounter(): void
426  {
427  $this->expectException(\LogicException::class);
428  $r = new Renderer(
429  $this->getUIFactory(),
430  $this->getTemplateFactory(),
431  $this->getLanguage(),
432  $this->getJavaScriptBinding(),
433  new ilImagePathResolver(),
434  $this->createMock(DataFactory::class),
435  $this->createMock(HelpTextRetriever::class),
436  $this->getUploadLimitResolver()
437  );
438  $f = $this->getCounterFactory();
439 
440  $r->render($f->status(0), $this->getDefaultRenderer());
441  }
442 
443  #[\PHPUnit\Framework\Attributes\DataProvider('getGlyphTypeProvider')]
444  public function testRenderWithOnLoadCode(string $type): void
445  {
446  $f = $this->getGlyphFactory();
447  $r = $this->getDefaultRenderer();
448  $ids = array();
449  $c = $f->$type()
450  ->withOnLoadCode(function ($id) use (&$ids): string {
451  $ids[] = $id;
452  return "";
453  });
454 
455  $html = $this->normalizeHTML($r->render($c));
456 
457  $this->assertCount(1, $ids);
458 
459  $css_classes = self::$canonical_css_classes[$type];
460  $aria_label = self::$aria_labels[$type];
461 
462  $id = $ids[0];
463  $expected = '<a class="glyph" aria-label="' . $aria_label . '" id="' . $id . '"><span class="' . $css_classes . '" aria-hidden="true"></span></a>';
464  $this->assertEquals($expected, $html);
465  }
466 }
static array $canonical_css_classes
Definition: GlyphTest.php:48
testOneCounter(string $counter_type)
Definition: GlyphTest.php:235
static array $aria_labels
Definition: GlyphTest.php:111
testRenderWithTwoCounters()
Definition: GlyphTest.php:403
testWithHighlight()
Definition: GlyphTest.php:214
testRenderWithCounter(string $type)
Definition: GlyphTest.php:382
testGlyphTypes(string $factory_method)
Definition: GlyphTest.php:184
$c
Definition: deliver.php:25
testImmutabilityWithCounter()
Definition: GlyphTest.php:308
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getLanguage()
testTwoCounters()
Definition: GlyphTest.php:254
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getGlyphTypeProvider()
Definition: GlyphTest.php:329
testRenderWithOnLoadCode(string $type)
Definition: GlyphTest.php:444
getCounterFactory()
Definition: GlyphTest.php:43
testRenderSimple(string $type)
Definition: GlyphTest.php:347
testImplementsFactoryInterface(string $factory_method)
Definition: GlyphTest.php:175
testDontRenderCounter()
Definition: GlyphTest.php:425
testWithUnavailableAction(string $factory_method)
Definition: GlyphTest.php:204
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
testKnownGlyphsOnly()
Definition: GlyphTest.php:323
testOnlyTwoCounters()
Definition: GlyphTest.php:279
testRenderWithUnavailableAction(string $type)
Definition: GlyphTest.php:363
testGlyphNoAction(string $factory_method)
Definition: GlyphTest.php:194
testNoCounter(string $factory_method)
Definition: GlyphTest.php:226
static getCounterTypeProvider()
Definition: GlyphTest.php:338
Test on glyph implementation.
Definition: GlyphTest.php:36
getGlyphFactory()
Definition: GlyphTest.php:38
$r