ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
PanelTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../libs/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 testReportGetTitle(): 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 testReportGetContent(): 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 testRenderStandard(): 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  <div class="panel-title"><h2>Title</h2></div>
214  <div class="panel-controls">
215  <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>
216  <ul id="id_3_menu" class="dropdown-menu">
217  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
218  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
219  </ul>
220  </div>
221  </div>
222  </div>
223  <div class="panel-body"></div>
224 </div>
225 EOT;
226  $this->assertHTMLEquals($expected_html, $html);
227  }
228 
229  public function testRenderSub(): void
230  {
231  $fp = $this->getPanelFactory();
232  $r = $this->getDefaultRenderer();
233 
234  $actions = new I\Component\Dropdown\Standard(array(
235  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
236  new I\Component\Button\Shy("GitHub", "https://www.github.com")
237  ));
238 
239  $p = $fp->sub("Title", array())->withActions($actions);
240  $card = new I\Component\Card\Card("Card Title");
241 
242  $p = $p->withFurtherInformation($card);
243  $html = $this->brutallyTrimHTML($r->render($p));
244 
245  $expected_html = <<<EOT
246 <div class="panel panel-sub panel-flex">
247  <div class="panel-heading ilBlockHeader">
248  <h3>Title</h3>
249  <div class="panel-controls">
250  <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>
251  <ul id="id_3_menu" class="dropdown-menu">
252  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
253  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
254  </ul>
255  </div>
256  </div>
257  </div>
258  <div class="panel-body">
259  <div class="row">
260  <div class="col-sm-8"></div>
261  <div class="col-sm-4">
262  <div class="il-card thumbnail">
263  <div class="card-no-highlight"></div>
264  <div class="caption card-title">Card Title</div>
265  </div>
266  </div>
267  </div>
268  </div>
269 </div>
270 EOT;
271 
272  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
273  }
274 
275  public function testRenderSubWithSecondaryPanel(): void
276  {
277  $fp = $this->getPanelFactory();
278  $r = $this->getDefaultRenderer();
279 
280  $p = $fp->sub("Title", array());
281  $legacy = new I\Component\Legacy\Legacy("Legacy content", new SignalGenerator());
282  $secondary = new I\Component\Panel\Secondary\Legacy("Legacy panel title", $legacy);
283  $p = $p->withFurtherInformation($secondary);
284  $html = $r->render($p);
285 
286  $expected_html = <<<EOT
287 <div class="panel panel-sub panel-flex">
288  <div class="panel-heading ilBlockHeader">
289  <h3>Title</h3>
290  <div class="panel-controls"></div>
291  </div>
292  <div class="panel-body">
293  <div class="row">
294  <div class="col-sm-8"></div>
295  <div class="col-sm-4">
296  <div class="panel panel-secondary panel-flex">
297  <div class="panel-heading ilHeader">
298  <div class="panel-title"><h2>Legacy panel title</h2></div>
299  <div class="panel-controls"></div>
300  </div>
301  <div class="panel-body">Legacy content</div>
302  </div>
303  </div>
304  </div>
305  </div>
306 </div>
307 EOT;
308 
309  $this->assertHTMLEquals(
310  $this->brutallyTrimHTML($expected_html),
311  $this->brutallyTrimHTML($html)
312  );
313  }
314 
315  public function testRenderReport(): void
316  {
317  $fp = $this->getPanelFactory();
318  $r = $this->getDefaultRenderer();
319  $sub = $fp->sub("Title", array());
320  $card = new I\Component\Card\Card("Card Title");
321  $sub = $sub->withFurtherInformation($card);
322  $report = $fp->report("Title", $sub);
323 
324  $html = $this->brutallyTrimHTML($r->render($report));
325 
326  $expected_html = <<<EOT
327 <div class="panel panel-primary il-panel-report panel-flex">
328  <div class="panel-heading ilHeader">
329  <h2>Title</h2>
330  </div>
331  <div class="panel-body">
332  <div class="panel panel-sub panel-flex">
333  <div class="panel-heading ilBlockHeader">
334  <h3>Title</h3>
335  <div class="panel-controls"></div>
336  </div>
337  <div class="panel-body"><div class="row">
338  <div class="col-sm-8"></div>
339  <div class="col-sm-4">
340  <div class="il-card thumbnail">
341  <div class="card-no-highlight"></div>
342  <div class="caption card-title">Card Title</div>
343  </div>
344  </div>
345  </div>
346  </div>
347  </div>
348  </div>
349 </div>
350 EOT;
351 
352  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
353  }
354 
355  public function testWithViewControls(): void
356  {
357  $sort_options = [
358  'a' => 'A',
359  'b' => 'B'
360  ];
361  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
362  $f = $this->getPanelFactory();
363  $p = $f->standard("Title", [])
364  ->withViewControls([$sortation])
365  ;
366 
367  $this->assertEquals($p->getViewControls(), [$sortation]);
368  }
369 
370  public function testRenderWithSortation(): void
371  {
372  $sort_options = [
373  'a' => 'A',
374  'b' => 'B'
375  ];
376  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
377 
378  $f = $this->getPanelFactory();
379  $r = $this->getDefaultRenderer();
380 
381 
382  $p = $f->standard("Title", [])
383  ->withViewControls([$sortation]);
384 
385  $html = $r->render($p);
386 
387  $expected_html = <<<EOT
388 <div class="panel panel-primary panel-flex">
389  <div class="panel-heading ilHeader">
390  <div class="panel-title"><h2>Title</h2></div>
391  <div class="panel-viewcontrols l-bar__space-keeper">
392  <div class="il-viewcontrol-sortation l-bar__element" id="id_1">
393  <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>
394  <ul id="id_4_menu" class="dropdown-menu">
395  <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
396  <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
397  </ul>
398  </div>
399  </div>
400  </div>
401  <div class="panel-controls"></div>
402  </div>
403  <div class="panel-body"></div>
404 </div>
405 EOT;
406  $this->assertEquals(
407  $this->brutallyTrimHTML($expected_html),
408  $this->brutallyTrimHTML($html)
409  );
410  }
411 
412  public function testRenderWithPagination(): void
413  {
414  $pagination = $this->getUIFactory()->viewControl()->pagination()
415  ->withTargetURL('http://ilias.de', 'page')
416  ->withTotalEntries(10)
417  ->withPageSize(2)
418  ->withCurrentPage(1);
419 
420  $f = $this->getPanelFactory();
421  $r = $this->getDefaultRenderer();
422 
423 
424  $p = $f->standard("Title", [])
425  ->withViewControls([$pagination]);
426 
427  $html = $r->render($p);
428 
429  $expected_html = <<<EOT
430 <div class="panel panel-primary panel-flex">
431  <div class="panel-heading ilHeader">
432  <div class="panel-title"><h2>Title</h2></div>
433  <div class="panel-viewcontrols l-bar__space-keeper">
434  <div class="il-viewcontrol-pagination l-bar__element">
435  <span class="btn btn-ctrl browse previous">
436  <a tabindex="0" class="glyph" href="http://ilias.de?page=0" aria-label="back">
437  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
438  </a>
439  </span>
440  <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
441  <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
442  <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
443  <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
444  <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
445  <span class="btn btn-ctrl browse next">
446  <a tabindex="0" class="glyph" href="http://ilias.de?page=2" aria-label="next">
447  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
448  </a>
449  </span>
450  </div>
451  </div>
452  <div class="panel-controls"></div>
453  </div>
454  <div class="panel-body"></div>
455 </div>
456 EOT;
457  $this->assertEquals(
458  $this->brutallyTrimHTML($expected_html),
459  $this->brutallyTrimHTML($html)
460  );
461  }
462 }
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:179
testSubWithActions()
Definition: PanelTest.php:136
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testRenderStandard()
Definition: PanelTest.php:196
Test on button implementation.
Definition: PanelTest.php:45
Class ChatMainBarProvider .
testRenderSub()
Definition: PanelTest.php:229
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
A component is the most general form of an entity in the UI.
Definition: Component.php:27
getPanelFactory()
Definition: PanelTest.php:77
Provides common functionality for UI tests.
Definition: Base.php:310
testSubWithCard()
Definition: PanelTest.php:152
testReportGetContent()
Definition: PanelTest.php:188
testStandardGetContent()
Definition: PanelTest.php:111
testRenderWithPagination()
Definition: PanelTest.php:412
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:275
testWithViewControls()
Definition: PanelTest.php:355
testRenderReport()
Definition: PanelTest.php:315
getUIFactory()
Definition: PanelTest.php:47
testStandardGetTitle()
Definition: PanelTest.php:103
testRenderWithSortation()
Definition: PanelTest.php:370
$r