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