ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BreadcrumbsTest.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
26
31{
32 public function getFactory(): NoUIFactory
33 {
34 return new class () extends NoUIFactory {
35 public function breadcrumbs(array $crumbs): I\Component\Breadcrumbs\Breadcrumbs
36 {
37 return new I\Component\Breadcrumbs\Breadcrumbs($crumbs);
38 }
39 };
40 }
41
42 public function testImplementsFactoryInterface(): void
43 {
44 $f = $this->getFactory();
45
46 $this->assertInstanceOf("ILIAS\\UI\\Factory", $f);
47 $this->assertInstanceOf(
48 "ILIAS\\UI\\Component\\Breadcrumbs\\Breadcrumbs",
49 $f->breadcrumbs(array())
50 );
51 }
52
53 public function testCrumbs(): void
54 {
55 $f = $this->getFactory();
56 $crumbs = array(
57 new I\Component\Link\Standard("label", '#'),
58 new I\Component\Link\Standard("label2", '#')
59 );
60
61 $c = $f->breadcrumbs($crumbs);
62 $this->assertEquals($crumbs, $c->getItems());
63 }
64
65 public function testAppending(): void
66 {
67 $f = $this->getFactory();
68 $crumb = new I\Component\Link\Standard("label2", '#');
69
70 $c = $f->Breadcrumbs(array())
71 ->withAppendedItem($crumb);
72 $this->assertEquals(array($crumb), $c->getItems());
73 }
74
75 public function testRendering(): void
76 {
77 $f = $this->getFactory();
78 $r = $this->getDefaultRenderer();
79
80 $crumbs = array(
81 new I\Component\Link\Standard("label", '#'),
82 new I\Component\Link\Standard("label2", '#')
83 );
84 $c = $f->Breadcrumbs($crumbs);
85
86 $html = $this->normalizeHTML($r->render($c));
87 $expected = '<nav aria-label="breadcrumbs_aria_label" class="breadcrumb_wrapper">'
88 . ' <div class="breadcrumb">'
89 . ' <span class="crumb">'
90 . ' <a href="#">label</a>'
91 . ' </span>'
92 . ' <span class="crumb">'
93 . ' <a href="#">label2</a>'
94 . ' </span>'
95 . ' </div>'
96 . '</nav>';
97
98 $this->assertHTMLEquals($expected, $html);
99 }
100
102 {
103 $f = $this->getFactory();
104 $r = $this->getDefaultRenderer();
105
106 $label = "label without special characters";
107 $label2 = "label with special characters + –...+}*@ç%#&/($";
108
109 $crumbs = [
110 new I\Component\Link\Standard($label, '#'),
111 new I\Component\Link\Standard($label2, '#')
112 ];
113 $c = $f->Breadcrumbs($crumbs);
114
115 $html = $this->brutallyTrimHTML($r->render($c));
116 $expected = '<nav aria-label="breadcrumbs_aria_label" class="breadcrumb_wrapper">'
117 . ' <div class="breadcrumb">'
118 . ' <span class="crumb">'
119 . ' <a href="#">label without special characters</a>'
120 . ' </span>'
121 . ' <span class="crumb">'
122 . ' <a href="#">label with special characters + –...+}*@ç%#&/($</a>'
123 . '&lrm;'
124 . ' </span>'
125 . ' </div>'
126 . '</nav>';
127
128 $this->assertEquals($this->brutallyTrimHTML($expected), $html);
129 }
130}
Tests for the Breadcrumbs-component.
Provides common functionality for UI tests.
Definition: Base.php:337
$c
Definition: deliver.php:25