ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
PanelSecondaryListingTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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 panelSecondary(): I\Component\Panel\Secondary\Factory
37  {
38  return new I\Component\Panel\Secondary\Factory();
39  }
40 
41  public function dropdown(): C\Dropdown\Factory
42  {
43  return new I\Component\Dropdown\Factory();
44  }
45 
46  public function viewControl(): C\ViewControl\Factory
47  {
48  return new I\Component\ViewControl\Factory(new SignalGenerator());
49  }
50 
51  public function button(): C\Button\Factory
52  {
53  return new I\Component\Button\Factory();
54  }
55 
56  public function symbol(): C\Symbol\Factory
57  {
58  return new I\Component\Symbol\Factory(
59  new I\Component\Symbol\Icon\Factory(),
60  new I\Component\Symbol\Glyph\Factory(),
61  new I\Component\Symbol\Avatar\Factory()
62  );
63  }
64  };
65  }
66 
67  protected function cleanHTML(string $html): string
68  {
69  $html = str_replace(["\n", "\t"], "", $html);
70 
71  return trim($html);
72  }
73 
74  public function test_implements_factory_interface(): void
75  {
76  $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("List Title", array(
77 
78  new I\Component\Item\Group("Subtitle 1", array(
79  new I\Component\Item\Standard("title1"),
80  new I\Component\Item\Standard("title2")
81  )),
82  new I\Component\Item\Group("Subtitle 2", array(
83  new I\Component\Item\Standard("title3")
84  ))
85  ));
86 
87  $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Secondary\\Listing", $secondary_panel);
88  }
89 
90  public function test_get_title(): void
91  {
92  $groups = array(
93  new I\Component\Item\Group("Subtitle 1", array(
94  new I\Component\Item\Standard("title1"),
95  new I\Component\Item\Standard("title2")
96  )),
97  new I\Component\Item\Group("Subtitle 2", array(
98  new I\Component\Item\Standard("title3")
99  ))
100  );
101 
102  $c = $this->getUIFactory()->panelSecondary()->listing("title", $groups);
103 
104  $this->assertEquals("title", $c->getTitle());
105  }
106 
107  public function test_get_item_groups(): void
108  {
109  $groups = array(
110  new I\Component\Item\Group("Subtitle 1", array(
111  new I\Component\Item\Standard("title1"),
112  new I\Component\Item\Standard("title2")
113  )),
114  new I\Component\Item\Group("Subtitle 2", array(
115  new I\Component\Item\Standard("title3")
116  ))
117  );
118 
119  $c = $this->getUIFactory()->panelSecondary()->listing("title", $groups);
120 
121  $this->assertEquals($c->getItemGroups(), $groups);
122  }
123 
124  public function test_with_actions(): void
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  $groups = array();
132 
133  $c = $this->getUIFactory()->panelSecondary()->listing("title", $groups)
134  ->withActions($actions);
135 
136  $this->assertEquals($c->getActions(), $actions);
137  }
138 
139  //RENDER
140 
141  public function test_render_with_actions(): void
142  {
143  $actions = $this->getUIFactory()->dropdown()->standard(array(
144  $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
145  $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
146  ));
147 
148  $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())->withActions($actions);
149 
150  $html = $this->getDefaultRenderer()->render($sec);
151 
152  $expected_html = <<<EOT
153 <div class="panel panel-secondary panel-flex">
154  <div class="panel-heading ilHeader">
155  <h2>Title</h2>
156  <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>
157  <ul id="id_3_menu" class="dropdown-menu">
158  <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
159  <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">Github</button></li>
160  </ul>
161  </div>
162  </div>
163  <div class="panel-body">
164  </div>
165 </div>
166 EOT;
167  $this->assertHTMLEquals(
168  $this->cleanHTML($expected_html),
169  $this->cleanHTML($html)
170  );
171  }
172 
173  public function test_render_with_sortation(): void
174  {
175  $sort_options = array(
176  'a' => 'A',
177  'b' => 'B'
178  );
179  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
180  $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())
181  ->withViewControls([$sortation]);
182 
183  $html = $this->getDefaultRenderer()->render($sec);
184 
185  $expected_html = <<<EOT
186 <div class="panel panel-secondary panel-flex">
187  <div class="panel-heading ilHeader">
188  <h2>Title</h2>
189  <div class="il-viewcontrol-sortation" id="id_1">
190  <div class="dropdown">
191  <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">
192  <span class="caret"></span>
193  </button>
194  <ul id="id_4_menu" class="dropdown-menu">
195  <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
196  <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
197  </ul>
198  </div>
199  </div>
200  </div>
201  <div class="panel-body">
202  </div>
203 </div>
204 EOT;
205  $this->assertHTMLEquals(
206  $this->cleanHTML($expected_html),
207  $this->cleanHTML($html)
208  );
209  }
210 
211  public function test_render_with_pagination(): void
212  {
213  $pagination = $this->getUIFactory()->viewControl()->pagination()
214  ->withTargetURL('http://ilias.de', 'page')
215  ->withTotalEntries(10)
216  ->withPageSize(2)
217  ->withCurrentPage(1);
218 
219  $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())
220  ->withViewControls([$pagination]);
221 
222  $html = $this->getDefaultRenderer()->render($sec);
223 
224  $expected_html = <<<EOT
225 <div class="panel panel-secondary panel-flex">
226  <div class="panel-heading ilHeader">
227  <h2>Title</h2>
228  <div class="il-viewcontrol-pagination">
229  <span class="browse previous">
230  <a tabindex="0" class="glyph" href="http://ilias.de?page=0" aria-label="back">
231  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
232  </a>
233  </span>
234  <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
235  <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
236  <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
237  <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
238  <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
239  <span class="browse next">
240  <a tabindex="0" class="glyph" href="http://ilias.de?page=2" aria-label="next">
241  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
242  </a>
243  </span>
244  </div>
245  </div>
246  <div class="panel-body">
247  </div>
248 </div>
249 EOT;
250  $this->assertHTMLEquals(
251  $this->cleanHTML($expected_html),
252  $this->cleanHTML($html)
253  );
254  }
255 
256  public function test_render_with_section(): void
257  {
258  $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
259  $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
260  $current = $this->getUIFactory()->button()->standard("current", "");
261  $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
262 
263  $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("Title", array())
264  ->withViewControls([$section]);
265 
266  $html = $this->getDefaultRenderer()->render($secondary_panel);
267 
268  $expected_html = <<<EOT
269 <div class="panel panel-secondary panel-flex">
270  <div class="panel-heading ilHeader">
271  <h2>Title</h2>
272  <div class="il-viewcontrol-section">
273  <a class="btn btn-default " href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de" id="id_1">
274  <span class="glyphicon glyphicon-chevron-left"></span>
275  </a>
276  <button class="btn btn-default" data-action="">
277  current
278  </button>
279  <a class="btn btn-default " href="http://www.github.com" aria-label="next" data-action="http://www.github.com" id="id_2">
280  <span class="glyphicon glyphicon-chevron-right"></span>
281  </a>
282  </div>
283  </div>
284  <div class="panel-body">
285  </div>
286 </div>
287 EOT;
288  $this->assertHTMLEquals(
289  $this->cleanHTML($expected_html),
290  $this->cleanHTML($html)
291  );
292  }
293  public function test_render_with_footer(): void
294  {
295  $footer_shy_button = $this->getUIFactory()->button()->shy("Action", "");
296  $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array())->withFooter($footer_shy_button);
297 
298  $html = $this->getDefaultRenderer()->render($secondary_panel);
299 
300  $expected_html = <<<EOT
301 <div class="panel panel-secondary panel-flex">\n
302 <div class="panel-body"></div>\n
303 <div class="panel-footer ilBlockInfo"><button class="btn btn-link" data-action="">Action</button></div>\n
304 </div>\n
305 
306 EOT;
307  $this->assertHTMLEquals(
308  $this->cleanHTML($expected_html),
309  $this->cleanHTML($html)
310  );
311  }
312 
314  {
315  $group = new I\Component\Item\Group(
316  "Subtitle 1",
317  array(
318  new I\Component\Item\Standard("title1"),
319  new I\Component\Item\Standard("title2"))
320  );
321 
322  $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array($group));
323 
324  $html = $this->getDefaultRenderer()->render($secondary_panel);
325 
326  $expected_html = <<<EOT
327 <div class="panel panel-secondary panel-flex">
328  <div class="panel-body">
329  <div class="il-item-group">
330  <h3>Subtitle 1</h3>
331  <div class="il-item-group-items">
332  <ul>
333  <li class="il-std-item-container">
334  <div class="il-item il-std-item ">
335  <div class="il-item-title">title1</div>
336  </div>
337  </li>
338  <li class="il-std-item-container">
339  <div class="il-item il-std-item ">
340  <div class="il-item-title">title2</div>
341  </div>
342  </li>
343  </ul>
344  </div>
345  </div>
346  </div>
347 </div>
348 EOT;
349  $this->assertHTMLEquals(
350  $this->brutallyTrimHTML($expected_html),
351  $this->brutallyTrimHTML($html)
352  );
353  }
354 
356  {
357  $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array());
358 
359  $html = $this->getDefaultRenderer()->render($secondary_panel);
360 
361  $this->assertEquals("", $html);
362  }
363 }
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:355
$c
Definition: cli.php:38
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:444
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
Provides common functionality for UI tests.
Definition: Base.php:298
Test secondary listing panels.