ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
GlyphTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 
31 
36 {
37  public function getGlyphFactory(): G\Factory
38  {
39  return new I\Symbol\Glyph\Factory();
40  }
41 
42  public function getCounterFactory(): C\Factory
43  {
44  return new I\Counter\Factory();
45  }
46 
47  public static array $canonical_css_classes = array(
48  G\Glyph::SETTINGS => "glyphicon glyphicon-cog",
49  G\Glyph::EXPAND => "glyphicon glyphicon-triangle-right",
50  G\Glyph::COLLAPSE => "glyphicon glyphicon-triangle-bottom",
51  G\Glyph::ADD => "glyphicon glyphicon-plus-sign",
52  G\Glyph::REMOVE => "glyphicon glyphicon-minus-sign",
53  G\Glyph::UP => "glyphicon glyphicon-circle-arrow-up",
54  G\Glyph::DOWN => "glyphicon glyphicon-circle-arrow-down",
55  G\Glyph::BACK => "glyphicon glyphicon-chevron-left",
56  G\Glyph::NEXT => "glyphicon glyphicon-chevron-right",
57  G\Glyph::SORT_ASCENDING => "glyphicon glyphicon-arrow-up",
58  G\Glyph::SORT_DESCENDING => "glyphicon glyphicon-arrow-down",
59  G\Glyph::USER => "glyphicon glyphicon-user",
60  G\Glyph::MAIL => "glyphicon glyphicon-envelope",
61  G\Glyph::NOTIFICATION => "glyphicon glyphicon-bell",
62  G\Glyph::TAG => "glyphicon glyphicon-tag",
63  G\Glyph::NOTE => "glyphicon glyphicon-pushpin",
64  G\Glyph::COMMENT => "glyphicon glyphicon-comment",
65  G\Glyph::BRIEFCASE => "glyphicon glyphicon-briefcase",
66  G\Glyph::LIKE => "glyphicon il-glyphicon-like",
67  G\Glyph::LOVE => "glyphicon il-glyphicon-love",
68  G\Glyph::DISLIKE => "glyphicon il-glyphicon-dislike",
69  G\Glyph::LAUGH => "glyphicon il-glyphicon-laugh",
70  G\Glyph::ASTOUNDED => "glyphicon il-glyphicon-astounded",
71  G\Glyph::SAD => "glyphicon il-glyphicon-sad",
72  G\Glyph::ANGRY => "glyphicon il-glyphicon-angry",
73  G\Glyph::EYEOPEN => "glyphicon glyphicon-eye-open",
74  G\Glyph::EYECLOSED => "glyphicon glyphicon-eye-close",
75  G\Glyph::ATTACHMENT => "glyphicon glyphicon-paperclip",
76  G\Glyph::RESET => "glyphicon glyphicon-reset",
77  G\Glyph::APPLY => "glyphicon glyphicon-apply",
78  G\Glyph::SEARCH => "glyphicon glyphicon-search",
79  G\Glyph::HELP => "glyphicon glyphicon-question-sign",
80  G\Glyph::CALENDAR => "glyphicon glyphicon-calendar",
81  G\Glyph::TIME => "glyphicon glyphicon-time",
82  G\Glyph::CLOSE => "glyphicon glyphicon-remove",
83  G\Glyph::MORE => "glyphicon glyphicon-option-horizontal",
84  G\Glyph::DISCLOSURE => "glyphicon glyphicon-option-vertical",
85  G\Glyph::LANGUAGE => "glyphicon glyphicon-lang",
86  G\Glyph::LOGIN => "glyphicon glyphicon-login",
87  G\Glyph::LOGOUT => "glyphicon glyphicon-logout",
88  G\Glyph::BULLETLIST => "glyphicon glyphicon-bulletlist",
89  G\Glyph::NUMBEREDLIST => "glyphicon glyphicon-numberedlist",
90  G\Glyph::LISTINDENT => "glyphicon glyphicon-listindent",
91  G\Glyph::LISTOUTDENT => "glyphicon glyphicon-listoutdent",
92  G\Glyph::FILTER => "glyphicon glyphicon-filter",
93  G\Glyph::COLLAPSE_HORIZONTAL => "glyphicon glyphicon-triangle-left",
94  G\Glyph::HEADER => "glyphicon glyphicon-header",
95  G\Glyph::ITALIC => "glyphicon glyphicon-italic",
96  G\Glyph::BOLD => "glyphicon glyphicon-bold",
97  G\Glyph::LINK => "glyphicon glyphicon-link",
98  G\Glyph::LAUNCH => "glyphicon glyphicon-launch"
99  );
100 
101  public static array $aria_labels = array(
102  G\Glyph::SETTINGS => "settings",
103  G\Glyph::EXPAND => "expand_content",
104  G\Glyph::COLLAPSE => "collapse_content",
105  G\Glyph::ADD => "add",
106  G\Glyph::REMOVE => "remove",
107  G\Glyph::UP => "up",
108  G\Glyph::DOWN => "down",
109  G\Glyph::BACK => "back",
110  G\Glyph::NEXT => "next",
111  G\Glyph::SORT_ASCENDING => "sort_ascending",
112  G\Glyph::SORT_DESCENDING => "sort_descending",
113  G\Glyph::USER => "show_who_is_online",
114  G\Glyph::MAIL => "mail",
115  G\Glyph::NOTIFICATION => "notifications",
116  G\Glyph::TAG => "tags",
117  G\Glyph::NOTE => "notes",
118  G\Glyph::COMMENT => "comments",
119  G\Glyph::BRIEFCASE => "briefcase",
120  G\Glyph::LIKE => "like",
121  G\Glyph::LOVE => "love",
122  G\Glyph::DISLIKE => "dislike",
123  G\Glyph::LAUGH => "laugh",
124  G\Glyph::ASTOUNDED => "astounded",
125  G\Glyph::SAD => "sad",
126  G\Glyph::ANGRY => "angry",
127  G\Glyph::EYEOPEN => "eyeopened",
128  G\Glyph::EYECLOSED => "eyeclosed",
129  G\Glyph::ATTACHMENT => "attachment",
130  G\Glyph::RESET => "reset",
131  G\Glyph::APPLY => "apply",
132  G\Glyph::SEARCH => "search",
133  G\Glyph::HELP => "help",
134  G\Glyph::CALENDAR => "calendar",
135  G\Glyph::TIME => "time",
136  G\Glyph::CLOSE => "close",
137  G\Glyph::MORE => "show_more",
138  G\Glyph::DISCLOSURE => "disclose",
139  G\Glyph::LANGUAGE => "switch_language",
140  G\Glyph::LOGIN => "log_in",
141  G\Glyph::LOGOUT => "log_out",
142  G\Glyph::BULLETLIST => "bulletlist_action",
143  G\Glyph::NUMBEREDLIST => "numberedlist_action",
144  G\Glyph::LISTINDENT => "listindent",
145  G\Glyph::LISTOUTDENT => "listoutdent",
146  G\Glyph::FILTER => "filter",
147  G\Glyph::COLLAPSE_HORIZONTAL => "collapse/back",
148  G\Glyph::HEADER => "header_action",
149  G\Glyph::ITALIC => "italic_action",
150  G\Glyph::BOLD => "bold_action",
151  G\Glyph::LINK => "link_action",
152  G\Glyph::LAUNCH => "launch"
153  );
154 
158  public function testImplementsFactoryInterface(string $factory_method): void
159  {
160  $f = $this->getGlyphFactory();
161 
162  $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Factory", $f);
163  $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph", $f->$factory_method("http://www.ilias.de"));
164  }
165 
169  public function testGlyphTypes(string $factory_method): void
170  {
171  $f = $this->getGlyphFactory();
172  $g = $f->$factory_method();
173 
174  $this->assertNotNull($g);
175  $this->assertEquals($factory_method, $g->getType());
176  }
177 
181  public function testGlyphAction(string $factory_method): void
182  {
183  $f = $this->getGlyphFactory();
184  $g = $f->$factory_method("http://www.ilias.de");
185 
186  $this->assertNotNull($g);
187  $this->assertEquals("http://www.ilias.de", $g->getAction());
188  }
189 
193  public function testGlyphNoAction(string $factory_method): void
194  {
195  $f = $this->getGlyphFactory();
196  $g = $f->$factory_method();
197 
198  $this->assertNotNull($g);
199  $this->assertEquals(null, $g->getAction());
200  }
201 
205  public function testWithUnavailableAction(string $factory_method): void
206  {
207  $f = $this->getGlyphFactory();
208  $g = $f->$factory_method();
209  $g2 = $f->$factory_method()->withUnavailableAction();
210 
211  $this->assertTrue($g->isActive());
212  $this->assertFalse($g2->isActive());
213  }
214 
215  public function testWithHighlight(): void
216  {
217  $gf = $this->getGlyphFactory();
218 
219  $g = $gf->mail();
220  $g2 = $g->withHighlight();
221 
222  $this->assertFalse($g->isHighlighted());
223  $this->assertTrue($g2->isHighlighted());
224  }
225 
229  public function testNoCounter(string $factory_method): void
230  {
231  $f = $this->getGlyphFactory();
232  $g = $f->$factory_method();
233 
234  $this->assertCount(0, $g->getCounters());
235  }
236 
240  public function testOneCounter(string $counter_type): void
241  {
242  $gf = $this->getGlyphFactory();
243  $cf = $this->getCounterFactory();
244  $number = 1;
245 
246  $g = $gf
247  ->mail()
248  ->withCounter(
249  $cf->$counter_type($number)
250  );
251 
252  $counters = $g->getCounters();
253  $this->assertCount(1, $counters);
254  $c = $counters[0];
255  $this->assertEquals($counter_type, $c->getType());
256  $this->assertEquals($number, $c->getNumber());
257  }
258 
259  public function testTwoCounters(): void
260  {
261  $gf = $this->getGlyphFactory();
262  $cf = $this->getCounterFactory();
263  $number_s = 1;
264  $number_n = 2;
265 
266  $g = $gf
267  ->mail()
268  ->withCounter(
269  $cf->status($number_s)
270  )
271  ->withCounter(
272  $cf->novelty($number_n)
273  );
274 
275  $counters = $g->getCounters();
276  $this->assertCount(2, $counters);
277  $vals = array_map(function ($c) {
278  return array($c->getType(), $c->getNumber());
279  }, $counters);
280  $this->assertContains(array("status", $number_s), $vals);
281  $this->assertContains(array("novelty", $number_n), $vals);
282  }
283 
284  public function testOnlyTwoCounters(): void
285  {
286  $gf = $this->getGlyphFactory();
287  $cf = $this->getCounterFactory();
288  $number_s = 1;
289  $number_n1 = 2;
290  $number_n2 = 2;
291 
292  $g = $gf
293  ->mail()
294  ->withCounter(
295  $cf->status($number_s)
296  )
297  ->withCounter(
298  $cf->novelty($number_n1)
299  )
300  ->withCounter(
301  $cf->novelty($number_n2)
302  );
303 
304  $counters = $g->getCounters();
305  $this->assertCount(2, $counters);
306  $vals = array_map(function ($c) {
307  return array($c->getType(), $c->getNumber());
308  }, $counters);
309  $this->assertContains(array("status", $number_s), $vals);
310  $this->assertContains(array("novelty", $number_n2), $vals);
311  }
312 
313  public function testImmutabilityWithCounter(): void
314  {
315  $gf = $this->getGlyphFactory();
316  $cf = $this->getCounterFactory();
317 
318  $g = $gf->mail();
319  $g
320  ->withCounter(
321  $cf->novelty(0)
322  );
323 
324  $counters = $g->getCounters();
325  $this->assertCount(0, $counters);
326  }
327 
328  public function testKnownGlyphsOnly(): void
329  {
330  $this->expectException(InvalidArgumentException::class);
331  new Glyph("FOO", "http://www.ilias.de");
332  }
333 
334  public function getGlyphTypeProvider(): array
335  {
336  $glyph_reflection = new ReflectionClass(G\Glyph::class);
337  $constant_values = array_values($glyph_reflection->getConstants());
338  return array_map(function ($val) {
339  return [$val];
340  }, $constant_values);
341  }
342 
343  public function getCounterTypeProvider(): array
344  {
345  return [
346  ["status"],
347  ["novelty"]
348  ];
349  }
350 
354  public function testRenderSimple(string $type): void
355  {
356  $f = $this->getGlyphFactory();
357  $r = $this->getDefaultRenderer();
358  $c = $f->$type("http://www.ilias.de");
359 
360  $html = $this->normalizeHTML($r->render($c));
361 
362  $css_classes = self::$canonical_css_classes[$type];
363  $aria_label = self::$aria_labels[$type];
364 
365  $expected = '<a tabindex="0" class="glyph" href="http://www.ilias.de" aria-label="' . $aria_label . '"><span class="' . $css_classes . '" aria-hidden="true"></span></a>';
366  $this->assertEquals($expected, $html);
367  }
368 
372  public function testRenderWithUnavailableAction(string $type): void
373  {
374  $f = $this->getGlyphFactory();
375  $r = $this->getDefaultRenderer();
376  $c = $f->$type("http://www.ilias.de")->withUnavailableAction();
377 
378  $html = $this->normalizeHTML($r->render($c));
379 
380  $css_classes = self::$canonical_css_classes[$type];
381  $aria_label = self::$aria_labels[$type];
382 
383  $expected = '
384  <a class="glyph disabled" aria-label="' . $aria_label . '" aria-disabled="true">
385  <span class="' . $css_classes . '" aria-hidden="true"></span>
386  </a>';
387  $this->assertEquals($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($html));
388  }
389 
393  public function testRenderWithCounter(string $type): void
394  {
395  $fg = $this->getGlyphFactory();
396  $fc = $this->getCounterFactory();
397  $r = $this->getDefaultRenderer();
398  $c = $fg->mail("http://www.ilias.de")->withCounter($fc->$type(42));
399 
400  $html = $this->normalizeHTML($r->render($c));
401 
402  $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
403  $aria_label = self::$aria_labels[G\Glyph::MAIL];
404 
405  $expected = '
406  <a tabindex="0" class="glyph" href="http://www.ilias.de" aria-label="' . $aria_label . '">
407  <span class="' . $css_classes . '" aria-hidden="true"></span>
408  <span class="il-counter"><span class="badge badge-notify il-counter-' . $type . '">42</span></span>
409  <span class="il-counter-spacer">42</span>
410  </a>';
411  $this->assertHTMLEquals($expected, $html);
412  }
413 
414  public function testRenderWithTwoCounters(): void
415  {
416  $fg = $this->getGlyphFactory();
417  $fc = $this->getCounterFactory();
418  $r = $this->getDefaultRenderer();
419  $c = $fg->mail("http://www.ilias.de")
420  ->withCounter($fc->novelty(42))
421  ->withCounter($fc->status(7));
422 
423  $html = $this->normalizeHTML($r->render($c));
424 
425  $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
426  $aria_label = self::$aria_labels[G\Glyph::MAIL];
427  $expected = "<a tabindex=\"0\" class=\"glyph\" href=\"http://www.ilias.de\" aria-label=\"$aria_label\">" .
428  "<span class=\"$css_classes\" aria-hidden=\"true\"></span>" .
429  "<span class=\"il-counter\"><span class=\"badge badge-notify il-counter-status\">7</span></span>" .
430  "<span class=\"il-counter\"><span class=\"badge badge-notify il-counter-novelty\">42</span></span>" .
431  "<span class=\"il-counter-spacer\">42</span>" .
432  "</a>";
433  $this->assertHTMLEquals($expected, $html);
434  }
435 
436  public function testDontRenderCounter(): void
437  {
438  $this->expectException(LogicException::class);
439  $r = new Renderer(
440  $this->getUIFactory(),
441  $this->getTemplateFactory(),
442  $this->getLanguage(),
443  $this->getJavaScriptBinding(),
444  $this->getRefinery(),
445  new ilImagePathResolver(),
446  $this->createMock(DataFactory::class),
447  $this->createMock(HelpTextRetriever::class),
448  $this->getUploadLimitResolver()
449  );
450  $f = $this->getCounterFactory();
451 
452  $r->render($f->status(0), $this->getDefaultRenderer());
453  }
454 
458  public function testRenderWithOnLoadCode(string $type): void
459  {
460  $f = $this->getGlyphFactory();
461  $r = $this->getDefaultRenderer();
462  $ids = array();
463  $c = $f->$type("http://www.ilias.de")
464  ->withOnLoadCode(function ($id) use (&$ids): string {
465  $ids[] = $id;
466  return "";
467  });
468 
469  $html = $this->normalizeHTML($r->render($c));
470 
471  $this->assertCount(1, $ids);
472 
473  $css_classes = self::$canonical_css_classes[$type];
474  $aria_label = self::$aria_labels[$type];
475 
476  $id = $ids[0];
477  $expected = "<a tabindex=\"0\" class=\"glyph\" href=\"http://www.ilias.de\" aria-label=\"$aria_label\" id=\"$id\"><span class=\"$css_classes\" aria-hidden=\"true\"></span></a>";
478  $this->assertEquals($expected, $html);
479  }
480 
484  public function testRenderWithAction(string $type): void
485  {
486  $f = $this->getGlyphFactory();
487  $r = $this->getDefaultRenderer();
488  $c = $f->$type("http://www.ilias.de");
489  $c = $c->withAction("http://www.ilias.de/open-source-lms-ilias/");
490 
491  $html = $this->normalizeHTML($r->render($c));
492 
493  $css_classes = self::$canonical_css_classes[$type];
494  $aria_label = self::$aria_labels[$type];
495 
496  $expected = "<a tabindex=\"0\" class=\"glyph\" href=\"http://www.ilias.de/open-source-lms-ilias/\" aria-label=\"$aria_label\"><span class=\"$css_classes\" aria-hidden=\"true\"></span></a>";
497  $this->assertEquals($expected, $html);
498  }
499 
500  public function testIsTabbable(): void
501  {
502  $f = $this->getGlyphFactory();
503  $r = $this->getDefaultRenderer();
504 
505  // Glyph without Action or Signal
506  $c = $f->user();
507  $this->assertFalse($c->isTabbable());
508 
509  // Glyph with Action
510  $c = $f->user()->withAction("#");
511  $this->assertTrue($c->isTabbable());
512 
513  // Glyph with Signal
514  $c = $f->user()->withOnClick(new I\Signal("id_1", "click"));
515  $this->assertTrue($c->isTabbable());
516 
517  // Glyph with Action and Signal
518  $c = $f->user()->withAction("#")->withOnClick(new I\Signal("id_1", "click"));
519  $this->assertTrue($c->isTabbable());
520 
521  // Glyph with Action and Signal but Inactive
522  $c = $f->user()->withAction("#")->withOnClick(new I\Signal("id_1", "click"))->withUnavailableAction();
523  $this->assertFalse($c->isTabbable());
524  }
525 
526  public function testTabbableGlyphRender(): void
527  {
528  $f = $this->getGlyphFactory();
529  $r = $this->getDefaultRenderer();
530 
531  // Glyph without Action or Signal (not Tabbable)
532  $c = $f->user();
533  $expected = '<a class="glyph" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>';
534  $html = $this->normalizeHTML($r->render($c));
535  $this->assertEquals($expected, $html);
536 
537  // Glyph with Action (Tabbable)
538  $c = $f->user()->withAction("#");
539  $expected = '<a tabindex="0" class="glyph" href="#" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>';
540  $html = $this->normalizeHTML($r->render($c));
541  $this->assertEquals($expected, $html);
542  }
543 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:377
static array $canonical_css_classes
Definition: GlyphTest.php:47
testOneCounter(string $counter_type)
getCounterTypeProvider
Definition: GlyphTest.php:240
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static array $aria_labels
Definition: GlyphTest.php:101
testIsTabbable()
Definition: GlyphTest.php:500
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testRenderWithTwoCounters()
Definition: GlyphTest.php:414
testWithHighlight()
Definition: GlyphTest.php:215
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testRenderWithCounter(string $type)
getCounterTypeProvider
Definition: GlyphTest.php:393
testGlyphTypes(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:169
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:475
testImmutabilityWithCounter()
Definition: GlyphTest.php:313
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Counter.php:21
getGlyphTypeProvider()
Definition: GlyphTest.php:334
testRenderWithAction(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:484
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:458
getJavaScriptBinding()
Definition: Base.php:342
testGlyphAction(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:181
Provides common functionality for UI tests.
Definition: Base.php:310
getUploadLimitResolver()
Definition: Base.php:372
testTwoCounters()
Definition: GlyphTest.php:259
testTabbableGlyphRender()
Definition: GlyphTest.php:526
testRenderWithOnLoadCode(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:458
getCounterFactory()
Definition: GlyphTest.php:42
testRenderSimple(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:354
getCounterTypeProvider()
Definition: GlyphTest.php:343
testImplementsFactoryInterface(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:158
testDontRenderCounter()
Definition: GlyphTest.php:436
getTemplateFactory()
Definition: Base.php:327
testWithUnavailableAction(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:205
testKnownGlyphsOnly()
Definition: GlyphTest.php:328
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
testOnlyTwoCounters()
Definition: GlyphTest.php:284
testRenderWithUnavailableAction(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:372
testGlyphNoAction(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:193
testNoCounter(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:229
normalizeHTML(string $html)
Definition: Base.php:453
Test on glyph implementation.
Definition: GlyphTest.php:35
getGlyphFactory()
Definition: GlyphTest.php:37
$r