ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BulkyLinkTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
26use ILIAS\Data;
29
34{
35 protected I\Link\Factory $factory;
36 protected I\Symbol\Glyph\Glyph $glyph;
37 protected I\Symbol\Icon\Standard $icon;
38 protected Data\URI $target;
39
40 public function setUp(): void
41 {
42 $this->factory = new I\Link\Factory();
43 $this->glyph = new I\Symbol\Glyph\Glyph("briefcase", "briefcase");
44 $this->icon = new I\Symbol\Icon\Standard("someExample", "Example", "small", false);
45 $this->target = new Data\URI("http://www.ilias.de");
46 }
47
48 public function testImplementsInterfaces(): void
49 {
50 $link = $this->factory->bulky($this->glyph, "label", $this->target);
51 $this->assertInstanceOf(C\Bulky::class, $link);
52 $this->assertInstanceOf(C\Link::class, $link);
53 }
54
55 public function testWrongConstruction(): void
56 {
57 $this->expectException(\TypeError::class);
58 $this->factory->bulky('wrong param', "label", $this->target);
59 }
60
61 public function testWithAriaRole(): void
62 {
63 try {
64 $b = $this->factory->bulky($this->glyph, "label", $this->target)
65 ->withAriaRole(I\Button\Bulky::MENUITEM);
66 $this->assertEquals("menuitem", $b->getAriaRole());
67 } catch (\InvalidArgumentException $e) {
68 $this->assertFalse("This should not happen");
69 }
70 }
71
72 public function testWithAriaRoleIncorrect(): void
73 {
74 try {
75 $this->factory->bulky($this->glyph, "label", $this->target)
76 ->withAriaRole("loremipsum");
77 $this->assertFalse("This should not happen");
78 } catch (\InvalidArgumentException $e) {
79 $this->assertTrue(true);
80 }
81 }
82
83 public function testGetLabell(): void
84 {
85 $label = 'some label for the link';
86 $link = $this->factory->bulky($this->glyph, $label, $this->target);
87 $this->assertEquals($label, $link->getLabel());
88 }
89
90 public function testGetGlyphSymbol(): void
91 {
92 $link = $this->factory->bulky($this->glyph, "label", $this->target);
93 $this->assertEquals($this->glyph, $link->getSymbol());
94 $link = $this->factory->bulky($this->icon, "label", $this->target);
95 $this->assertEquals($this->icon, $link->getSymbol());
96 }
97
98 public function testGetAction(): void
99 {
100 $plain = "http://www.ilias.de";
101 $with_query = $plain . "?query1=1";
102 $with_multi_query = $with_query . "&query2=2";
103 $with_fragment = $plain . "#fragment";
104 $with_multi_query_and_fragment_uri = $with_multi_query . $with_fragment;
105
106 $plain_uri = new Data\URI($plain);
107 $with_query_uri = new Data\URI($with_query);
108 $with_multi_query_uri = new Data\URI($with_multi_query);
109 $with_fragment_uri = new Data\URI($with_fragment);
110 $with_multi_query_and_fragment_uri = new Data\URI($with_multi_query_and_fragment_uri);
111
112 $this->assertEquals($plain, $this->factory->bulky($this->glyph, "label", $plain_uri)->getAction());
113 $this->assertEquals($with_query, $this->factory->bulky($this->glyph, "label", $with_query_uri)->getAction());
114 $this->assertEquals($with_multi_query, $this->factory->bulky($this->glyph, "label", $with_multi_query_uri)->getAction());
115 $this->assertEquals($with_fragment_uri, $this->factory->bulky($this->glyph, "label", $with_fragment_uri)->getAction());
116 $this->assertEquals($with_multi_query_and_fragment_uri, $this->factory->bulky($this->glyph, "label", $with_multi_query_and_fragment_uri)->getAction());
117 }
118
119 public function testRenderingGlyph(): void
120 {
121 $r = $this->getDefaultRenderer();
122 $b = $this->factory->bulky($this->glyph, "label", $this->target);
123
124 $expected = ''
125 . '<a class="il-link link-bulky" href="http://www.ilias.de">'
126 . ' <span class="glyph" role="img">'
127 . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
128 . ' </span>'
129 . ' <span class="bulky-label">label</span>'
130 . '</a>';
131
132 $this->assertHTMLEquals(
133 $expected,
134 $r->render($b)
135 );
136 }
137
138 public function testRenderingIcon(): void
139 {
140 $r = $this->getDefaultRenderer();
141 $b = $this->factory->bulky($this->icon, "label", $this->target);
142
143 $expected = ''
144 . '<a class="il-link link-bulky" href="http://www.ilias.de">'
145 . ' <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
146 . ' <span class="bulky-label">label</span>'
147 . '</a>';
148
149 $this->assertHTMLEquals(
150 $expected,
151 $r->render($b)
152 );
153 }
154 public function testRenderingWithId(): void
155 {
156 $r = $this->getDefaultRenderer();
157 $b = $this->factory->bulky($this->icon, "label", $this->target)
158 ->withAdditionalOnloadCode(function ($id) {
159 return '';
160 });
161
162 $expected = ''
163 . '<a class="il-link link-bulky" href="http://www.ilias.de" id="id_1">'
164 . '<img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
165 . ' <span class="bulky-label">label</span>'
166 . '</a>';
167
168 $this->assertHTMLEquals(
169 $expected,
170 $r->render($b)
171 );
172 }
173
174 public function testRenderWithAriaRoleMenuitem(): void
175 {
176 $r = $this->getDefaultRenderer();
177 $b = $this->factory->bulky($this->icon, "label", $this->target)
178 ->withAriaRole(I\Button\Bulky::MENUITEM);
179
180 $expected = ''
181 . '<a class="il-link link-bulky" href="http://www.ilias.de" role="menuitem">'
182 . '<img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
183 . ' <span class="bulky-label">label</span>'
184 . '</a>';
185
186 $this->assertHTMLEquals(
187 $expected,
188 $r->render($b)
189 );
190 }
191
193 {
194 $r = $this->getDefaultRenderer();
195 $b = $this->factory->bulky($this->icon, "Example", $this->target)
196 ->withAriaRole(I\Button\Bulky::MENUITEM);
197
198 $expected = ''
199 . '<a class="il-link link-bulky" href="http://www.ilias.de" role="menuitem">'
200 . '<img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
201 . ' <span class="bulky-label">Example</span>'
202 . '</a>';
203
204 $this->assertHTMLEquals(
205 $expected,
206 $r->render($b)
207 );
208 }
209
210 public function testRenderWithLanguage(): void
211 {
212 $language = $this->getMockBuilder(LanguageTag::class)->getMock();
213 $language->method('__toString')->willReturn('en');
214 $reference = $this->getMockBuilder(LanguageTag::class)->getMock();
215 $reference->method('__toString')->willReturn('fr');
216
217 $r = $this->getDefaultRenderer();
218 $b = $this->factory->bulky($this->icon, "label", $this->target)
219 ->withContentLanguage($language)
220 ->withLanguageOfReferencedContent($reference);
221
222 $expected = ''
223 . '<a lang="en" hreflang="fr" class="il-link link-bulky" href="http://www.ilias.de">'
224 . '<img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
225 . ' <span class="bulky-label">label</span>'
226 . '</a>';
227
228 $this->assertHTMLEquals(
229 $expected,
230 $r->render($b)
231 );
232 }
233
234 public function testRenderWithHelpTopic(): void
235 {
236 $r = $this->getDefaultRenderer();
237 $b = $this->factory->bulky($this->icon, "label", $this->target)
238 ->withHelpTopics(new \ILIAS\UI\Help\Topic("a"));
239
240 $html = $r->render($b);
241 $expected_html = <<<EXP
242 <div class="c-tooltip__container">
243 <a class="il-link link-bulky" aria-describedby="id_1" href="http://www.ilias.de" id="id_2">
244 <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt="" />
245 <span class="bulky-label">label</span>
246 </a>
247 <div id="id_1" role="tooltip" class="c-tooltip c-tooltip--hidden"><p>tooltip: a</p></div>
248 </div>
249EXP;
250
251 $this->assertHTMLEquals($expected_html, $html);
252 }
253
254 public function testRenderWithRelationships(): void
255 {
256 $r = $this->getDefaultRenderer();
257 $b = $this->factory->bulky($this->icon, "label", $this->target)
258 ->withAdditionalRelationshipToReferencedResource(Relationship::LICENSE)
259 ->withAdditionalRelationshipToReferencedResource(Relationship::NOOPENER);
260
261 $expected_html = <<<EXP
262 <a class="il-link link-bulky" href="http://www.ilias.de" rel="license noopener">
263 <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>
264 <span class="bulky-label">label</span>
265 </a>
266EXP;
267
268 $html = $r->render($b);
269 $this->assertHTMLEquals($expected_html, $html);
270 }
271
273 {
274 $r = $this->getDefaultRenderer();
275 $b = $this->factory->bulky($this->icon, "label", $this->target)
276 ->withAdditionalRelationshipToReferencedResource(Relationship::LICENSE)
277 ->withAdditionalRelationshipToReferencedResource(Relationship::NOOPENER)
278 ->withAdditionalRelationshipToReferencedResource(Relationship::LICENSE);
279
280 $expected_html = <<<EXP
281 <a class="il-link link-bulky" href="http://www.ilias.de" rel="license noopener">
282 <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>
283 <span class="bulky-label">label</span>
284 </a>
285EXP;
286
287 $html = $r->render($b);
288 $this->assertHTMLEquals($expected_html, $html);
289 }
290
291 public function testBulkyLinkRenderWithDisabled(): void
292 {
293 $r = $this->getDefaultRenderer();
294 $b = $this->factory->bulky($this->icon, "label", $this->target)
295 ->withDisabled(true);
296 $expected_html = <<<EXP
297 <a class="il-link link-bulky" aria-disabled="true">
298 <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>
299 <span class="bulky-label">label</span>
300 </a>
301EXP;
302 $this->assertHTMLEquals($expected_html, $r->render($b));
303 }
304}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
factory()
Testing behavior of the Bulky Link.
testRenderWithLabelAndAltImageSame()
I Symbol Icon Standard $icon
testBulkyLinkRenderWithDisabled()
testRenderWithAriaRoleMenuitem()
Data URI $target
I Link Factory $factory
I Symbol Glyph Glyph $glyph
testRenderWithDuplicateRelationship()
Definition: UI.php:24
Provides common functionality for UI tests.
Definition: Base.php:337
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.