ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PanelTest.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
27
29{
30 use I\Component\ComponentHelper;
31
32 protected string $id;
33
34 public function __construct($id = "")
35 {
36 $this->id = $id;
37 }
38 public function getCanonicalName(): string
39 {
40 return "Component Dummy";
41 }
42}
43
48{
49 public function getUIFactory(): NoUIFactory
50 {
51 return new class () extends NoUIFactory {
52 public function panelSecondary(): I\Component\Panel\Secondary\Factory
53 {
54 return new I\Component\Panel\Secondary\Factory();
55 }
56 public function dropdown(): I\Component\Dropdown\Factory
57 {
58 return new I\Component\Dropdown\Factory();
59 }
60 public function viewControl(): I\Component\ViewControl\Factory
61 {
62 return new I\Component\ViewControl\Factory(new SignalGenerator());
63 }
64 public function button(): I\Component\Button\Factory
65 {
66 return new I\Component\Button\Factory();
67 }
68 public function symbol(): I\Component\Symbol\Factory
69 {
70 return new I\Component\Symbol\Factory(
71 new I\Component\Symbol\Icon\Factory(),
72 new I\Component\Symbol\Glyph\Factory(),
73 new I\Component\Symbol\Avatar\Factory()
74 );
75 }
76 };
77 }
78
79 public function getPanelFactory(): I\Component\Panel\Factory
80 {
81 return new I\Component\Panel\Factory(
82 $this->createMock(I\Component\Panel\Listing\Factory::class),
83 $this->createMock(I\Component\Panel\Secondary\Factory::class),
84 );
85 }
86
87 public function testImplementsFactoryInterface(): void
88 {
89 $f = $this->getPanelFactory();
90
91 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Factory", $f);
92 $this->assertInstanceOf(
93 "ILIAS\\UI\\Component\\Panel\\Standard",
94 $f->standard("Title", array(new ComponentDummy()))
95 );
96 $this->assertInstanceOf(
97 "ILIAS\\UI\\Component\\Panel\\Sub",
98 $f->sub("Title", array(new ComponentDummy()))
99 );
100 $this->assertInstanceOf(
101 "ILIAS\\UI\\Component\\Panel\\Report",
102 $f->report("Title", $f->sub("Title", array(new ComponentDummy())))
103 );
104 }
105
106 public function testStandardGetTitle(): void
107 {
108 $f = $this->getPanelFactory();
109 $p = $f->standard("Title", array(new ComponentDummy()));
110
111 $this->assertEquals("Title", $p->getTitle());
112 }
113
114 public function testStandardGetContent(): void
115 {
116 $f = $this->getPanelFactory();
117 $c = new ComponentDummy();
118 $p = $f->standard("Title", array($c));
119
120 $this->assertEquals($p->getContent(), array($c));
121 }
122
123 public function testStandardWithActions(): void
124 {
125 $fp = $this->getPanelFactory();
126
127 $p = $fp->standard("Title", array(new ComponentDummy()));
128
129 $actions = new I\Component\Dropdown\Standard(array(
130 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
131 new I\Component\Button\Shy("GitHub", "https://www.github.com")
132 ));
133
134 $p = $p->withActions($actions);
135
136 $this->assertEquals($p->getActions(), $actions);
137 }
138
139 public function testSubWithActions(): void
140 {
141 $fp = $this->getPanelFactory();
142
143 $p = $fp->sub("Title", array(new ComponentDummy()));
144
145 $actions = new I\Component\Dropdown\Standard(array(
146 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
147 new I\Component\Button\Shy("GitHub", "https://www.github.com")
148 ));
149
150 $p = $p->withActions($actions);
151
152 $this->assertEquals($p->getActions(), $actions);
153 }
154
155 public function testSubWithCard(): void
156 {
157 $fp = $this->getPanelFactory();
158
159 $p = $fp->sub("Title", array(new ComponentDummy()));
160
161 $card = new I\Component\Card\Card("Card Title");
162
163 $p = $p->withFurtherInformation($card);
164
165 $this->assertEquals($p->getFurtherInformation(), $card);
166 }
167
168 public function testSubWithSecondaryPanel(): void
169 {
170 $fp = $this->getPanelFactory();
171
172 $p = $fp->sub("Title", array(new ComponentDummy()));
173
174 $legacy = new I\Component\Legacy\Content("Legacy content", new SignalGenerator());
175 $secondary = new I\Component\Panel\Secondary\Legacy("Legacy panel title", $legacy);
176
177 $p = $p->withFurtherInformation($secondary);
178
179 $this->assertEquals($p->getFurtherInformation(), $secondary);
180 }
181
182 public function testReportWithActions(): void
183 {
184 $fp = $this->getPanelFactory();
185
186 $p = $fp->report("Title", $fp->sub("Title", array(new ComponentDummy())));
187
188 $actions = new I\Component\Dropdown\Standard(array(
189 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
190 new I\Component\Button\Shy("GitHub", "https://www.github.com")
191 ));
192
193 $p = $p->withActions($actions);
194
195 $this->assertEquals($p->getActions(), $actions);
196 }
197
198 public function testReportGetTitle(): void
199 {
200 $f = $this->getPanelFactory();
201 $sub = $f->sub("Title", array(new ComponentDummy()));
202 $p = $f->report("Title", array($sub));
203
204 $this->assertEquals("Title", $p->getTitle());
205 }
206
207 public function testReportGetContent(): void
208 {
209 $f = $this->getPanelFactory();
210 $sub = $f->sub("Title", array(new ComponentDummy()));
211 $p = $f->report("Title", [$sub]);
212
213 $this->assertEquals($p->getContent(), array($sub));
214 }
215
216 public function testRenderStandard(): void
217 {
218 $f = $this->getPanelFactory();
219 $r = $this->getDefaultRenderer();
220
221 $actions = new I\Component\Dropdown\Standard(array(
222 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
223 new I\Component\Button\Shy("GitHub", "https://www.github.com")
224 ));
225
226 $p = $f->standard("Title", array())->withActions($actions);
227
228 $html = $r->render($p);
229
230 $expected_html = <<<EOT
231<div class="panel panel-primary panel-flex">
232 <div class="panel-heading ilHeader">
233 <div class="panel-title"><h2>Title</h2></div>
234 <div class="panel-controls">
235 <div class="dropdown" id="id_3"><button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu"><span class="caret"></span></button>
236 <ul id="id_3_menu" class="dropdown-menu">
237 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
238 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
239 </ul>
240 </div>
241 </div>
242 </div>
243 <div class="panel-body"></div>
244</div>
245EOT;
246 $this->assertHTMLEquals($expected_html, $html);
247 }
248
249 public function testRenderSub(): void
250 {
251 $fp = $this->getPanelFactory();
252 $r = $this->getDefaultRenderer();
253
254 $actions = new I\Component\Dropdown\Standard(array(
255 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
256 new I\Component\Button\Shy("GitHub", "https://www.github.com")
257 ));
258
259 $p = $fp->sub("Title", array())->withActions($actions);
260 $card = new I\Component\Card\Card("Card Title");
261
262 $p = $p->withFurtherInformation($card);
263 $html = $this->brutallyTrimHTML($r->render($p));
264
265 $expected_html = <<<EOT
266<div class="panel panel-sub panel-flex">
267 <div class="panel-heading ilBlockHeader">
268 <h3>Title</h3>
269 <div class="panel-controls">
270 <div class="dropdown" id="id_3"><button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu"><span class="caret"></span></button>
271 <ul id="id_3_menu" class="dropdown-menu">
272 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
273 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
274 </ul>
275 </div>
276 </div>
277 </div>
278 <div class="panel-body">
279 <div class="row">
280 <div class="col-sm-8"></div>
281 <div class="col-sm-4">
282 <div class="il-card thumbnail">
283 <div class="card-no-highlight"></div>
284 <div class="caption card-title">Card Title</div>
285 </div>
286 </div>
287 </div>
288 </div>
289</div>
290EOT;
291
292 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
293 }
294
295 public function testRenderSubWithSecondaryPanel(): void
296 {
297 $fp = $this->getPanelFactory();
298 $r = $this->getDefaultRenderer();
299
300 $p = $fp->sub("Title", array());
301 $legacy = new I\Component\Legacy\Content("Legacy content", new SignalGenerator());
302 $secondary = new I\Component\Panel\Secondary\Legacy("Legacy panel title", $legacy);
303 $p = $p->withFurtherInformation($secondary);
304 $html = $r->render($p);
305
306 $expected_html = <<<EOT
307<div class="panel panel-sub panel-flex">
308 <div class="panel-heading ilBlockHeader">
309 <h3>Title</h3>
310 <div class="panel-controls"></div>
311 </div>
312 <div class="panel-body">
313 <div class="row">
314 <div class="col-sm-8"></div>
315 <div class="col-sm-4">
316 <div class="panel panel-secondary panel-flex">
317 <div class="panel-heading ilHeader">
318 <div class="panel-title"><h2>Legacy panel title</h2></div>
319 <div class="panel-controls"></div>
320 </div>
321 <div class="panel-body">Legacy content</div>
322 </div>
323 </div>
324 </div>
325 </div>
326</div>
327EOT;
328
329 $this->assertHTMLEquals(
330 $this->brutallyTrimHTML($expected_html),
331 $this->brutallyTrimHTML($html)
332 );
333 }
334
335 public function testRenderReport(): void
336 {
337 $fp = $this->getPanelFactory();
338 $r = $this->getDefaultRenderer();
339
340 $actions = new I\Component\Dropdown\Standard(array(
341 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
342 new I\Component\Button\Shy("GitHub", "https://www.github.com")
343 ));
344
345 $sub = $fp->sub("Title", array());
346 $card = new I\Component\Card\Card("Card Title");
347 $sub = $sub->withFurtherInformation($card);
348 $report = $fp->report("Title", $sub)->withActions($actions);
349
350 $html = $this->brutallyTrimHTML($r->render($report));
351
352 $expected_html = <<<EOT
353<div class="panel panel-primary il-panel-report panel-flex">
354 <div class="panel-heading ilHeader">
355 <div class="panel-title"><h2>Title</h2></div>
356 <div class="panel-controls">
357 <div class="dropdown" id="id_3"><button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu"><span class="caret"></span></button>
358 <ul id="id_3_menu" class="dropdown-menu">
359 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
360 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
361 </ul>
362 </div>
363 </div>
364 </div>
365 <div class="panel-body">
366 <div class="panel panel-sub panel-flex">
367 <div class="panel-heading ilBlockHeader">
368 <h3>Title</h3>
369 <div class="panel-controls"></div>
370 </div>
371 <div class="panel-body"><div class="row">
372 <div class="col-sm-8"></div>
373 <div class="col-sm-4">
374 <div class="il-card thumbnail">
375 <div class="card-no-highlight"></div>
376 <div class="caption card-title">Card Title</div>
377 </div>
378 </div>
379 </div>
380 </div>
381 </div>
382 </div>
383</div>
384EOT;
385
386 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
387 }
388
389 public function testStandardWithViewControls(): void
390 {
391 $sort_options = [
392 'a' => 'A',
393 'b' => 'B'
394 ];
395 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'a');
396 $f = $this->getPanelFactory();
397 $p = $f->standard("Title", [])
398 ->withViewControls([$sortation])
399 ;
400
401 $this->assertEquals($p->getViewControls(), [$sortation]);
402 }
403
404 public function testReportWithViewControls(): void
405 {
406 $sort_options = [
407 'a' => 'A',
408 'b' => 'B'
409 ];
410 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'a');
411 $f = $this->getPanelFactory();
412 $p = $f->report("Title", [])
413 ->withViewControls([$sortation])
414 ;
415
416 $this->assertEquals($p->getViewControls(), [$sortation]);
417 }
418
419 public function testRenderReportWithMode(): void
420 {
421 $modes = [
422 'A' => 'a',
423 'B' => 'b'
424 ];
425 $mode = $this->getUIFactory()->viewControl()->mode($modes, 'Presentation Mode');
426
427 $f = $this->getPanelFactory();
428 $r = $this->getDefaultRenderer();
429
430
431 $p = $f->report("Title", [])
432 ->withViewControls([$mode]);
433
434 $html = $r->render($p);
435
436 $expected_html = <<<EOT
437<div class="panel panel-primary il-panel-report panel-flex">
438 <div class="panel-heading ilHeader">
439 <div class="panel-title"><h2>Title</h2></div>
440 <div class="panel-viewcontrols l-bar__space-keeper">
441 <div class="il-viewcontrol-mode l-bar__element" aria-label="Presentation Mode" role="group">
442 <button class="btn btn-default engaged" aria-pressed="true" data-action="a" id="id_1">A</button>
443 <button class="btn btn-default" aria-pressed="false" data-action="b" id="id_2">B</button>
444 </div>
445 </div>
446 <div class="panel-controls"></div>
447 </div>
448 <div class="panel-body"></div>
449</div>
450EOT;
451 $this->assertEquals(
452 $this->brutallyTrimHTML($expected_html),
453 $this->brutallyTrimHTML($html)
454 );
455 }
456
457 public function testRenderWithSortation(): void
458 {
459 $sort_options = [
460 'a' => 'A',
461 'b' => 'B'
462 ];
463
464 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'b');
465
466 $f = $this->getPanelFactory();
467 $r = $this->getDefaultRenderer();
468
469
470 $p = $f->standard("Title", [])
471 ->withViewControls([$sortation]);
472
473 $html = $r->render($p);
474
475 $expected_html = <<<EOT
476<div class="panel panel-primary panel-flex">
477 <div class="panel-heading ilHeader">
478 <div class="panel-title"><h2>Title</h2></div>
479 <div class="panel-viewcontrols l-bar__space-keeper">
480 <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_1">
481 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="sortation" aria-haspopup="true" aria-expanded="false" aria-controls="id_1_ctrl">
482 <span class="label">vc_sort B</span>
483 <span class="glyphicon-sort"></span>
484 </button>
485 <ul id="id_1_ctrl" class="dropdown-menu">
486 <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
487 <li class="selected"><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
488 </ul>
489 </div>
490 </div>
491 <div class="panel-controls"></div>
492 </div>
493 <div class="panel-body"></div>
494</div>
495EOT;
496 $this->assertEquals(
497 $this->brutallyTrimHTML($expected_html),
498 $this->brutallyTrimHTML($html)
499 );
500 }
501
502 public function testRenderWithPagination(): void
503 {
504 $pagination = $this->getUIFactory()->viewControl()->pagination()
505 ->withTargetURL('http://ilias.de', 'page')
506 ->withTotalEntries(10)
507 ->withPageSize(2)
508 ->withCurrentPage(1);
509
510 $f = $this->getPanelFactory();
511 $r = $this->getDefaultRenderer();
512
513
514 $p = $f->standard("Title", [])
515 ->withViewControls([$pagination]);
516
517 $html = $r->render($p);
518
519 $expected_html = <<<EOT
520<div class="panel panel-primary panel-flex">
521 <div class="panel-heading ilHeader">
522 <div class="panel-title"><h2>Title</h2></div>
523 <div class="panel-viewcontrols l-bar__space-keeper">
524 <div class="il-viewcontrol-pagination l-bar__element">
525 <button class="btn btn-default" data-action="http://ilias.de?page=0" id="id_6">
526 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
527 </button>
528 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
529 <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
530 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
531 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
532 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
533 <button class="btn btn-default" data-action="http://ilias.de?page=2" id="id_7">
534 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
535 </button>
536 </div>
537 </div>
538 <div class="panel-controls"></div>
539 </div>
540 <div class="panel-body"></div>
541</div>
542EOT;
543 $this->assertEquals(
544 $this->brutallyTrimHTML($expected_html),
545 $this->brutallyTrimHTML($html)
546 );
547 }
548}
__construct($id="")
Definition: PanelTest.php:34
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:38
Provides common functionality for UI tests.
Definition: Base.php:337
Test on button implementation.
Definition: PanelTest.php:48
getPanelFactory()
Definition: PanelTest.php:79
testRenderWithPagination()
Definition: PanelTest.php:502
testRenderSub()
Definition: PanelTest.php:249
testSubWithActions()
Definition: PanelTest.php:139
testStandardGetContent()
Definition: PanelTest.php:114
testSubWithCard()
Definition: PanelTest.php:155
testRenderWithSortation()
Definition: PanelTest.php:457
testSubWithSecondaryPanel()
Definition: PanelTest.php:168
testStandardGetTitle()
Definition: PanelTest.php:106
testStandardWithActions()
Definition: PanelTest.php:123
testRenderStandard()
Definition: PanelTest.php:216
getUIFactory()
Definition: PanelTest.php:49
testRenderReport()
Definition: PanelTest.php:335
testReportGetContent()
Definition: PanelTest.php:207
testStandardWithViewControls()
Definition: PanelTest.php:389
testRenderSubWithSecondaryPanel()
Definition: PanelTest.php:295
testReportGetTitle()
Definition: PanelTest.php:198
testReportWithViewControls()
Definition: PanelTest.php:404
testImplementsFactoryInterface()
Definition: PanelTest.php:87
testRenderReportWithMode()
Definition: PanelTest.php:419
testReportWithActions()
Definition: PanelTest.php:182
Title class.
Definition: Title.php:42
$c
Definition: deliver.php:25
A component is the most general form of an entity in the UI.
Definition: Component.php:28
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.