ILIAS  release_8 Revision v8.24
GlyphTest Class Reference

Test on glyph implementation. More...

+ Inheritance diagram for GlyphTest:
+ Collaboration diagram for GlyphTest:

Public Member Functions

 getGlyphFactory ()
 
 getCounterFactory ()
 
 test_implements_factory_interface (string $factory_method)
 @dataProvider glyph_type_provider More...
 
 test_glyph_types (string $factory_method)
 @dataProvider glyph_type_provider More...
 
 test_glyph_action (string $factory_method)
 @dataProvider glyph_type_provider More...
 
 test_glyph_no_action (string $factory_method)
 @dataProvider glyph_type_provider More...
 
 test_with_unavailable_action (string $factory_method)
 @dataProvider glyph_type_provider More...
 
 test_with_highlight ()
 
 test_no_counter (string $factory_method)
 @dataProvider glyph_type_provider More...
 
 test_one_counter (string $counter_type)
 @dataProvider counter_type_provider More...
 
 test_two_counters ()
 
 test_only_two_counters ()
 
 test_immutability_withCounter ()
 
 test_known_glyphs_only ()
 
 glyph_type_provider ()
 
 counter_type_provider ()
 
 test_render_simple (string $type)
 @dataProvider glyph_type_provider More...
 
 test_render_with_unavailable_action (string $type)
 @dataProvider glyph_type_provider More...
 
 test_render_withCounter (string $type)
 @dataProvider counter_type_provider More...
 
 test_render_withTwoCounters ()
 
 test_dont_render_counter ()
 
 test_render_with_on_load_code (string $type)
 @dataProvider glyph_type_provider More...
 
 test_render_with_action (string $type)
 @dataProvider glyph_type_provider More...
 
 testIsTabbable ()
 
 testTabbableGlyphRender ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Static Public Attributes

static array $canonical_css_classes
 
static array $aria_labels
 

Additional Inherited Members

- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Detailed Description

Test on glyph implementation.

Definition at line 33 of file GlyphTest.php.

Member Function Documentation

◆ counter_type_provider()

GlyphTest::counter_type_provider ( )

Definition at line 331 of file GlyphTest.php.

331 : array
332 {
333 return [
334 ["status"],
335 ["novelty"]
336 ];
337 }

◆ getCounterFactory()

GlyphTest::getCounterFactory ( )

Definition at line 40 of file GlyphTest.php.

40 : C\Factory
41 {
42 return new I\Counter\Factory();
43 }

Referenced by test_dont_render_counter(), test_immutability_withCounter(), test_one_counter(), test_only_two_counters(), test_render_withCounter(), test_render_withTwoCounters(), and test_two_counters().

+ Here is the caller graph for this function:

◆ getGlyphFactory()

◆ glyph_type_provider()

GlyphTest::glyph_type_provider ( )

Definition at line 322 of file GlyphTest.php.

322 : array
323 {
324 $glyph_reflection = new ReflectionClass(G\Glyph::class);
325 $constant_values = array_values($glyph_reflection->getConstants());
326 return array_map(function ($val) {
327 return [$val];
328 }, $constant_values);
329 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21

◆ test_dont_render_counter()

GlyphTest::test_dont_render_counter ( )

Definition at line 424 of file GlyphTest.php.

424 : void
425 {
426 $this->expectException(LogicException::class);
427 $r = new Renderer(
428 $this->getUIFactory(),
429 $this->getTemplateFactory(),
430 $this->getLanguage(),
431 $this->getJavaScriptBinding(),
432 $this->getRefinery(),
434 $this->getDataFactory()
435 );
436 $f = $this->getCounterFactory();
437
438 $r->render($f->status(0), $this->getDefaultRenderer());
439 }
getCounterFactory()
Definition: GlyphTest.php:40
getJavaScriptBinding()
Definition: Base.php:330
getTemplateFactory()
Definition: Base.php:315

References Vendor\Package\$f, getCounterFactory(), ILIAS_UI_TestBase\getDataFactory(), ILIAS_UI_TestBase\getJavaScriptBinding(), ILIAS_UI_TestBase\getLanguage(), ILIAS_UI_TestBase\getRefinery(), ILIAS_UI_TestBase\getTemplateFactory(), and ILIAS_UI_TestBase\getUIFactory().

+ Here is the call graph for this function:

◆ test_glyph_action()

GlyphTest::test_glyph_action ( string  $factory_method)

@dataProvider glyph_type_provider

Definition at line 169 of file GlyphTest.php.

169 : void
170 {
171 $f = $this->getGlyphFactory();
172 $g = $f->$factory_method("http://www.ilias.de");
173
174 $this->assertNotNull($g);
175 $this->assertEquals("http://www.ilias.de", $g->getAction());
176 }
getGlyphFactory()
Definition: GlyphTest.php:35

References Vendor\Package\$f, and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_glyph_no_action()

GlyphTest::test_glyph_no_action ( string  $factory_method)

@dataProvider glyph_type_provider

Definition at line 181 of file GlyphTest.php.

181 : void
182 {
183 $f = $this->getGlyphFactory();
184 $g = $f->$factory_method();
185
186 $this->assertNotNull($g);
187 $this->assertEquals(null, $g->getAction());
188 }

References Vendor\Package\$f, and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_glyph_types()

GlyphTest::test_glyph_types ( string  $factory_method)

@dataProvider glyph_type_provider

Definition at line 157 of file GlyphTest.php.

157 : void
158 {
159 $f = $this->getGlyphFactory();
160 $g = $f->$factory_method();
161
162 $this->assertNotNull($g);
163 $this->assertEquals($factory_method, $g->getType());
164 }

References Vendor\Package\$f, and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_immutability_withCounter()

GlyphTest::test_immutability_withCounter ( )

Definition at line 301 of file GlyphTest.php.

301 : void
302 {
303 $gf = $this->getGlyphFactory();
304 $cf = $this->getCounterFactory();
305
306 $g = $gf->mail();
307 $g
308 ->withCounter(
309 $cf->novelty(0)
310 );
311
312 $counters = $g->getCounters();
313 $this->assertCount(0, $counters);
314 }

References getCounterFactory(), and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_implements_factory_interface()

GlyphTest::test_implements_factory_interface ( string  $factory_method)

@dataProvider glyph_type_provider

Definition at line 146 of file GlyphTest.php.

146 : void
147 {
148 $f = $this->getGlyphFactory();
149
150 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Factory", $f);
151 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Glyph\\Glyph", $f->$factory_method("http://www.ilias.de"));
152 }

References Vendor\Package\$f, and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_known_glyphs_only()

GlyphTest::test_known_glyphs_only ( )

Definition at line 316 of file GlyphTest.php.

316 : void
317 {
318 $this->expectException(InvalidArgumentException::class);
319 new Glyph("FOO", "http://www.ilias.de");
320 }

◆ test_no_counter()

GlyphTest::test_no_counter ( string  $factory_method)

@dataProvider glyph_type_provider

Definition at line 217 of file GlyphTest.php.

217 : void
218 {
219 $f = $this->getGlyphFactory();
220 $g = $f->$factory_method();
221
222 $this->assertCount(0, $g->getCounters());
223 }

References Vendor\Package\$f, and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_one_counter()

GlyphTest::test_one_counter ( string  $counter_type)

@dataProvider counter_type_provider

Definition at line 228 of file GlyphTest.php.

228 : void
229 {
230 $gf = $this->getGlyphFactory();
231 $cf = $this->getCounterFactory();
232 $number = 1;
233
234 $g = $gf
235 ->mail()
236 ->withCounter(
237 $cf->$counter_type($number)
238 );
239
240 $counters = $g->getCounters();
241 $this->assertCount(1, $counters);
242 $c = $counters[0];
243 $this->assertEquals($counter_type, $c->getType());
244 $this->assertEquals($number, $c->getNumber());
245 }
$c
Definition: cli.php:38

References $c, getCounterFactory(), and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_only_two_counters()

GlyphTest::test_only_two_counters ( )

Definition at line 272 of file GlyphTest.php.

272 : void
273 {
274 $gf = $this->getGlyphFactory();
275 $cf = $this->getCounterFactory();
276 $number_s = 1;
277 $number_n1 = 2;
278 $number_n2 = 2;
279
280 $g = $gf
281 ->mail()
282 ->withCounter(
283 $cf->status($number_s)
284 )
285 ->withCounter(
286 $cf->novelty($number_n1)
287 )
288 ->withCounter(
289 $cf->novelty($number_n2)
290 );
291
292 $counters = $g->getCounters();
293 $this->assertCount(2, $counters);
294 $vals = array_map(function ($c) {
295 return array($c->getType(), $c->getNumber());
296 }, $counters);
297 $this->assertContains(array("status", $number_s), $vals);
298 $this->assertContains(array("novelty", $number_n2), $vals);
299 }

References $c, getCounterFactory(), and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_render_simple()

GlyphTest::test_render_simple ( string  $type)

@dataProvider glyph_type_provider

Definition at line 342 of file GlyphTest.php.

342 : void
343 {
344 $f = $this->getGlyphFactory();
345 $r = $this->getDefaultRenderer();
346 $c = $f->$type("http://www.ilias.de");
347
348 $html = $this->normalizeHTML($r->render($c));
349
350 $css_classes = self::$canonical_css_classes[$type];
351 $aria_label = self::$aria_labels[$type];
352
353 $expected = '<a tabindex="0" class="glyph" href="http://www.ilias.de" aria-label="' . $aria_label . '"><span class="' . $css_classes . '" aria-hidden="true"></span></a>';
354 $this->assertEquals($expected, $html);
355 }
normalizeHTML(string $html)
Definition: Base.php:422
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
$type

References $c, Vendor\Package\$f, $type, ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_with_action()

GlyphTest::test_render_with_action ( string  $type)

@dataProvider glyph_type_provider

Definition at line 470 of file GlyphTest.php.

470 : void
471 {
472 $f = $this->getGlyphFactory();
473 $r = $this->getDefaultRenderer();
474 $c = $f->$type("http://www.ilias.de");
475 $c = $c->withAction("http://www.ilias.de/open-source-lms-ilias/");
476
477 $html = $this->normalizeHTML($r->render($c));
478
479 $css_classes = self::$canonical_css_classes[$type];
480 $aria_label = self::$aria_labels[$type];
481
482 $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>";
483 $this->assertEquals($expected, $html);
484 }

References $c, Vendor\Package\$f, $type, ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_with_on_load_code()

GlyphTest::test_render_with_on_load_code ( string  $type)

@dataProvider glyph_type_provider

Definition at line 444 of file GlyphTest.php.

444 : void
445 {
446 $f = $this->getGlyphFactory();
447 $r = $this->getDefaultRenderer();
448 $ids = array();
449 $c = $f->$type("http://www.ilias.de")
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 tabindex=\"0\" class=\"glyph\" href=\"http://www.ilias.de\" aria-label=\"$aria_label\" id=\"$id\"><span class=\"$css_classes\" aria-hidden=\"true\"></span></a>";
464 $this->assertEquals($expected, $html);
465 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $c, Vendor\Package\$f, $id, $type, ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_with_unavailable_action()

GlyphTest::test_render_with_unavailable_action ( string  $type)

@dataProvider glyph_type_provider

Definition at line 360 of file GlyphTest.php.

360 : void
361 {
362 $f = $this->getGlyphFactory();
363 $r = $this->getDefaultRenderer();
364 $c = $f->$type("http://www.ilias.de")->withUnavailableAction();
365
366 $html = $this->normalizeHTML($r->render($c));
367
368 $css_classes = self::$canonical_css_classes[$type];
369 $aria_label = self::$aria_labels[$type];
370
371 $expected = '
372 <a class="glyph disabled" aria-label="' . $aria_label . '" aria-disabled="true">
373 <span class="' . $css_classes . '" aria-hidden="true"></span>
374 </a>';
375 $this->assertEquals($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($html));
376 }
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444

References $c, Vendor\Package\$f, $type, ILIAS_UI_TestBase\brutallyTrimHTML(), ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_withCounter()

GlyphTest::test_render_withCounter ( string  $type)

@dataProvider counter_type_provider

Definition at line 381 of file GlyphTest.php.

381 : void
382 {
383 $fg = $this->getGlyphFactory();
384 $fc = $this->getCounterFactory();
385 $r = $this->getDefaultRenderer();
386 $c = $fg->mail("http://www.ilias.de")->withCounter($fc->$type(42));
387
388 $html = $this->normalizeHTML($r->render($c));
389
390 $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
391 $aria_label = self::$aria_labels[G\Glyph::MAIL];
392
393 $expected = '
394 <a tabindex="0" class="glyph" href="http://www.ilias.de" aria-label="' . $aria_label . '">
395 <span class="' . $css_classes . '" aria-hidden="true"></span>
396 <span class="il-counter"><span class="badge badge-notify il-counter-' . $type . '">42</span></span>
397 <span class="il-counter-spacer">42</span>
398 </a>';
399 $this->assertHTMLEquals($expected, $html);
400 }
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427

References $c, $type, ILIAS_UI_TestBase\assertHTMLEquals(), getCounterFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), ILIAS\UI\Component\Symbol\Glyph\Glyph\MAIL, and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_withTwoCounters()

GlyphTest::test_render_withTwoCounters ( )

Definition at line 402 of file GlyphTest.php.

402 : void
403 {
404 $fg = $this->getGlyphFactory();
405 $fc = $this->getCounterFactory();
406 $r = $this->getDefaultRenderer();
407 $c = $fg->mail("http://www.ilias.de")
408 ->withCounter($fc->novelty(42))
409 ->withCounter($fc->status(7));
410
411 $html = $this->normalizeHTML($r->render($c));
412
413 $css_classes = self::$canonical_css_classes[G\Glyph::MAIL];
414 $aria_label = self::$aria_labels[G\Glyph::MAIL];
415 $expected = "<a tabindex=\"0\" class=\"glyph\" href=\"http://www.ilias.de\" aria-label=\"$aria_label\">" .
416 "<span class=\"$css_classes\" aria-hidden=\"true\"></span>" .
417 "<span class=\"il-counter\"><span class=\"badge badge-notify il-counter-status\">7</span></span>" .
418 "<span class=\"il-counter\"><span class=\"badge badge-notify il-counter-novelty\">42</span></span>" .
419 "<span class=\"il-counter-spacer\">42</span>" .
420 "</a>";
421 $this->assertHTMLEquals($expected, $html);
422 }

References $c, ILIAS_UI_TestBase\assertHTMLEquals(), getCounterFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), ILIAS\UI\Component\Symbol\Glyph\Glyph\MAIL, and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_two_counters()

GlyphTest::test_two_counters ( )

Definition at line 247 of file GlyphTest.php.

247 : void
248 {
249 $gf = $this->getGlyphFactory();
250 $cf = $this->getCounterFactory();
251 $number_s = 1;
252 $number_n = 2;
253
254 $g = $gf
255 ->mail()
256 ->withCounter(
257 $cf->status($number_s)
258 )
259 ->withCounter(
260 $cf->novelty($number_n)
261 );
262
263 $counters = $g->getCounters();
264 $this->assertCount(2, $counters);
265 $vals = array_map(function ($c) {
266 return array($c->getType(), $c->getNumber());
267 }, $counters);
268 $this->assertContains(array("status", $number_s), $vals);
269 $this->assertContains(array("novelty", $number_n), $vals);
270 }

References $c, getCounterFactory(), and getGlyphFactory().

+ Here is the call graph for this function:

◆ test_with_highlight()

GlyphTest::test_with_highlight ( )

Definition at line 203 of file GlyphTest.php.

203 : void
204 {
205 $gf = $this->getGlyphFactory();
206
207 $g = $gf->mail();
208 $g2 = $g->withHighlight();
209
210 $this->assertFalse($g->isHighlighted());
211 $this->assertTrue($g2->isHighlighted());
212 }

References getGlyphFactory().

+ Here is the call graph for this function:

◆ test_with_unavailable_action()

GlyphTest::test_with_unavailable_action ( string  $factory_method)

@dataProvider glyph_type_provider

Definition at line 193 of file GlyphTest.php.

193 : void
194 {
195 $f = $this->getGlyphFactory();
196 $g = $f->$factory_method();
197 $g2 = $f->$factory_method()->withUnavailableAction();
198
199 $this->assertTrue($g->isActive());
200 $this->assertFalse($g2->isActive());
201 }

References Vendor\Package\$f, and getGlyphFactory().

+ Here is the call graph for this function:

◆ testIsTabbable()

GlyphTest::testIsTabbable ( )

Definition at line 486 of file GlyphTest.php.

486 : void
487 {
488 $f = $this->getGlyphFactory();
489 $r = $this->getDefaultRenderer();
490
491 // Glyph without Action or Signal
492 $c = $f->user();
493 $this->assertFalse($c->isTabbable());
494
495 // Glyph with Action
496 $c = $f->user()->withAction("#");
497 $this->assertTrue($c->isTabbable());
498
499 // Glyph with Signal
500 $c = $f->user()->withOnClick(new I\Signal("id_1", "click"));
501 $this->assertTrue($c->isTabbable());
502
503 // Glyph with Action and Signal
504 $c = $f->user()->withAction("#")->withOnClick(new I\Signal("id_1", "click"));
505 $this->assertTrue($c->isTabbable());
506
507 // Glyph with Action and Signal but Inactive
508 $c = $f->user()->withAction("#")->withOnClick(new I\Signal("id_1", "click"))->withUnavailableAction();
509 $this->assertFalse($c->isTabbable());
510 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $c, Vendor\Package\$f, ILIAS_UI_TestBase\getDefaultRenderer(), and getGlyphFactory().

+ Here is the call graph for this function:

◆ testTabbableGlyphRender()

GlyphTest::testTabbableGlyphRender ( )

Definition at line 512 of file GlyphTest.php.

512 : void
513 {
514 $f = $this->getGlyphFactory();
515 $r = $this->getDefaultRenderer();
516
517 // Glyph without Action or Signal (not Tabbable)
518 $c = $f->user();
519 $expected = '<a class="glyph" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>';
520 $html = $this->normalizeHTML($r->render($c));
521 $this->assertEquals($expected, $html);
522
523 // Glyph with Action (Tabbable)
524 $c = $f->user()->withAction("#");
525 $expected = '<a tabindex="0" class="glyph" href="#" aria-label="show_who_is_online"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a>';
526 $html = $this->normalizeHTML($r->render($c));
527 $this->assertEquals($expected, $html);
528 }

References $c, Vendor\Package\$f, ILIAS_UI_TestBase\getDefaultRenderer(), getGlyphFactory(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

Field Documentation

◆ $aria_labels

array GlyphTest::$aria_labels
static

Definition at line 94 of file GlyphTest.php.

◆ $canonical_css_classes

array GlyphTest::$canonical_css_classes
static

Definition at line 45 of file GlyphTest.php.


The documentation for this class was generated from the following file: