ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BulkyButtonTest.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
26
31{
32 private I\Component\Button\Factory $button_factory;
33 private I\Component\Symbol\Glyph\Glyph $glyph;
34 private I\Component\Symbol\Icon\Standard $icon;
35
36 public function setUp(): void
37 {
38 $this->button_factory = new I\Component\Button\Factory();
39 $this->glyph = new I\Component\Symbol\Glyph\Glyph("briefcase", "briefcase");
40 $this->icon = new I\Component\Symbol\Icon\Standard("someExample", "Example", "small", false);
41 }
42
43 public function testImplementsFactoryInterface(): void
44 {
45 $this->assertInstanceOf(
46 "ILIAS\\UI\\Component\\Button\\Bulky",
47 $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
48 );
49 }
50
51 public function testConstructionIconTypeWrong(): void
52 {
53 $this->expectException(TypeError::class);
54
57 $c = new stdClass();
58 $f->bulky($c, "", "http://www.ilias.de");
59 }
60
61 public function testGlyphOrIconForGlyph(): void
62 {
63 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
64 $this->assertEquals(
65 $this->glyph,
66 $b->getSymbol()
67 );
68 }
69
70 public function testGlyphOrIconForIcon(): void
71 {
72 $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
73 $this->assertEquals(
74 $this->icon,
75 $b->getSymbol()
76 );
77 }
78
79 public function testEngaged(): void
80 {
81 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
82 $this->assertFalse($b->isEngaged());
83 $this->assertFalse($b->isEngageable());
84
85 $b = $b->withEngagedState(true);
86 $this->assertInstanceOf(
87 "ILIAS\\UI\\Component\\Button\\Bulky",
88 $b
89 );
90 $this->assertTrue($b->isEngaged());
91 $this->assertTrue($b->isEngageable());
92 }
93
94 public function testEngageableDisengaged(): void
95 {
96 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
97 $this->assertFalse($b->isEngaged());
98 $this->assertFalse($b->isEngageable());
99
100 $b = $b->withEngagedState(false);
101 $this->assertInstanceOf(
102 "ILIAS\\UI\\Component\\Button\\Bulky",
103 $b
104 );
105 $this->assertFalse($b->isEngaged());
106 $this->assertTrue($b->isEngageable());
107 }
108
109 public function testWithAriaRole(): void
110 {
111 try {
112 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
113 ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
114 $this->assertEquals("menuitem", $b->getAriaRole());
115 } catch (InvalidArgumentException $e) {
116 $this->assertFalse("This should not happen");
117 }
118 }
119
120 public function testWithAriaRoleIncorrect(): void
121 {
122 try {
123 $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
124 ->withAriaRole("loremipsum");
125 $this->assertFalse("This should not happen");
126 } catch (InvalidArgumentException $e) {
127 $this->assertTrue(true);
128 }
129 }
130
131 public function testRenderWithGlyphInContext(): void
132 {
133 $r = $this->getDefaultRenderer();
134 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de");
135
136 $this->assertHTMLEquals(
137 $this->getHtmlWithGlyph(),
138 $r->render($b)
139 );
140 }
141
143 {
144 $r = $this->getDefaultRenderer();
145 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
146 ->withEngagedState(true);
147
148 $this->assertHTMLEquals(
149 $this->getHtmlWithGlyph(true, true),
150 $r->render($b)
151 );
152 }
153
155 {
156 $r = $this->getDefaultRenderer();
157 $b = $this->button_factory->bulky($this->glyph, "label", "http://www.ilias.de")
158 ->withEngagedState(true);
159 $this->assertHTMLEquals(
160 $this->getHtmlWithGlyph(true),
161 $r->render($b)
162 );
163 }
164
165 protected function getHtmlWithGlyph(bool $engeagable = false, bool $engeaged = false): string
166 {
167 $aria_pressed = "";
168 $engaged_class = "";
169 if ($engeagable) {
170 if ($engeagable) {
171 $aria_pressed = " aria-pressed='true'";
172 $engaged_class = " engaged";
173 } else {
174 $aria_pressed = " aria-pressed='false'";
175 $engaged_class = " disengaged";
176 }
177 }
178 return ''
179 . '<button class="btn btn-bulky' . $engaged_class . '" data-action="http://www.ilias.de" id="id_1" ' . $aria_pressed . '>'
180 . ' <span class="glyph" role="img">'
181 . ' <span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>'
182 . ' </span>'
183 . ' <span class="bulky-label">label</span>'
184 . '</button>';
185 }
186
187 public function testRenderWithIcon(): void
188 {
189 $r = $this->getDefaultRenderer();
190 $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de");
191
192 $expected = ''
193 . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1">'
194 . ' <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
195 . ' <span class="bulky-label">label</span>'
196 . '</button>';
197
198 $this->assertHTMLEquals(
199 $expected,
200 $r->render($b)
201 );
202 }
203
205 {
206 $r = $this->getDefaultRenderer();
207 $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de")
208 ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
209
210 $expected = ''
211 . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem">'
212 . ' <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
213 . ' <span class="bulky-label">label</span>'
214 . '</button>';
215
216 $this->assertHTMLEquals(
217 $expected,
218 $r->render($b)
219 );
220 }
221
223 {
224 $r = $this->getDefaultRenderer();
225 $b = $this->button_factory->bulky($this->icon, "label", "http://www.ilias.de")
226 ->withEngagedState(false)
227 ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
228
229 $expected = ''
230 . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem" aria-haspopup="true">'
231 . ' <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
232 . ' <span class="bulky-label">label</span>'
233 . '</button>';
234
235 $this->assertHTMLEquals(
236 $expected,
237 $r->render($b)
238 );
239 }
240
242 {
243 $r = $this->getDefaultRenderer();
244 $b = $this->button_factory->bulky($this->icon, "Example", "http://www.ilias.de")
245 ->withEngagedState(false)
246 ->withAriaRole(I\Component\Button\Bulky::MENUITEM);
247
248 $expected = ''
249 . '<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem" aria-haspopup="true">'
250 . ' <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt=""/>'
251 . ' <span class="bulky-label">Example</span>'
252 . '</button>';
253
254 $this->assertHTMLEquals(
255 $expected,
256 $r->render($b)
257 );
258 }
259 public function testRenderWithHelpTopics(): void
260 {
261 $r = $this->getDefaultRenderer();
262 $b = $this->button_factory->bulky($this->icon, "Example", "http://www.ilias.de")
263 ->withAriaRole(I\Component\Button\Bulky::MENUITEM)
264 ->withHelpTopics(new \ILIAS\UI\Help\Topic("a"));
265 ;
266
267 $expected = <<<EXP
268<div class="c-tooltip__container">
269<button class="btn btn-bulky" data-action="http://www.ilias.de" id="id_1" role="menuitem" aria-describedby="id_2">
270 <img class="icon someExample small" src="./assets/images/standard/icon_default.svg" alt="" /><span class="bulky-label">Example</span>
271 </button>
272<div id="id_2" role="tooltip" class="c-tooltip c-tooltip--hidden"><p>tooltip: a</p></div>
273</div>
274EXP;
275
276 $this->assertHTMLEquals(
277 $expected,
278 $r->render($b)
279 );
280 }
281}
Test on button implementation.
testRenderWithGlyphInContextAndEngaged()
I Component Symbol Glyph Glyph $glyph
testRenderButtonWithAriaRoleMenuitemNotEngageable()
I Component Button Factory $button_factory
testRenderWithGlyphInContextAndDisengaged()
getHtmlWithGlyph(bool $engeagable=false, bool $engeaged=false)
testRenderButtonWithAriaRoleMenuitemIsEngageable()
I Component Symbol Icon Standard $icon
Provides common functionality for UI tests.
Definition: Base.php:337
$c
Definition: deliver.php:25
button(string $caption, string $cmd)
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.