ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
PanelSecondaryLegacyTest.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 
32 {
33  public function getUIFactory(): NoUIFactory
34  {
35  return new class () extends NoUIFactory {
36  public function legacyPanel(string $title, C\Legacy\Legacy $content): I\Component\Panel\Secondary\Legacy
37  {
38  return new I\Component\Panel\Secondary\Legacy($title, $content);
39  }
40 
41  public function legacy(string $content): C\Legacy\Legacy
42  {
43  $f = new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
44  return $f->legacy($content);
45  }
46 
47  public function dropdown(): C\Dropdown\Factory
48  {
49  return new I\Component\Dropdown\Factory();
50  }
51 
52  public function viewControl(): C\ViewControl\Factory
53  {
54  return new I\Component\ViewControl\Factory(new SignalGenerator());
55  }
56 
57  public function button(): C\Button\Factory
58  {
59  return new I\Component\Button\Factory();
60  }
61 
62  public function symbol(): C\Symbol\Factory
63  {
64  return new I\Component\Symbol\Factory(
65  new I\Component\Symbol\Icon\Factory(),
66  new I\Component\Symbol\Glyph\Factory(),
67  new I\Component\Symbol\Avatar\Factory()
68  );
69  }
70  };
71  }
72 
73  protected function cleanHTML(string $html): string
74  {
75  $html = str_replace(["\n", "\t"], "", $html);
76 
77  return trim($html);
78  }
79 
80  public function testImplementsFactoryInterface(): void
81  {
82  $legacy = $this->getUIFactory()->legacy("Legacy content");
83  $secondary_panel = $this->getUIFactory()->legacyPanel("List Title", $legacy);
84 
85  $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Secondary\\Legacy", $secondary_panel);
86  }
87 
88  public function testGetTitle(): void
89  {
90  $legacy = $this->getUIFactory()->legacy("Legacy content");
91  $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy);
92 
93  $this->assertEquals("Title", $secondary_panel->getTitle());
94  }
95 
96  public function testGetLegacyComponent(): void
97  {
98  $legacy = $this->getUIFactory()->legacy("Legacy content");
99  $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy);
100 
101  $this->assertEquals($secondary_panel->getLegacyComponent(), $legacy);
102  }
103 
104  public function testWithActions(): void
105  {
106  $legacy = $this->getUIFactory()->legacy("Legacy content");
107  $actions = $this->getUIFactory()->dropdown()->standard(array(
108  $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
109  $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
110  ));
111 
112  $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
113  ->withActions($actions);
114 
115  $this->assertEquals($secondary_panel->getActions(), $actions);
116  }
117 
118  public function testWithoutViewControls(): void
119  {
120  $legacy = $this->getUIFactory()->legacy("Legacy content");
121  $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy);
122  $array_vc = $secondary_panel->getViewControls();
123 
124  $this->assertEquals(null, $array_vc);
125  }
126 
127  public function testWithSortationViewControl(): void
128  {
129  $legacy = $this->getUIFactory()->legacy("Legacy content");
130  $sort_options = array(
131  'internal_rating' => 'Best',
132  'date_desc' => 'Most Recent',
133  'date_asc' => 'Oldest',
134  );
135  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
136 
137  $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
138  ->withViewControls([$sortation]);
139 
140  $array_vc = $secondary_panel->getViewControls();
141 
142  $this->assertEquals($array_vc[0], $sortation);
143  }
144 
145  public function testWithPaginationViewControl(): void
146  {
147  $legacy = $this->getUIFactory()->legacy("Legacy content");
148  $pagination = $this->getUIFactory()->viewControl()->pagination()
149  ->withTargetURL("http://ilias.de", 'page')
150  ->withTotalEntries(98)
151  ->withPageSize(10)
152  ->withCurrentPage(1);
153 
154  $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
155  ->withViewControls([$pagination]);
156 
157  $array_vc = $secondary_panel->getViewControls();
158 
159  $this->assertEquals($array_vc[0], $pagination);
160  }
161 
162  public function testWithSectionViewControl(): void
163  {
164  $legacy = $this->getUIFactory()->legacy("Legacy content");
165  $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
166  $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
167  $current = $this->getUIFactory()->button()->standard("current", "");
168  $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
169 
170  $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
171  ->withViewControls([$section]);
172 
173  $array_vc = $secondary_panel->getViewControls();
174 
175  $this->assertEquals($array_vc[0], $section);
176  }
177 
178  //RENDER
179 
180  public function testRenderPanelSecondaryWithActions(): void
181  {
182  $legacy = $this->getUIFactory()->legacy("Legacy content");
183  $actions = $this->getUIFactory()->dropdown()->standard(array(
184  $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
185  $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
186  ));
187 
188  $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)->withActions($actions);
189 
190  $html = $this->getDefaultRenderer()->render($sec);
191 
192  $expected_html = <<<EOT
193 <div class="panel panel-secondary panel-flex">
194  <div class="panel-heading ilHeader">
195  <div class="panel-title"><h2>Title</h2></div>
196  <div class="panel-controls">
197  <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>
198  <ul id="id_3_menu" class="dropdown-menu">
199  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
200  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">Github</button></li>
201  </ul>
202  </div>
203  </div>
204  </div>
205 
206  <div class="panel-body">
207  Legacy content
208  </div>
209 </div>
210 EOT;
211  $this->assertHTMLEquals(
212  $this->cleanHTML($expected_html),
213  $this->cleanHTML($html)
214  );
215  }
216 
218  {
219  $legacy = $this->getUIFactory()->legacy("Legacy content");
220  $sort_options = array(
221  'a' => 'A',
222  'b' => 'B'
223  );
224  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
225  $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)
226  ->withViewControls([$sortation]);
227 
228  $html = $this->getDefaultRenderer()->render($sec);
229 
230  $expected_html = <<<EOT
231 <div class="panel panel-secondary panel-flex">
232  <div class="panel-heading ilHeader">
233  <div class="panel-title"><h2>Title</h2></div>
234  <div class="panel-viewcontrols l-bar__space-keeper">
235  <div class="il-viewcontrol-sortation l-bar__element" id="id_1">
236  <div class="dropdown">
237  <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">
238  <span class="caret"></span>
239  </button>
240  <ul id="id_4_menu" class="dropdown-menu">
241  <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
242  <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
243  </ul>
244  </div>
245  </div>
246  </div>
247  <div class="panel-controls"></div>
248  </div>
249  <div class="panel-body">
250  Legacy content
251  </div>
252 </div>
253 EOT;
254  $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
255  }
256 
258  {
259  $legacy = $this->getUIFactory()->legacy("Legacy content");
260 
261  $pagination = $this->getUIFactory()->viewControl()->pagination()
262  ->withTargetURL('http://ilias.de', 'page')
263  ->withTotalEntries(10)
264  ->withPageSize(2)
265  ->withCurrentPage(1);
266 
267  $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)
268  ->withViewControls([$pagination]);
269 
270  $html = $this->getDefaultRenderer()->render($sec);
271 
272  $expected_html = <<<EOT
273 <div class="panel panel-secondary panel-flex">
274  <div class="panel-heading ilHeader">
275  <div class="panel-title"><h2>Title</h2></div>
276  <div class="panel-viewcontrols l-bar__space-keeper">
277  <div class="il-viewcontrol-pagination l-bar__element">
278  <span class="btn btn-ctrl browse previous"><a tabindex="0" class="glyph" href="http://ilias.de?page=0" aria-label="back"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></a></span>
279  <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
280  <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
281  <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
282  <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
283  <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
284  <span class="btn btn-ctrl browse next"><a tabindex="0" class="glyph" href="http://ilias.de?page=2" aria-label="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a></span>
285  </div>
286  </div>
287  <div class="panel-controls"></div>
288  </div>
289  <div class="panel-body">Legacy content</div>
290 </div>
291 EOT;
292  $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
293  }
294 
295  public function testRenderPanelSecondaryWithSection(): void
296  {
297  $legacy = $this->getUIFactory()->legacy("Legacy content");
298  $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
299  $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
300  $current = $this->getUIFactory()->button()->standard("current", "");
301  $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
302 
303  $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy)
304  ->withViewControls([$section]);
305 
306  $html = $this->getDefaultRenderer()->render($secondary_panel);
307 
308  $expected_html = <<<EOT
309 <div class="panel panel-secondary panel-flex">
310  <div class="panel-heading ilHeader">
311  <div class="panel-title"><h2>Title</h2></div>
312  <div class="panel-viewcontrols l-bar__space-keeper">
313  <div class="il-viewcontrol-section l-bar__element">
314  <a class="btn btn-ctrl browse previous" href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de" id="id_1"><span class="glyphicon glyphicon-chevron-left"></span></a>
315  <button class="btn btn-default" data-action="">current</button>
316  <a class="btn btn-ctrl browse next" href="http://www.github.com" aria-label="next" data-action="http://www.github.com" id="id_2"><span class="glyphicon glyphicon-chevron-right"></span></a>
317  </div>
318  </div>
319  <div class="panel-controls"></div>
320  </div>
321  <div class="panel-body">Legacy content</div>
322 </div>
323 EOT;
324  $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
325  }
326 
327  public function testRenderPanelSecondaryWithFooter(): void
328  {
329  $legacy = $this->getUIFactory()->legacy("Legacy content");
330  $footer_shy_button = $this->getUIFactory()->button()->shy("Action", "");
331 
332  $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy)
333  ->withFooter($footer_shy_button);
334 
335  $html = $this->getDefaultRenderer()->render($secondary_panel);
336 
337  $expected_html = <<<EOT
338 <div class="panel panel-secondary panel-flex">
339  <div class="panel-heading ilHeader">
340  <div class="panel-title"><h2>Title</h2></div>
341  <div class="panel-controls"></div>
342  </div>
343  <div class="panel-body">
344  Legacy content
345  </div>
346  <div class="panel-footer ilBlockInfo">
347  <button class="btn btn-link" data-action="">Action</button>
348  </div>
349 </div>
350 EOT;
351  $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
352  }
353 
354  public function testRenderPanelSecondaryWithNoHeader(): void
355  {
356  $legacy = $this->getUIFactory()->legacy("Legacy content");
357 
358  $secondary_panel = $this->getUIFactory()->legacyPanel("", $legacy);
359 
360  $html = $this->getDefaultRenderer()->render($secondary_panel);
361 
362  $expected_html = <<<EOT
363 <div class="panel panel-secondary panel-flex">
364  <div class="panel-body">
365  Legacy content
366  </div>
367 </div>
368 EOT;
369  $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
370  }
371 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Avatar.php:21
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:377
button(string $caption, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Title class.
Definition: Title.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:475
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:458
Provides common functionality for UI tests.
Definition: Base.php:310
Test secondary legacy panels.