ILIAS  release_8 Revision v8.24
BulkyLinkTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
26use ILIAS\Data;
27
32{
33 protected I\Link\Factory $factory;
34 protected I\Symbol\Glyph\Glyph $glyph;
35 protected I\Symbol\Icon\Standard $icon;
36 protected Data\URI $target;
37
38 public function setUp(): void
39 {
40 $this->factory = new I\Link\Factory();
41 $this->glyph = new I\Symbol\Glyph\Glyph("briefcase", "briefcase");
42 $this->icon = new I\Symbol\Icon\Standard("someExample", "Example", "small", false);
43 $this->target = new Data\URI("http://www.ilias.de");
44 }
45
46 public function testImplementsInterfaces(): void
47 {
48 $link = $this->factory->bulky($this->glyph, "label", $this->target);
49 $this->assertInstanceOf(C\Bulky::class, $link);
50 $this->assertInstanceOf(C\Link::class, $link);
51 }
52
53 public function testWrongConstruction(): void
54 {
55 $this->expectException(\TypeError::class);
56 $this->factory->bulky('wrong param', "label", $this->target);
57 }
58
59 public function testWithAriaRole(): void
60 {
61 try {
62 $b = $this->factory->bulky($this->glyph, "label", $this->target)
63 ->withAriaRole(I\Button\Bulky::MENUITEM);
64 $this->assertEquals("menuitem", $b->getAriaRole());
65 } catch (\InvalidArgumentException $e) {
66 $this->assertFalse("This should not happen");
67 }
68 }
69
70 public function testWithAriaRoleIncorrect(): void
71 {
72 try {
73 $this->factory->bulky($this->glyph, "label", $this->target)
74 ->withAriaRole("loremipsum");
75 $this->assertFalse("This should not happen");
76 } catch (\InvalidArgumentException $e) {
77 $this->assertTrue(true);
78 }
79 }
80
81 public function testGetLabell(): void
82 {
83 $label = 'some label for the link';
84 $link = $this->factory->bulky($this->glyph, $label, $this->target);
85 $this->assertEquals($label, $link->getLabel());
86 }
87
88 public function testGetGlyphSymbol(): void
89 {
90 $link = $this->factory->bulky($this->glyph, "label", $this->target);
91 $this->assertEquals($this->glyph, $link->getSymbol());
92 $link = $this->factory->bulky($this->icon, "label", $this->target);
93 $this->assertEquals($this->icon, $link->getSymbol());
94 }
95
96 public function testGetAction(): void
97 {
98 $plain = "http://www.ilias.de";
99 $with_query = $plain . "?query1=1";
100 $with_multi_query = $with_query . "&query2=2";
101 $with_fragment = $plain . "#fragment";
102 $with_multi_query_and_fragment_uri = $with_multi_query . $with_fragment;
103
104 $plain_uri = new Data\URI($plain);
105 $with_query_uri = new Data\URI($with_query);
106 $with_multi_query_uri = new Data\URI($with_multi_query);
107 $with_fragment_uri = new Data\URI($with_fragment);
108 $with_multi_query_and_fragment_uri = new Data\URI($with_multi_query_and_fragment_uri);
109
110 $this->assertEquals($plain, $this->factory->bulky($this->glyph, "label", $plain_uri)->getAction());
111 $this->assertEquals($with_query, $this->factory->bulky($this->glyph, "label", $with_query_uri)->getAction());
112 $this->assertEquals($with_multi_query, $this->factory->bulky($this->glyph, "label", $with_multi_query_uri)->getAction());
113 $this->assertEquals($with_fragment_uri, $this->factory->bulky($this->glyph, "label", $with_fragment_uri)->getAction());
114 $this->assertEquals($with_multi_query_and_fragment_uri, $this->factory->bulky($this->glyph, "label", $with_multi_query_and_fragment_uri)->getAction());
115 }
116
117 public function testRenderingGlyph(): void
118 {
119 $r = $this->getDefaultRenderer();
120 $b = $this->factory->bulky($this->glyph, "label", $this->target);
121
122 $expected = ''
123 . '<a class="il-link link-bulky" href="http://www.ilias.de">'
124 . ' <span class="glyph" role="img">'
125 . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
126 . ' </span>'
127 . ' <span class="bulky-label">label</span>'
128 . '</a>';
129
130 $this->assertHTMLEquals(
131 $expected,
132 $r->render($b)
133 );
134 }
135
136 public function testRenderingIcon(): void
137 {
138 $r = $this->getDefaultRenderer();
139 $b = $this->factory->bulky($this->icon, "label", $this->target);
140
141 $expected = ''
142 . '<a class="il-link link-bulky" href="http://www.ilias.de">'
143 . ' <img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt=""/>'
144 . ' <span class="bulky-label">label</span>'
145 . '</a>';
146
147 $this->assertHTMLEquals(
148 $expected,
149 $r->render($b)
150 );
151 }
152 public function testRenderingWithId(): void
153 {
154 $r = $this->getDefaultRenderer();
155 $b = $this->factory->bulky($this->icon, "label", $this->target)
156 ->withAdditionalOnloadCode(function ($id) {
157 return '';
158 });
159
160 $expected = ''
161 . '<a class="il-link link-bulky" href="http://www.ilias.de" id="id_1">'
162 . '<img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt=""/>'
163 . ' <span class="bulky-label">label</span>'
164 . '</a>';
165
166 $this->assertHTMLEquals(
167 $expected,
168 $r->render($b)
169 );
170 }
171
172 public function testRenderWithAriaRoleMenuitem(): void
173 {
174 $r = $this->getDefaultRenderer();
175 $b = $this->factory->bulky($this->icon, "label", $this->target)
176 ->withAriaRole(I\Button\Bulky::MENUITEM);
177
178 $expected = ''
179 . '<a class="il-link link-bulky" href="http://www.ilias.de" role="menuitem">'
180 . '<img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt=""/>'
181 . ' <span class="bulky-label">label</span>'
182 . '</a>';
183
184 $this->assertHTMLEquals(
185 $expected,
186 $r->render($b)
187 );
188 }
189
191 {
192 $r = $this->getDefaultRenderer();
193 $b = $this->factory->bulky($this->icon, "Example", $this->target)
194 ->withAriaRole(I\Button\Bulky::MENUITEM);
195
196 $expected = ''
197 . '<a class="il-link link-bulky" href="http://www.ilias.de" role="menuitem">'
198 . '<img class="icon someExample small" src="./templates/default/images/icon_default.svg" alt=""/>'
199 . ' <span class="bulky-label">Example</span>'
200 . '</a>';
201
202 $this->assertHTMLEquals(
203 $expected,
204 $r->render($b)
205 );
206 }
207}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Testing behavior of the Bulky Link.
testRenderWithLabelAndAltImageSame()
I Symbol Icon Standard $icon
testRenderWithAriaRoleMenuitem()
Data URI $target
I Link Factory $factory
I Symbol Glyph Glyph $glyph
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Provides common functionality for UI tests.
Definition: Base.php:299
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...