ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
PanelTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
27 
28 class ComponentDummy implements C\Component
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 testImplementsFactoryInterface(): 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 testStandardGetTitle(): 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 testStandardGetContent(): 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 testStandardWithActions(): 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 testSubWithActions(): 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 testSubWithCard(): 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 testSubWithSecondaryPanel(): 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 testReportWithActions(): void
180  {
181  $fp = $this->getPanelFactory();
182 
183  $p = $fp->report("Title", $fp->sub("Title", array(new ComponentDummy())));
184 
185  $actions = new I\Component\Dropdown\Standard(array(
186  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
187  new I\Component\Button\Shy("GitHub", "https://www.github.com")
188  ));
189 
190  $p = $p->withActions($actions);
191 
192  $this->assertEquals($p->getActions(), $actions);
193  }
194 
195  public function testReportGetTitle(): void
196  {
197  $f = $this->getPanelFactory();
198  $sub = $f->sub("Title", array(new ComponentDummy()));
199  $p = $f->report("Title", array($sub));
200 
201  $this->assertEquals("Title", $p->getTitle());
202  }
203 
204  public function testReportGetContent(): void
205  {
206  $f = $this->getPanelFactory();
207  $sub = $f->sub("Title", array(new ComponentDummy()));
208  $p = $f->report("Title", [$sub]);
209 
210  $this->assertEquals($p->getContent(), array($sub));
211  }
212 
213  public function testRenderStandard(): void
214  {
215  $f = $this->getPanelFactory();
216  $r = $this->getDefaultRenderer();
217 
218  $actions = new I\Component\Dropdown\Standard(array(
219  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
220  new I\Component\Button\Shy("GitHub", "https://www.github.com")
221  ));
222 
223  $p = $f->standard("Title", array())->withActions($actions);
224 
225  $html = $r->render($p);
226 
227  $expected_html = <<<EOT
228 <div class="panel panel-primary panel-flex">
229  <div class="panel-heading ilHeader">
230  <div class="panel-title"><h2>Title</h2></div>
231  <div class="panel-controls">
232  <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>
233  <ul id="id_3_menu" class="dropdown-menu">
234  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
235  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
236  </ul>
237  </div>
238  </div>
239  </div>
240  <div class="panel-body"></div>
241 </div>
242 EOT;
243  $this->assertHTMLEquals($expected_html, $html);
244  }
245 
246  public function testRenderSub(): void
247  {
248  $fp = $this->getPanelFactory();
249  $r = $this->getDefaultRenderer();
250 
251  $actions = new I\Component\Dropdown\Standard(array(
252  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
253  new I\Component\Button\Shy("GitHub", "https://www.github.com")
254  ));
255 
256  $p = $fp->sub("Title", array())->withActions($actions);
257  $card = new I\Component\Card\Card("Card Title");
258 
259  $p = $p->withFurtherInformation($card);
260  $html = $this->brutallyTrimHTML($r->render($p));
261 
262  $expected_html = <<<EOT
263 <div class="panel panel-sub panel-flex">
264  <div class="panel-heading ilBlockHeader">
265  <h3>Title</h3>
266  <div class="panel-controls">
267  <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>
268  <ul id="id_3_menu" class="dropdown-menu">
269  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
270  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
271  </ul>
272  </div>
273  </div>
274  </div>
275  <div class="panel-body">
276  <div class="row">
277  <div class="col-sm-8"></div>
278  <div class="col-sm-4">
279  <div class="il-card thumbnail">
280  <div class="card-no-highlight"></div>
281  <div class="caption card-title">Card Title</div>
282  </div>
283  </div>
284  </div>
285  </div>
286 </div>
287 EOT;
288 
289  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
290  }
291 
292  public function testRenderSubWithSecondaryPanel(): void
293  {
294  $fp = $this->getPanelFactory();
295  $r = $this->getDefaultRenderer();
296 
297  $p = $fp->sub("Title", array());
298  $legacy = new I\Component\Legacy\Legacy("Legacy content", new SignalGenerator());
299  $secondary = new I\Component\Panel\Secondary\Legacy("Legacy panel title", $legacy);
300  $p = $p->withFurtherInformation($secondary);
301  $html = $r->render($p);
302 
303  $expected_html = <<<EOT
304 <div class="panel panel-sub panel-flex">
305  <div class="panel-heading ilBlockHeader">
306  <h3>Title</h3>
307  <div class="panel-controls"></div>
308  </div>
309  <div class="panel-body">
310  <div class="row">
311  <div class="col-sm-8"></div>
312  <div class="col-sm-4">
313  <div class="panel panel-secondary panel-flex">
314  <div class="panel-heading ilHeader">
315  <div class="panel-title"><h2>Legacy panel title</h2></div>
316  <div class="panel-controls"></div>
317  </div>
318  <div class="panel-body">Legacy content</div>
319  </div>
320  </div>
321  </div>
322  </div>
323 </div>
324 EOT;
325 
326  $this->assertHTMLEquals(
327  $this->brutallyTrimHTML($expected_html),
328  $this->brutallyTrimHTML($html)
329  );
330  }
331 
332  public function testRenderReport(): void
333  {
334  $fp = $this->getPanelFactory();
335  $r = $this->getDefaultRenderer();
336 
337  $actions = new I\Component\Dropdown\Standard(array(
338  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
339  new I\Component\Button\Shy("GitHub", "https://www.github.com")
340  ));
341 
342  $sub = $fp->sub("Title", array());
343  $card = new I\Component\Card\Card("Card Title");
344  $sub = $sub->withFurtherInformation($card);
345  $report = $fp->report("Title", $sub)->withActions($actions);
346 
347  $html = $this->brutallyTrimHTML($r->render($report));
348 
349  $expected_html = <<<EOT
350 <div class="panel panel-primary il-panel-report panel-flex">
351  <div class="panel-heading ilHeader">
352  <div class="panel-title"><h2>Title</h2></div>
353  <div class="panel-controls">
354  <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>
355  <ul id="id_3_menu" class="dropdown-menu">
356  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
357  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
358  </ul>
359  </div>
360  </div>
361  </div>
362  <div class="panel-body">
363  <div class="panel panel-sub panel-flex">
364  <div class="panel-heading ilBlockHeader">
365  <h3>Title</h3>
366  <div class="panel-controls"></div>
367  </div>
368  <div class="panel-body"><div class="row">
369  <div class="col-sm-8"></div>
370  <div class="col-sm-4">
371  <div class="il-card thumbnail">
372  <div class="card-no-highlight"></div>
373  <div class="caption card-title">Card Title</div>
374  </div>
375  </div>
376  </div>
377  </div>
378  </div>
379  </div>
380 </div>
381 EOT;
382 
383  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
384  }
385 
386  public function testStandardWithViewControls(): void
387  {
388  $sort_options = [
389  'a' => 'A',
390  'b' => 'B'
391  ];
392  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'a');
393  $f = $this->getPanelFactory();
394  $p = $f->standard("Title", [])
395  ->withViewControls([$sortation])
396  ;
397 
398  $this->assertEquals($p->getViewControls(), [$sortation]);
399  }
400 
401  public function testReportWithViewControls(): void
402  {
403  $sort_options = [
404  'a' => 'A',
405  'b' => 'B'
406  ];
407  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'a');
408  $f = $this->getPanelFactory();
409  $p = $f->report("Title", [])
410  ->withViewControls([$sortation])
411  ;
412 
413  $this->assertEquals($p->getViewControls(), [$sortation]);
414  }
415 
416  public function testRenderReportWithMode(): void
417  {
418  $modes = [
419  'A' => 'a',
420  'B' => 'b'
421  ];
422  $mode = $this->getUIFactory()->viewControl()->mode($modes, 'Presentation Mode');
423 
424  $f = $this->getPanelFactory();
425  $r = $this->getDefaultRenderer();
426 
427 
428  $p = $f->report("Title", [])
429  ->withViewControls([$mode]);
430 
431  $html = $r->render($p);
432 
433  $expected_html = <<<EOT
434 <div class="panel panel-primary il-panel-report panel-flex">
435  <div class="panel-heading ilHeader">
436  <div class="panel-title"><h2>Title</h2></div>
437  <div class="panel-viewcontrols l-bar__space-keeper">
438  <div class="il-viewcontrol-mode l-bar__element" aria-label="Presentation Mode" role="group">
439  <button class="btn btn-default engaged" aria-pressed="true" data-action="a" id="id_1">A</button>
440  <button class="btn btn-default" aria-pressed="false" data-action="b" id="id_2">B</button>
441  </div>
442  </div>
443  <div class="panel-controls"></div>
444  </div>
445  <div class="panel-body"></div>
446 </div>
447 EOT;
448  $this->assertEquals(
449  $this->brutallyTrimHTML($expected_html),
450  $this->brutallyTrimHTML($html)
451  );
452  }
453 
454  public function testRenderWithSortation(): void
455  {
456  $sort_options = [
457  'a' => 'A',
458  'b' => 'B'
459  ];
460 
461  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'b');
462 
463  $f = $this->getPanelFactory();
464  $r = $this->getDefaultRenderer();
465 
466 
467  $p = $f->standard("Title", [])
468  ->withViewControls([$sortation]);
469 
470  $html = $r->render($p);
471 
472  $expected_html = <<<EOT
473 <div class="panel panel-primary panel-flex">
474  <div class="panel-heading ilHeader">
475  <div class="panel-title"><h2>Title</h2></div>
476  <div class="panel-viewcontrols l-bar__space-keeper">
477  <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_1">
478  <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">
479  <span class="label">vc_sort B</span>
480  <span class="caret"></span>
481  </button>
482  <ul id="id_1_ctrl" class="dropdown-menu">
483  <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
484  <li class="selected"><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
485  </ul>
486  </div>
487  </div>
488  <div class="panel-controls"></div>
489  </div>
490  <div class="panel-body"></div>
491 </div>
492 EOT;
493  $this->assertEquals(
494  $this->brutallyTrimHTML($expected_html),
495  $this->brutallyTrimHTML($html)
496  );
497  }
498 
499  public function testRenderWithPagination(): void
500  {
501  $pagination = $this->getUIFactory()->viewControl()->pagination()
502  ->withTargetURL('http://ilias.de', 'page')
503  ->withTotalEntries(10)
504  ->withPageSize(2)
505  ->withCurrentPage(1);
506 
507  $f = $this->getPanelFactory();
508  $r = $this->getDefaultRenderer();
509 
510 
511  $p = $f->standard("Title", [])
512  ->withViewControls([$pagination]);
513 
514  $html = $r->render($p);
515 
516  $expected_html = <<<EOT
517 <div class="panel panel-primary panel-flex">
518  <div class="panel-heading ilHeader">
519  <div class="panel-title"><h2>Title</h2></div>
520  <div class="panel-viewcontrols l-bar__space-keeper">
521  <div class="il-viewcontrol-pagination l-bar__element">
522  <button class="btn btn-default" data-action="http://ilias.de?page=0" id="id_6">
523  <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
524  </button>
525  <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
526  <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
527  <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
528  <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
529  <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
530  <button class="btn btn-default" data-action="http://ilias.de?page=2" id="id_7">
531  <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
532  </button>
533  </div>
534  </div>
535  <div class="panel-controls"></div>
536  </div>
537  <div class="panel-body"></div>
538 </div>
539 EOT;
540  $this->assertEquals(
541  $this->brutallyTrimHTML($expected_html),
542  $this->brutallyTrimHTML($html)
543  );
544  }
545 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Avatar.php:21
button(string $caption, string $cmd)
testReportGetTitle()
Definition: PanelTest.php:195
testSubWithActions()
Definition: PanelTest.php:136
testRenderReportWithMode()
Definition: PanelTest.php:416
testRenderStandard()
Definition: PanelTest.php:213
Test on button implementation.
Definition: PanelTest.php:45
Interface Observer Contains several chained tasks and infos about them.
testRenderSub()
Definition: PanelTest.php:246
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Title class.
Definition: Title.php:26
testStandardWithActions()
Definition: PanelTest.php:120
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
$c
Definition: deliver.php:9
getPanelFactory()
Definition: PanelTest.php:77
testStandardWithViewControls()
Definition: PanelTest.php:386
testSubWithCard()
Definition: PanelTest.php:152
testReportGetContent()
Definition: PanelTest.php:204
testStandardGetContent()
Definition: PanelTest.php:111
testRenderWithPagination()
Definition: PanelTest.php:499
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:36
__construct($id="")
Definition: PanelTest.php:32
testImplementsFactoryInterface()
Definition: PanelTest.php:84
testSubWithSecondaryPanel()
Definition: PanelTest.php:165
testRenderSubWithSecondaryPanel()
Definition: PanelTest.php:292
testRenderReport()
Definition: PanelTest.php:332
testReportWithViewControls()
Definition: PanelTest.php:401
testReportWithActions()
Definition: PanelTest.php:179
getUIFactory()
Definition: PanelTest.php:47
testStandardGetTitle()
Definition: PanelTest.php:103
testRenderWithSortation()
Definition: PanelTest.php:454
$r