ILIAS  release_8 Revision v8.24
MainBarTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
28use ILIAS\Data;
29use PHPUnit\Framework\MockObject\MockObject;
30
35{
36 protected I\Button\Factory $button_factory;
37 protected I\Link\Factory $link_factory;
38 protected I\Symbol\Icon\Factory $icon_factory;
39 protected I\MainControls\Factory $factory;
40 protected C\MainControls\MainBar $mainbar;
41
42 public function setUp(): void
43 {
44 $sig_gen = new I\SignalGenerator();
45 $this->button_factory = new I\Button\Factory();
46 $this->link_factory = new I\Link\Factory();
47 $this->icon_factory = new I\Symbol\Icon\Factory();
48 $counter_factory = new I\Counter\Factory();
49 $slate_factory = new I\MainControls\Slate\Factory(
50 $sig_gen,
51 $counter_factory,
52 new I\Symbol\Factory(
53 new I\Symbol\Icon\Factory(),
54 new I\Symbol\Glyph\Factory(),
55 new I\Symbol\Avatar\Factory()
56 )
57 );
58 $this->factory = new I\MainControls\Factory($sig_gen, $slate_factory);
59
60 $this->mainbar = $this->factory->mainBar();
61 }
62
63 public function testConstruction(): void
64 {
65 $this->assertInstanceOf(
66 "ILIAS\\UI\\Component\\MainControls\\MainBar",
67 $this->mainbar
68 );
69 }
70
71 protected function getButton(): C\Button\Bulky
72 {
73 $symbol = $this->icon_factory->custom('', '');
74 return $this->button_factory->bulky($symbol, 'TestEntry', '#');
75 }
76
77 protected function getLink(): C\Link\Bulky
78 {
79 $symbol = $this->icon_factory->custom('', '');
80 $target = new Data\URI("http://www.ilias.de");
81 return $this->link_factory->bulky($symbol, 'TestEntry', $target);
82 }
83
87 protected function getSlate()
88 {
89 $mock = $this->getMockBuilder(Legacy::class)
90 ->disableOriginalConstructor()
91 ->getMock();
92
93 return $mock;
94 }
95
96 public function testAddEntry(): C\MainControls\MainBar
97 {
98 $btn = $this->getButton();
99 $lnk = $this->getLink();
100 $mb = $this->mainbar
101 ->withAdditionalEntry('testbtn', $btn)
102 ->withAdditionalEntry('testlnk', $lnk);
103
104 $entries = $mb->getEntries();
105 $expected = [
106 'testbtn' => $btn,
107 'testlnk' => $lnk,
108 ];
109 $this->assertEquals($expected, $entries);
110 return $mb;
111 }
112
113 public function testDisallowedEntry(): void
114 {
115 $this->expectException(InvalidArgumentException::class);
116 $this->mainbar->withAdditionalEntry('test', 'wrong_param');
117 }
118
119 public function testDouplicateIdEntry(): void
120 {
121 $this->expectException(InvalidArgumentException::class);
122 $btn = $this->getButton();
123 $this->mainbar
124 ->withAdditionalEntry('test', $btn)
125 ->withAdditionalEntry('test', $btn);
126 }
127
128 public function testDisallowedToolEntry(): void
129 {
130 $this->expectException(\TypeError::class);
131 $this->mainbar->withAdditionalToolEntry('test', 'wrong_param');
132 }
133
135 {
136 $this->expectException(LogicException::class);
137 $this->mainbar->withAdditionalToolEntry('test', $this->getSlate());
138 }
139
140 public function testAddToolEntry(): void
141 {
142 $slate = $this->getSlate();
143 $mb = $this->mainbar
144 ->withToolsButton($this->getButton())
145 ->withAdditionalToolEntry('test', $slate);
146 $entries = $mb->getToolEntries();
147 $this->assertEquals($slate, $entries['test']);
148 }
149
150 public function testDouplicateIdToolEntry(): void
151 {
152 $this->expectException(InvalidArgumentException::class);
153 $btn = $this->getButton();
154 $slate = $this->getSlate();
155 $this->mainbar
156 ->withToolsButton($btn)
157 ->withAdditionalToolEntry('test', $slate)
158 ->withAdditionalToolEntry('test', $slate);
159 }
160
164 public function testActive(C\MainControls\MainBar $mb): void
165 {
166 $mb = $mb->withActive('testbtn');
167 $this->assertEquals('testbtn', $mb->getActive());
168 }
169
170 public function testWithInvalidActive(): void
171 {
172 $this->expectException(InvalidArgumentException::class);
173 $this->mainbar->withActive('this-is-not-a-valid-entry');
174 }
175
176 public function testSignalsPresent(): void
177 {
178 $this->assertInstanceOf(Signal::class, $this->mainbar->getEntryClickSignal());
179 $this->assertInstanceOf(Signal::class, $this->mainbar->getToolsClickSignal());
180 $this->assertInstanceOf(Signal::class, $this->mainbar->getToolsRemovalSignal());
181 $this->assertInstanceOf(Signal::class, $this->mainbar->getDisengageAllSignal());
182 }
183
184 public function getUIFactory(): NoUIFactory
185 {
186 $factory = new class () extends NoUIFactory {
187 public C\Button\Factory $button_factory;
188
189 public function button(): C\Button\Factory
190 {
192 }
193 public function symbol(): C\Symbol\Factory
194 {
195 $f_icon = new I\Symbol\Icon\Factory();
196 $f_glyph = new I\Symbol\Glyph\Factory();
197 $f_avatar = new I\Symbol\Avatar\Factory();
198
199 return new I\Symbol\Factory($f_icon, $f_glyph, $f_avatar);
200 }
201 public function mainControls(): C\MainControls\Factory
202 {
203 $sig_gen = new I\SignalGenerator();
204 $counter_factory = new I\Counter\Factory();
205 $symbol_factory = new I\Symbol\Factory(
206 new I\Symbol\Icon\Factory(),
207 new I\Symbol\Glyph\Factory(),
208 new I\Symbol\Avatar\Factory()
209 );
210 $slate_factory = new I\MainControls\Slate\Factory($sig_gen, $counter_factory, $symbol_factory);
211 return new I\MainControls\Factory($sig_gen, $slate_factory);
212 }
213 public function legacy(string $content): C\Legacy\Legacy
214 {
215 $sig_gen = new I\SignalGenerator();
216 return new I\Legacy\Legacy($content, $sig_gen);
217 }
218 };
219 $factory->button_factory = $this->button_factory;
220 return $factory;
221 }
222
223 public function testRendering(): void
224 {
225 $r = $this->getDefaultRenderer();
226 $icon = $this->icon_factory->custom('', '');
227
228 $sf = $this->factory->slate();
229 $slate = $sf->combined('1', $icon)
230 ->withAdditionalEntry(
231 $sf->combined('1.1', $icon)
232 ->withAdditionalEntry(
233 $sf->combined('1.1.1', $icon)
234 )
235 );
236
237 $toolslate = $sf->legacy('Help', $icon, new I\Legacy\Legacy('Help', new I\SignalGenerator()));
238
239 $mb = $this->factory->mainBar()
240 ->withAdditionalEntry('test1', $this->getButton())
241 ->withAdditionalEntry('test2', $this->getButton())
242 ->withAdditionalEntry('slate', $slate)
243 ->withToolsButton($this->getButton())
244 ->withAdditionalToolEntry('tool1', $toolslate);
245
246 $html = $r->render($mb);
247
248 $expected = <<<EOT
249 <div class="il-maincontrols-mainbar" id="id_16">
250 <nav class="il-mainbar" aria-label="mainbar_aria_label">
251 <div class="il-mainbar-tools-button">
252 <button class="btn btn-bulky" id="id_14">
253 <img class="icon custom small" src="" alt=""/>
254 <span class="bulky-label">TestEntry</span>
255 </button>
256 </div>
257 <div class="il-mainbar-triggers">
258 <ul class="il-mainbar-entries" role="menubar" style="visibility: hidden">
259 <li role="none">
260 <button class="btn btn-bulky" data-action="#" id="id_1" role="menuitem">
261 <img class="icon custom small" src="" alt=""/>
262 <span class="bulky-label">TestEntry</span>
263 </button>
264 </li>
265 <li role="none">
266 <button class="btn btn-bulky" data-action="#" id="id_2" role="menuitem">
267 <img class="icon custom small" src="" alt=""/>
268 <span class="bulky-label">TestEntry</span>
269 </button>
270 </li>
271 <li role="none">
272 <button class="btn btn-bulky" id="id_3" role="menuitem">
273 <img class="icon custom small" src="" alt=""/>
274 <span class="bulky-label">1</span>
275 </button>
276 </li>
277 <li role="none">
278 <button class="btn btn-bulky" id="id_9" role="menuitem">
279 <span class="glyph" role="img">
280 <span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span>
281 </span>
282 <span class="bulky-label">mainbar_more_label</span>
283 </button>
284 </li>
285 </ul>
286 </div>
287 </nav>
288 <div class="il-mainbar-slates">
289 <div class="il-mainbar-tools-entries">
290 <ul class="il-mainbar-tools-entries-bg" role="menubar">
291 <li class="il-mainbar-tool-trigger-item" role="none">
292 <button class="btn btn-bulky" id="id_11" role="menuitem">
293 <img class="icon custom small" src="" alt=""/>
294 <span class="bulky-label">Help</span>
295 </button>
296 </li>
297 </ul>
298 </div>
299 <div class="il-maincontrols-slate disengaged" id="id_8" data-depth-level="1" role="menu">
300 <div class="il-maincontrols-slate-content" data-replace-marker="content">
301 <ul>
302 <li>
303 <button class="btn btn-bulky" id="id_4">
304 <img class="icon custom small" src="" alt=""/>
305 <span class="bulky-label">1.1</span>
306 </button>
307 <div class="il-maincontrols-slate disengaged" id="id_7" data-depth-level="2">
308 <div class="il-maincontrols-slate-content" data-replace-marker="content">
309 <ul>
310 <li>
311 <button class="btn btn-bulky" id="id_5">
312 <img class="icon custom small" src="" alt=""/>
313 <span class="bulky-label">1.1.1</span>
314 </button>
315 <div class="il-maincontrols-slate disengaged" id="id_6" data-depth-level="3">
316 <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
317 </div>
318 </li>
319 </ul>
320 </div>
321 </div>
322 </li>
323 </ul>
324 </div>
325 </div>
326 <div class="il-maincontrols-slate disengaged" id="id_10" data-depth-level="1" role="menu">
327 <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
328 </div>
329 <div class="il-maincontrols-slate disengaged" id="id_13" data-depth-level="1" role="menu">
330 <div class="il-maincontrols-slate-content" data-replace-marker="content">Help</div>
331 </div>
332 <div class="il-mainbar-close-slates">
333 <button class="btn btn-bulky" id="id_15">
334 <span class="glyph" role="img">
335 <span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>
336 </span>
337 <span class="bulky-label">close</span>
338 </button>
339 </div>
340 </div>
341 </div>
342EOT;
343
344 $this->assertEquals(
345 $this->brutallyTrimHTML($expected),
346 $this->brutallyTrimHTML($html)
347 );
348 }
349}
Builds data types.
Definition: Factory.php:21
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
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Tests for the Main Bar.
Definition: MainBarTest.php:35
I Button Factory $button_factory
Definition: MainBarTest.php:36
I Link Factory $link_factory
Definition: MainBarTest.php:37
testActive(C\MainControls\MainBar $mb)
@depends testAddEntry
I MainControls Factory $factory
Definition: MainBarTest.php:39
testDouplicateIdToolEntry()
I Symbol Icon Factory $icon_factory
Definition: MainBarTest.php:38
testAddToolEntryWithoutToolsButton()
testWithInvalidActive()
testDouplicateIdEntry()
testDisallowedToolEntry()
C MainControls MainBar $mainbar
Definition: MainBarTest.php:40
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...