ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PanelSecondaryListingTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
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(): I\Component\Dropdown\Factory
42 {
43 return new I\Component\Dropdown\Factory();
44 }
45
46 public function viewControl(): I\Component\ViewControl\Factory
47 {
48 return new I\Component\ViewControl\Factory(new SignalGenerator());
49 }
50
51 public function button(): I\Component\Button\Factory
52 {
53 return new I\Component\Button\Factory();
54 }
55
56 public function symbol(): I\Component\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 testImplementsFactoryInterface(): 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 testGetTitle(): 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 testGetItemGroups(): 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 testWithActions(): 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 testRenderWithActions(): 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 <div class="panel-title"><h2>Title</h2></div>
156 <div class="panel-controls">
157 <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>
158 <ul id="id_3_menu" class="dropdown-menu">
159 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
160 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">Github</button></li>
161 </ul>
162 </div>
163 </div>
164 </div>
165 <div class="panel-body">
166 </div>
167</div>
168EOT;
169 $this->assertEquals(
170 $this->brutallyTrimHTML($expected_html),
171 $this->brutallyTrimHTML($html)
172 );
173 }
174
175 public function testRenderWithSortation(): void
176 {
177 $sort_options = array(
178 'a' => 'A',
179 'b' => 'B'
180 );
181 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'a');
182 $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())
183 ->withViewControls([$sortation]);
184
185 $html = $this->getDefaultRenderer()->render($sec);
186
187 $expected_html = <<<EOT
188<div class="panel panel-secondary panel-flex">
189 <div class="panel-heading ilHeader">
190 <div class="panel-title"><h2>Title</h2></div>
191 <div class="panel-viewcontrols l-bar__space-keeper">
192 <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_1">
193 <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">
194 <span class="label">vc_sort A</span>
195 <span class="glyphicon-sort"></span>
196 </button>
197 <ul id="id_1_ctrl" class="dropdown-menu">
198 <li class="selected"><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
199 <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
200 </ul>
201 </div>
202 </div>
203 <div class="panel-controls"></div>
204 </div>
205 <div class="panel-body">
206 </div>
207</div>
208EOT;
209 $this->assertEquals(
210 $this->brutallyTrimHTML($expected_html),
211 $this->brutallyTrimHTML($html)
212 );
213 }
214
215 public function testRenderWithPagination(): void
216 {
217 $pagination = $this->getUIFactory()->viewControl()->pagination()
218 ->withTargetURL('http://ilias.de', 'page')
219 ->withTotalEntries(10)
220 ->withPageSize(2)
221 ->withCurrentPage(1);
222
223 $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())
224 ->withViewControls([$pagination]);
225
226 $html = $this->getDefaultRenderer()->render($sec);
227
228 $expected_html = <<<EOT
229<div class="panel panel-secondary panel-flex">
230 <div class="panel-heading ilHeader">
231 <div class="panel-title"><h2>Title</h2></div>
232 <div class="panel-viewcontrols l-bar__space-keeper">
233 <div class="il-viewcontrol-pagination l-bar__element">
234 <button class="btn btn-default" data-action="http://ilias.de?page=0" id="id_6">
235 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
236 </button>
237 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
238 <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
239 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
240 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
241 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
242 <button class="btn btn-default" data-action="http://ilias.de?page=2" id="id_7">
243 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
244 </button>
245 </div>
246 </div>
247 <div class="panel-controls"></div>
248 </div>
249 <div class="panel-body"></div>
250</div>
251EOT;
252 $this->assertEquals(
253 $this->brutallyTrimHTML($expected_html),
254 $this->brutallyTrimHTML($html)
255 );
256 }
257
258 public function testRenderWithSection(): void
259 {
260 $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
261 $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
262 $current = $this->getUIFactory()->button()->standard("current", "");
263 $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
264
265 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("Title", array())
266 ->withViewControls([$section]);
267
268 $html = $this->getDefaultRenderer()->render($secondary_panel);
269
270 $expected_html = <<<EOT
271<div class="panel panel-secondary panel-flex">
272 <div class="panel-heading ilHeader">
273 <div class="panel-title"><h2>Title</h2></div>
274 <div class="panel-viewcontrols l-bar__space-keeper">
275 <div class="il-viewcontrol-section l-bar__element">
276 <a class="btn btn-ctrl browse previous" href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de" id="id_1">
277 <span class="glyphicon glyphicon-chevron-left"></span>
278 </a>
279 <button class="btn btn-default" data-action="">current</button>
280 <a class="btn btn-ctrl browse next" href="http://www.github.com" aria-label="next" data-action="http://www.github.com" id="id_2">
281 <span class="glyphicon glyphicon-chevron-right"></span>
282 </a>
283 </div>
284 </div>
285 <div class="panel-controls"></div>
286 </div>
287 <div class="panel-body">
288 </div>
289</div>
290EOT;
291 $this->assertEquals(
292 $this->brutallyTrimHTML($expected_html),
293 $this->brutallyTrimHTML($html)
294 );
295 }
296 public function testRenderWithFooter(): void
297 {
298 $footer_shy_button = $this->getUIFactory()->button()->shy("Action", "");
299 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array())->withFooter($footer_shy_button);
300
301 $html = $this->getDefaultRenderer()->render($secondary_panel);
302
303 $expected_html = <<<EOT
304<div class="panel panel-secondary panel-flex">\n
305<div class="panel-body"></div>\n
306<div class="panel-footer ilBlockInfo"><button class="btn btn-link" data-action="">Action</button></div>\n
307</div>\n
308
309EOT;
310 $this->assertHTMLEquals(
311 $this->brutallyTrimHTML($expected_html),
312 $this->brutallyTrimHTML($html)
313 );
314 }
315
316 public function testRenderWithNoHeaderButContent(): void
317 {
318 $group = new I\Component\Item\Group(
319 "Subtitle 1",
320 array(
321 new I\Component\Item\Standard("title1"),
322 new I\Component\Item\Standard("title2"))
323 );
324
325 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array($group));
326
327 $html = $this->getDefaultRenderer()->render($secondary_panel);
328
329 $expected_html = <<<EOT
330<div class="panel panel-secondary panel-flex">
331 <div class="panel-body">
332 <div class="il-item-group">
333 <h3>Subtitle 1</h3>
334 <div class="il-item-group-items">
335 <ul>
336 <li class="il-std-item-container">
337 <div class="il-item il-std-item ">
338 <h4 class="il-item-title">title1</h4>
339 </div>
340 </li>
341 <li class="il-std-item-container">
342 <div class="il-item il-std-item ">
343 <h4 class="il-item-title">title2</h4>
344 </div>
345 </li>
346 </ul>
347 </div>
348 </div>
349 </div>
350</div>
351EOT;
352 $this->assertHTMLEquals(
353 $this->brutallyTrimHTML($expected_html),
354 $this->brutallyTrimHTML($html)
355 );
356 }
357
359 {
360 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array());
361
362 $html = $this->getDefaultRenderer()->render($secondary_panel);
363
364 $this->assertEquals("", $html);
365 }
366}
Provides common functionality for UI tests.
Definition: Base.php:337
Test secondary listing panels.
Title class.
Definition: Title.php:42
$c
Definition: deliver.php:25
button(string $caption, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.