ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 
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  G\Glyph::ENLARGE => "glyphicon glyphicon-enlarge",
100  G\Glyph::LIST_VIEW => "glyphicon glyphicon-listView",
101  G\Glyph::PREVIEW => "glyphicon glyphicon-preview",
102  G\Glyph::SORT => "glyphicon glyphicon-sort",
103  G\Glyph::COLUMN_SELECTION => "glyphicon glyphicon-columnSelection",
104  G\Glyph::TILE_VIEW => "glyphicon glyphicon-tileView",
105  G\Glyph::DRAG_HANDLE => "glyphicon glyphicon-dragHandle",
106  );
107 
108  public static array $aria_labels = array(
109  G\Glyph::SETTINGS => "settings",
110  G\Glyph::EXPAND => "expand_content",
111  G\Glyph::COLLAPSE => "collapse_content",
112  G\Glyph::ADD => "add",
113  G\Glyph::REMOVE => "remove",
114  G\Glyph::UP => "up",
115  G\Glyph::DOWN => "down",
116  G\Glyph::BACK => "back",
117  G\Glyph::NEXT => "next",
118  G\Glyph::SORT_ASCENDING => "sort_ascending",
119  G\Glyph::SORT_DESCENDING => "sort_descending",
120  G\Glyph::USER => "show_who_is_online",
121  G\Glyph::MAIL => "mail",
122  G\Glyph::NOTIFICATION => "notifications",
123  G\Glyph::TAG => "tags",
124  G\Glyph::NOTE => "notes",
125  G\Glyph::COMMENT => "comments",
126  G\Glyph::BRIEFCASE => "briefcase",
127  G\Glyph::LIKE => "like",
128  G\Glyph::LOVE => "love",
129  G\Glyph::DISLIKE => "dislike",
130  G\Glyph::LAUGH => "laugh",
131  G\Glyph::ASTOUNDED => "astounded",
132  G\Glyph::SAD => "sad",
133  G\Glyph::ANGRY => "angry",
134  G\Glyph::EYEOPEN => "eyeopened",
135  G\Glyph::EYECLOSED => "eyeclosed",
136  G\Glyph::ATTACHMENT => "attachment",
137  G\Glyph::RESET => "reset",
138  G\Glyph::APPLY => "apply",
139  G\Glyph::SEARCH => "search",
140  G\Glyph::HELP => "help",
141  G\Glyph::CALENDAR => "calendar",
142  G\Glyph::TIME => "time",
143  G\Glyph::CLOSE => "close",
144  G\Glyph::MORE => "show_more",
145  G\Glyph::DISCLOSURE => "disclose",
146  G\Glyph::LANGUAGE => "switch_language",
147  G\Glyph::LOGIN => "log_in",
148  G\Glyph::LOGOUT => "log_out",
149  G\Glyph::BULLETLIST => "bulletlist_action",
150  G\Glyph::NUMBEREDLIST => "numberedlist_action",
151  G\Glyph::LISTINDENT => "listindent",
152  G\Glyph::LISTOUTDENT => "listoutdent",
153  G\Glyph::FILTER => "filter",
154  G\Glyph::COLLAPSE_HORIZONTAL => "collapse/back",
155  G\Glyph::HEADER => "header_action",
156  G\Glyph::ITALIC => "italic_action",
157  G\Glyph::BOLD => "bold_action",
158  G\Glyph::LINK => "link_action",
159  G\Glyph::LAUNCH => "launch",
160  G\Glyph::ENLARGE => "enlarge",
161  G\Glyph::LIST_VIEW => "list_view",
162  G\Glyph::PREVIEW => "preview",
163  G\Glyph::SORT => "sort",
164  G\Glyph::COLUMN_SELECTION => "column_selection",
165  G\Glyph::TILE_VIEW => "tile_view",
166  G\Glyph::DRAG_HANDLE => "drag_handle",
167  );
168 
172  public function testImplementsFactoryInterface(string $factory_method): void
173  {
174  $f = $this->getGlyphFactory();
175 
176  $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Factory", $f);
177  $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph", $f->$factory_method("http://www.ilias.de"));
178  }
179 
183  public function testGlyphTypes(string $factory_method): void
184  {
185  $f = $this->getGlyphFactory();
186  $g = $f->$factory_method();
187 
188  $this->assertNotNull($g);
189  $this->assertEquals($factory_method, $g->getType());
190  }
191 
195  public function testGlyphAction(string $factory_method): void
196  {
197  $f = $this->getGlyphFactory();
198  $g = $f->$factory_method("http://www.ilias.de");
199 
200  $this->assertNotNull($g);
201  $this->assertEquals("http://www.ilias.de", $g->getAction());
202  }
203 
207  public function testGlyphNoAction(string $factory_method): void
208  {
209  $f = $this->getGlyphFactory();
210  $g = $f->$factory_method();
211 
212  $this->assertNotNull($g);
213  $this->assertEquals(null, $g->getAction());
214  }
215 
219  public function testWithUnavailableAction(string $factory_method): void
220  {
221  $f = $this->getGlyphFactory();
222  $g = $f->$factory_method();
223  $g2 = $f->$factory_method()->withUnavailableAction();
224 
225  $this->assertTrue($g->isActive());
226  $this->assertFalse($g2->isActive());
227  }
228 
229  public function testWithHighlight(): void
230  {
231  $gf = $this->getGlyphFactory();
232 
233  $g = $gf->mail();
234  $g2 = $g->withHighlight();
235 
236  $this->assertFalse($g->isHighlighted());
237  $this->assertTrue($g2->isHighlighted());
238  }
239 
243  public function testNoCounter(string $factory_method): void
244  {
245  $f = $this->getGlyphFactory();
246  $g = $f->$factory_method();
247 
248  $this->assertCount(0, $g->getCounters());
249  }
250 
254  public function testOneCounter(string $counter_type): void
255  {
256  $gf = $this->getGlyphFactory();
257  $cf = $this->getCounterFactory();
258  $number = 1;
259 
260  $g = $gf
261  ->mail()
262  ->withCounter(
263  $cf->$counter_type($number)
264  );
265 
266  $counters = $g->getCounters();
267  $this->assertCount(1, $counters);
268  $c = $counters[0];
269  $this->assertEquals($counter_type, $c->getType());
270  $this->assertEquals($number, $c->getNumber());
271  }
272 
273  public function testTwoCounters(): void
274  {
275  $gf = $this->getGlyphFactory();
276  $cf = $this->getCounterFactory();
277  $number_s = 1;
278  $number_n = 2;
279 
280  $g = $gf
281  ->mail()
282  ->withCounter(
283  $cf->status($number_s)
284  )
285  ->withCounter(
286  $cf->novelty($number_n)
287  );
288 
289  $counters = $g->getCounters();
290  $this->assertCount(2, $counters);
291  $vals = array_map(function ($c) {
292  return array($c->getType(), $c->getNumber());
293  }, $counters);
294  $this->assertContains(array("status", $number_s), $vals);
295  $this->assertContains(array("novelty", $number_n), $vals);
296  }
297 
298  public function testOnlyTwoCounters(): void
299  {
300  $gf = $this->getGlyphFactory();
301  $cf = $this->getCounterFactory();
302  $number_s = 1;
303  $number_n1 = 2;
304  $number_n2 = 2;
305 
306  $g = $gf
307  ->mail()
308  ->withCounter(
309  $cf->status($number_s)
310  )
311  ->withCounter(
312  $cf->novelty($number_n1)
313  )
314  ->withCounter(
315  $cf->novelty($number_n2)
316  );
317 
318  $counters = $g->getCounters();
319  $this->assertCount(2, $counters);
320  $vals = array_map(function ($c) {
321  return array($c->getType(), $c->getNumber());
322  }, $counters);
323  $this->assertContains(array("status", $number_s), $vals);
324  $this->assertContains(array("novelty", $number_n2), $vals);
325  }
326 
327  public function testImmutabilityWithCounter(): void
328  {
329  $gf = $this->getGlyphFactory();
330  $cf = $this->getCounterFactory();
331 
332  $g = $gf->mail();
333  $g
334  ->withCounter(
335  $cf->novelty(0)
336  );
337 
338  $counters = $g->getCounters();
339  $this->assertCount(0, $counters);
340  }
341 
342  public function testKnownGlyphsOnly(): void
343  {
344  $this->expectException(InvalidArgumentException::class);
345  new Glyph("FOO", "http://www.ilias.de");
346  }
347 
348  public static function getGlyphTypeProvider(): array
349  {
350  $glyph_reflection = new ReflectionClass(G\Glyph::class);
351  $constant_values = array_values($glyph_reflection->getConstants());
352  return array_map(function ($val) {
353  return [$val];
354  }, $constant_values);
355  }
356 
357  public static function getCounterTypeProvider(): array
358  {
359  return [
360  ["status"],
361  ["novelty"]
362  ];
363  }
364 
368  public function testRenderSimple(string $type): void
369  {
370  $f = $this->getGlyphFactory();
371  $r = $this->getDefaultRenderer();
372  $c = $f->$type("http://www.ilias.de");
373 
374  $html = $this->normalizeHTML($r->render($c));
375 
376  $css_classes = self::$canonical_css_classes[$type];
377  $aria_label = self::$aria_labels[$type];
378 
379  $expected = '<a tabindex="0" class="glyph" href="http://www.ilias.de" aria-label="' . $aria_label . '"><span class="' . $css_classes . '" aria-hidden="true"></span></a>';
380  $this->assertEquals($expected, $html);
381  }
382 
386  public function testRenderWithUnavailableAction(string $type): void
387  {
388  $f = $this->getGlyphFactory();
389  $r = $this->getDefaultRenderer();
390  $c = $f->$type("http://www.ilias.de")->withUnavailableAction();
391 
392  $html = $this->normalizeHTML($r->render($c));
393 
394  $css_classes = self::$canonical_css_classes[$type];
395  $aria_label = self::$aria_labels[$type];
396 
397  $expected = '
398  <a class="glyph disabled" aria-label="' . $aria_label . '" aria-disabled="true">
399  <span class="' . $css_classes . '" aria-hidden="true"></span>
400  </a>';
401  $this->assertEquals($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($html));
402  }
403 
407  public function testRenderWithCounter(string $type): void
408  {
409  $fg = $this->getGlyphFactory();
410  $fc = $this->getCounterFactory();
411  $r = $this->getDefaultRenderer();
412  $c = $fg->mail("http://www.ilias.de")->withCounter($fc->$type(42));
413 
414  $html = $this->normalizeHTML($r->render($c));
415 
416  $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
417  $aria_label = self::$aria_labels[G\Glyph::MAIL];
418 
419  $expected = '
420  <a tabindex="0" class="glyph" href="http://www.ilias.de" aria-label="' . $aria_label . '">
421  <span class="' . $css_classes . '" aria-hidden="true"></span>
422  <span class="il-counter"><span class="badge badge-notify il-counter-' . $type . '">42</span></span>
423  <span class="il-counter-spacer">42</span>
424  </a>';
425  $this->assertHTMLEquals($expected, $html);
426  }
427 
428  public function testRenderWithTwoCounters(): void
429  {
430  $fg = $this->getGlyphFactory();
431  $fc = $this->getCounterFactory();
432  $r = $this->getDefaultRenderer();
433  $c = $fg->mail("http://www.ilias.de")
434  ->withCounter($fc->novelty(42))
435  ->withCounter($fc->status(7));
436 
437  $html = $this->normalizeHTML($r->render($c));
438 
439  $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
440  $aria_label = self::$aria_labels[G\Glyph::MAIL];
441  $expected = "<a tabindex=\"0\" class=\"glyph\" href=\"http://www.ilias.de\" aria-label=\"$aria_label\">" .
442  "<span class=\"$css_classes\" aria-hidden=\"true\"></span>" .
443  "<span class=\"il-counter\"><span class=\"badge badge-notify il-counter-status\">7</span></span>" .
444  "<span class=\"il-counter\"><span class=\"badge badge-notify il-counter-novelty\">42</span></span>" .
445  "<span class=\"il-counter-spacer\">42</span>" .
446  "</a>";
447  $this->assertHTMLEquals($expected, $html);
448  }
449 
450  public function testDontRenderCounter(): void
451  {
452  $this->expectException(\LogicException::class);
453  $r = new Renderer(
454  $this->getUIFactory(),
455  $this->getTemplateFactory(),
456  $this->getLanguage(),
457  $this->getJavaScriptBinding(),
458  new ilImagePathResolver(),
459  $this->createMock(DataFactory::class),
460  $this->createMock(HelpTextRetriever::class),
461  $this->getUploadLimitResolver()
462  );
463  $f = $this->getCounterFactory();
464 
465  $r->render($f->status(0), $this->getDefaultRenderer());
466  }
467 
471  public function testRenderWithOnLoadCode(string $type): void
472  {
473  $f = $this->getGlyphFactory();
474  $r = $this->getDefaultRenderer();
475  $ids = array();
476  $c = $f->$type("http://www.ilias.de")
477  ->withOnLoadCode(function ($id) use (&$ids): string {
478  $ids[] = $id;
479  return "";
480  });
481 
482  $html = $this->normalizeHTML($r->render($c));
483 
484  $this->assertCount(1, $ids);
485 
486  $css_classes = self::$canonical_css_classes[$type];
487  $aria_label = self::$aria_labels[$type];
488 
489  $id = $ids[0];
490  $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>";
491  $this->assertEquals($expected, $html);
492  }
493 
497  public function testRenderWithAction(string $type): void
498  {
499  $f = $this->getGlyphFactory();
500  $r = $this->getDefaultRenderer();
501  $c = $f->$type("http://www.ilias.de");
502  $c = $c->withAction("http://www.ilias.de/open-source-lms-ilias/");
503 
504  $html = $this->normalizeHTML($r->render($c));
505 
506  $css_classes = self::$canonical_css_classes[$type];
507  $aria_label = self::$aria_labels[$type];
508 
509  $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>";
510  $this->assertEquals($expected, $html);
511  }
512 
513  public function testIsTabbable(): void
514  {
515  $f = $this->getGlyphFactory();
516  $r = $this->getDefaultRenderer();
517 
518  // Glyph without Action or Signal
519  $c = $f->user();
520  $this->assertFalse($c->isTabbable());
521 
522  // Glyph with Action
523  $c = $f->user()->withAction("#");
524  $this->assertTrue($c->isTabbable());
525 
526  // Glyph with Signal
527  $c = $f->user()->withOnClick(new I\Signal("id_1", "click"));
528  $this->assertTrue($c->isTabbable());
529 
530  // Glyph with Action and Signal
531  $c = $f->user()->withAction("#")->withOnClick(new I\Signal("id_1", "click"));
532  $this->assertTrue($c->isTabbable());
533 
534  // Glyph with Action and Signal but Inactive
535  $c = $f->user()->withAction("#")->withOnClick(new I\Signal("id_1", "click"))->withUnavailableAction();
536  $this->assertFalse($c->isTabbable());
537  }
538 
539  public function testTabbableGlyphRender(): void
540  {
541  $f = $this->getGlyphFactory();
542  $r = $this->getDefaultRenderer();
543 
544  // Glyph without Action or Signal (not Tabbable)
545  $c = $f->user();
546  $expected = '<a class="glyph" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>';
547  $html = $this->normalizeHTML($r->render($c));
548  $this->assertEquals($expected, $html);
549 
550  // Glyph with Action (Tabbable)
551  $c = $f->user()->withAction("#");
552  $expected = '<a tabindex="0" class="glyph" href="#" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>';
553  $html = $this->normalizeHTML($r->render($c));
554  $this->assertEquals($expected, $html);
555  }
556 }
static array $canonical_css_classes
Definition: GlyphTest.php:47
testOneCounter(string $counter_type)
getCounterTypeProvider
Definition: GlyphTest.php:254
static array $aria_labels
Definition: GlyphTest.php:108
testIsTabbable()
Definition: GlyphTest.php:513
testRenderWithTwoCounters()
Definition: GlyphTest.php:428
testWithHighlight()
Definition: GlyphTest.php:229
testRenderWithCounter(string $type)
getCounterTypeProvider
Definition: GlyphTest.php:407
testGlyphTypes(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:183
$c
Definition: deliver.php:25
testImmutabilityWithCounter()
Definition: GlyphTest.php:327
testRenderWithAction(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:497
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getLanguage()
testGlyphAction(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:195
testTwoCounters()
Definition: GlyphTest.php:273
testTabbableGlyphRender()
Definition: GlyphTest.php:539
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getGlyphTypeProvider()
Definition: GlyphTest.php:348
testRenderWithOnLoadCode(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:471
getCounterFactory()
Definition: GlyphTest.php:42
testRenderSimple(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:368
testImplementsFactoryInterface(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:172
testDontRenderCounter()
Definition: GlyphTest.php:450
testWithUnavailableAction(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:219
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
testKnownGlyphsOnly()
Definition: GlyphTest.php:342
testOnlyTwoCounters()
Definition: GlyphTest.php:298
testRenderWithUnavailableAction(string $type)
getGlyphTypeProvider
Definition: GlyphTest.php:386
testGlyphNoAction(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:207
testNoCounter(string $factory_method)
getGlyphTypeProvider
Definition: GlyphTest.php:243
static getCounterTypeProvider()
Definition: GlyphTest.php:357
Test on glyph implementation.
Definition: GlyphTest.php:35
getGlyphFactory()
Definition: GlyphTest.php:37
$r