ILIAS  release_8 Revision v8.24
PanelTest.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
27
29{
30 protected string $id;
31
32 public function __construct($id = "")
33 {
34 $this->id = $id;
35 }
36 public function getCanonicalName(): string
37 {
38 return "Component Dummy";
39 }
40}
41
46{
47 public function getUIFactory(): NoUIFactory
48 {
49 return new class () extends NoUIFactory {
50 public function panelSecondary(): I\Component\Panel\Secondary\Factory
51 {
52 return new I\Component\Panel\Secondary\Factory();
53 }
54 public function dropdown(): I\Component\Dropdown\Factory
55 {
56 return new I\Component\Dropdown\Factory();
57 }
58 public function viewControl(): I\Component\ViewControl\Factory
59 {
60 return new I\Component\ViewControl\Factory(new SignalGenerator());
61 }
62 public function button(): I\Component\Button\Factory
63 {
64 return new I\Component\Button\Factory();
65 }
66 public function symbol(): C\Symbol\Factory
67 {
68 return new I\Component\Symbol\Factory(
69 new I\Component\Symbol\Icon\Factory(),
70 new I\Component\Symbol\Glyph\Factory(),
71 new I\Component\Symbol\Avatar\Factory()
72 );
73 }
74 };
75 }
76
77 public function getPanelFactory(): I\Component\Panel\Factory
78 {
79 return new I\Component\Panel\Factory(
80 $this->createMock(C\Panel\Listing\Factory::class)
81 );
82 }
83
84 public function test_implements_factory_interface(): void
85 {
86 $f = $this->getPanelFactory();
87
88 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Factory", $f);
89 $this->assertInstanceOf(
90 "ILIAS\\UI\\Component\\Panel\\Standard",
91 $f->standard("Title", array(new ComponentDummy()))
92 );
93 $this->assertInstanceOf(
94 "ILIAS\\UI\\Component\\Panel\\Sub",
95 $f->sub("Title", array(new ComponentDummy()))
96 );
97 $this->assertInstanceOf(
98 "ILIAS\\UI\\Component\\Panel\\Report",
99 $f->report("Title", $f->sub("Title", array(new ComponentDummy())))
100 );
101 }
102
103 public function test_standard_get_title(): void
104 {
105 $f = $this->getPanelFactory();
106 $p = $f->standard("Title", array(new ComponentDummy()));
107
108 $this->assertEquals("Title", $p->getTitle());
109 }
110
111 public function test_standard_get_content(): void
112 {
113 $f = $this->getPanelFactory();
114 $c = new ComponentDummy();
115 $p = $f->standard("Title", array($c));
116
117 $this->assertEquals($p->getContent(), array($c));
118 }
119
120 public function test_standard_with_actions(): void
121 {
122 $fp = $this->getPanelFactory();
123
124 $p = $fp->standard("Title", array(new ComponentDummy()));
125
126 $actions = new I\Component\Dropdown\Standard(array(
127 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
128 new I\Component\Button\Shy("GitHub", "https://www.github.com")
129 ));
130
131 $p = $p->withActions($actions);
132
133 $this->assertEquals($p->getActions(), $actions);
134 }
135
136 public function test_sub_with_actions(): void
137 {
138 $fp = $this->getPanelFactory();
139
140 $p = $fp->sub("Title", array(new ComponentDummy()));
141
142 $actions = new I\Component\Dropdown\Standard(array(
143 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
144 new I\Component\Button\Shy("GitHub", "https://www.github.com")
145 ));
146
147 $p = $p->withActions($actions);
148
149 $this->assertEquals($p->getActions(), $actions);
150 }
151
152 public function test_sub_with_card(): void
153 {
154 $fp = $this->getPanelFactory();
155
156 $p = $fp->sub("Title", array(new ComponentDummy()));
157
158 $card = new I\Component\Card\Card("Card Title");
159
160 $p = $p->withFurtherInformation($card);
161
162 $this->assertEquals($p->getFurtherInformation(), $card);
163 }
164
165 public function test_sub_with_secondary_panel(): void
166 {
167 $fp = $this->getPanelFactory();
168
169 $p = $fp->sub("Title", array(new ComponentDummy()));
170
171 $legacy = new I\Component\Legacy\Legacy("Legacy content", new SignalGenerator());
172 $secondary = new I\Component\Panel\Secondary\Legacy("Legacy panel title", $legacy);
173
174 $p = $p->withFurtherInformation($secondary);
175
176 $this->assertEquals($p->getFurtherInformation(), $secondary);
177 }
178
179 public function test_report_get_title(): void
180 {
181 $f = $this->getPanelFactory();
182 $sub = $f->sub("Title", array(new ComponentDummy()));
183 $p = $f->report("Title", array($sub));
184
185 $this->assertEquals("Title", $p->getTitle());
186 }
187
188 public function test_report_get_content(): void
189 {
190 $f = $this->getPanelFactory();
191 $sub = $f->sub("Title", array(new ComponentDummy()));
192 $p = $f->report("Title", [$sub]);
193
194 $this->assertEquals($p->getContent(), array($sub));
195 }
196 public function test_render_standard(): void
197 {
198 $f = $this->getPanelFactory();
199 $r = $this->getDefaultRenderer();
200
201 $actions = new I\Component\Dropdown\Standard(array(
202 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
203 new I\Component\Button\Shy("GitHub", "https://www.github.com")
204 ));
205
206 $p = $f->standard("Title", array())->withActions($actions);
207
208 $html = $r->render($p);
209
210 $expected_html = <<<EOT
211<div class="panel panel-primary panel-flex">
212 <div class="panel-heading ilHeader">
213 <h2>Title</h2>
214 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="id_3" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu"> <span class="caret"></span></button>
215 <ul id="id_3_menu" class="dropdown-menu">
216 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
217 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
218 </ul>
219 </div>
220 </div>
221 <div class="panel-body"></div>
222</div>
223EOT;
224 $this->assertHTMLEquals($expected_html, $html);
225 }
226
227 public function test_render_sub(): void
228 {
229 $fp = $this->getPanelFactory();
230 $r = $this->getDefaultRenderer();
231
232 $actions = new I\Component\Dropdown\Standard(array(
233 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
234 new I\Component\Button\Shy("GitHub", "https://www.github.com")
235 ));
236
237 $p = $fp->sub("Title", array())->withActions($actions);
238 $card = new I\Component\Card\Card("Card Title");
239
240 $p = $p->withFurtherInformation($card);
241 $html = $this->brutallyTrimHTML($r->render($p));
242
243 $expected_html = <<<EOT
244<div class="panel panel-sub panel-flex">
245 <div class="panel-heading ilBlockHeader">
246 <h3>Title</h3>
247 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="id_3" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu"> <span class="caret"></span></button>
248 <ul id="id_3_menu" class="dropdown-menu">
249 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
250 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
251 </ul>
252 </div>
253 </div>
254 <div class="panel-body">
255 <div class="row">
256 <div class="col-sm-8"></div>
257 <div class="col-sm-4">
258 <div class="il-card thumbnail">
259 <div class="card-no-highlight"></div>
260 <div class="caption card-title">Card Title</div>
261 </div>
262 </div>
263 </div>
264 </div>
265</div>
266EOT;
267
268 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
269 }
270
272 {
273 $fp = $this->getPanelFactory();
274 $r = $this->getDefaultRenderer();
275
276 $p = $fp->sub("Title", array());
277 $legacy = new I\Component\Legacy\Legacy("Legacy content", new SignalGenerator());
278 $secondary = new I\Component\Panel\Secondary\Legacy("Legacy panel title", $legacy);
279 $p = $p->withFurtherInformation($secondary);
280 $html = $r->render($p);
281
282 $expected_html = <<<EOT
283<div class="panel panel-sub panel-flex">
284 <div class="panel-heading ilBlockHeader">
285 <h3>Title</h3>
286 </div>
287 <div class="panel-body">
288 <div class="row">
289 <div class="col-sm-8"></div>
290 <div class="col-sm-4">
291 <div class="panel panel-secondary panel-flex">
292 <div class="panel-heading ilHeader">
293 <h2>Legacy panel title</h2>
294 </div>
295 <div class="panel-body">Legacy content</div>
296 </div>
297 </div>
298 </div>
299 </div>
300</div>
301EOT;
302
303 $this->assertHTMLEquals(
304 $this->brutallyTrimHTML($expected_html),
305 $this->brutallyTrimHTML($html)
306 );
307 }
308
309 public function test_render_report(): void
310 {
311 $fp = $this->getPanelFactory();
312 $r = $this->getDefaultRenderer();
313 $sub = $fp->sub("Title", array());
314 $card = new I\Component\Card\Card("Card Title");
315 $sub = $sub->withFurtherInformation($card);
316 $report = $fp->report("Title", $sub);
317
318 $html = $this->brutallyTrimHTML($r->render($report));
319
320 $expected_html = <<<EOT
321<div class="panel panel-primary il-panel-report panel-flex">
322 <div class="panel-heading ilHeader">
323 <h2>Title</h2>
324 </div>
325 <div class="panel-body">
326 <div class="panel panel-sub panel-flex">
327 <div class="panel-heading ilBlockHeader">
328 <h3>Title</h3>
329 </div>
330 <div class="panel-body"><div class="row">
331 <div class="col-sm-8"></div>
332 <div class="col-sm-4">
333 <div class="il-card thumbnail">
334 <div class="card-no-highlight"></div>
335 <div class="caption card-title">Card Title</div>
336 </div>
337 </div>
338 </div>
339 </div>
340 </div>
341 </div>
342</div>
343EOT;
344
345 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
346 }
347
348 public function test_with_view_controls(): void
349 {
350 $sort_options = [
351 'a' => 'A',
352 'b' => 'B'
353 ];
354 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
355 $f = $this->getPanelFactory();
356 $p = $f->standard("Title", [])
357 ->withViewControls([$sortation])
358 ;
359
360 $this->assertEquals($p->getViewControls(), [$sortation]);
361 }
362
363 public function test_render_with_sortation(): void
364 {
365 $sort_options = [
366 'a' => 'A',
367 'b' => 'B'
368 ];
369 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
370
371 $f = $this->getPanelFactory();
372 $r = $this->getDefaultRenderer();
373
374
375 $p = $f->standard("Title", [])
376 ->withViewControls([$sortation]);
377 ;
378
379 $html = $r->render($p);
380
381 $expected_html = <<<EOT
382<div class="panel panel-primary panel-flex">
383 <div class="panel-heading ilHeader">
384 <h2>Title</h2>
385 <div class="il-viewcontrol-sortation" id="id_1">
386<div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="id_4" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_4_menu"> <span class="caret"></span></button>
387<ul id="id_4_menu" class="dropdown-menu">
388 <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button>
389</li>
390 <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button>
391</li>
392</ul>
393</div>
394</div>
395 </div>
396 <div class="panel-body"></div>
397</div>
398EOT;
399 $this->assertHTMLEquals($expected_html, $html);
400 }
401
402 public function test_render_with_pagination(): void
403 {
404 $pagination = $this->getUIFactory()->viewControl()->pagination()
405 ->withTargetURL('http://ilias.de', 'page')
406 ->withTotalEntries(10)
407 ->withPageSize(2)
408 ->withCurrentPage(1);
409
410 $f = $this->getPanelFactory();
411 $r = $this->getDefaultRenderer();
412
413
414 $p = $f->standard("Title", [])
415 ->withViewControls([$pagination]);
416
417 $html = $r->render($p);
418
419 $expected_html = <<<EOT
420<div class="panel panel-primary panel-flex">
421 <div class="panel-heading ilHeader">
422 <h2>Title</h2>
423 <div class="il-viewcontrol-pagination">
424 <span class="browse previous">
425 <a tabindex="0" class="glyph" href="http://ilias.de?page=0" aria-label="back">
426 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
427 </a>
428 </span>
429 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
430 <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
431 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
432 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
433 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
434 <span class="browse next">
435 <a tabindex="0" class="glyph" href="http://ilias.de?page=2" aria-label="next">
436 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
437 </a>
438 </span>
439 </div>
440 </div>
441 <div class="panel-body"></div>
442</div>
443EOT;
444 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
445 }
446}
__construct($id="")
Definition: PanelTest.php:32
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:36
Provides common functionality for UI tests.
Definition: Base.php:299
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
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
Test on button implementation.
Definition: PanelTest.php:46
getPanelFactory()
Definition: PanelTest.php:77
test_standard_with_actions()
Definition: PanelTest.php:120
test_render_sub_with_secondary_panel()
Definition: PanelTest.php:271
test_render_with_pagination()
Definition: PanelTest.php:402
test_standard_get_content()
Definition: PanelTest.php:111
test_sub_with_secondary_panel()
Definition: PanelTest.php:165
test_sub_with_card()
Definition: PanelTest.php:152
test_report_get_title()
Definition: PanelTest.php:179
getUIFactory()
Definition: PanelTest.php:47
test_with_view_controls()
Definition: PanelTest.php:348
test_render_report()
Definition: PanelTest.php:309
test_report_get_content()
Definition: PanelTest.php:188
test_render_standard()
Definition: PanelTest.php:196
test_render_with_sortation()
Definition: PanelTest.php:363
test_render_sub()
Definition: PanelTest.php:227
test_sub_with_actions()
Definition: PanelTest.php:136
test_standard_get_title()
Definition: PanelTest.php:103
test_implements_factory_interface()
Definition: PanelTest.php:84
Title class.
Definition: Title.php:27
$c
Definition: cli.php:38
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Breadcrumbs.php:21
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...
Definition: Avatar.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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.