ILIAS  release_7 Revision v7.30-3-g800a261c036
PanelSecondaryLegacyTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Jesús López <lopez@leifos.com> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation as I;
10use \ILIAS\UI\Implementation\Component\SignalGenerator;
11
16{
17 public function getUIFactory()
18 {
19 $factory = new class extends NoUIFactory {
20 public function legacyPanel($title, $content)
21 {
22 return new I\Component\Panel\Secondary\Legacy($title, $content);
23 }
24 public function legacy($content)
25 {
26 $f = new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
27 return $f->legacy($content);
28 }
29 public function dropdown()
30 {
31 return new I\Component\Dropdown\Factory();
32 }
33 public function viewControl()
34 {
35 return new I\Component\ViewControl\Factory(new SignalGenerator());
36 }
37 public function button()
38 {
39 return new I\Component\Button\Factory();
40 }
41 public function symbol() : C\Symbol\Factory
42 {
43 return new I\Component\Symbol\Factory(
44 new I\Component\Symbol\Icon\Factory(),
45 new I\Component\Symbol\Glyph\Factory(),
46 new I\Component\Symbol\Avatar\Factory()
47 );
48 }
49 };
50 return $factory;
51 }
52
53 protected function cleanHTML($html)
54 {
55 $html = str_replace(["\n", "\t"], "", $html);
56
57 return trim($html);
58 }
59
61 {
62 $legacy = $this->getUIFactory()->legacy("Legacy content");
63 $secondary_panel = $this->getUIFactory()->legacyPanel("List Title", $legacy);
64
65 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Secondary\\Legacy", $secondary_panel);
66 }
67
68 public function test_get_title()
69 {
70 $legacy = $this->getUIFactory()->legacy("Legacy content");
71 $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy);
72
73 $this->assertEquals($secondary_panel->getTitle(), "Title");
74 }
75
76 public function test_get_legacy_component()
77 {
78 $legacy = $this->getUIFactory()->legacy("Legacy content");
79 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy);
80
81 $this->assertEquals($secondary_panel->getLegacyComponent(), $legacy);
82 }
83
84 public function test_with_actions()
85 {
86 $legacy = $this->getUIFactory()->legacy("Legacy content");
87 $actions = $this->getUIFactory()->dropdown()->standard(array(
88 $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
89 $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
90 ));
91
92 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
93 ->withActions($actions);
94
95 $this->assertEquals($secondary_panel->getActions(), $actions);
96 }
97
98 public function test_without_viewcontrols()
99 {
100 $legacy = $this->getUIFactory()->legacy("Legacy content");
101 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy);
102 $array_vc = $secondary_panel->getViewControls();
103
104 $this->assertEquals($array_vc, null);
105 }
106
108 {
109 $legacy = $this->getUIFactory()->legacy("Legacy content");
110 $sort_options = array(
111 'internal_rating' => 'Best',
112 'date_desc' => 'Most Recent',
113 'date_asc' => 'Oldest',
114 );
115 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
116
117 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
118 ->withViewControls([$sortation]);
119
120 $array_vc = $secondary_panel->getViewControls();
121
122 $this->assertEquals($array_vc[0], $sortation);
123 }
124
126 {
127 $legacy = $this->getUIFactory()->legacy("Legacy content");
128 $pagination = $this->getUIFactory()->viewControl()->pagination()
129 ->withTargetURL("http://ilias.de", 'page')
130 ->withTotalEntries(98)
131 ->withPageSize(10)
132 ->withCurrentPage(1);
133
134 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
135 ->withViewControls([$pagination]);
136
137 $array_vc = $secondary_panel->getViewControls();
138
139 $this->assertEquals($array_vc[0], $pagination);
140 }
141
143 {
144 $legacy = $this->getUIFactory()->legacy("Legacy content");
145 $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
146 $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
147 $current = $this->getUIFactory()->button()->standard("current", "");
148 $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
149
150 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
151 ->withViewControls([$section]);
152
153 $array_vc = $secondary_panel->getViewControls();
154
155 $this->assertEquals($array_vc[0], $section);
156 }
157
158 //RENDER
159
160 public function test_render_with_actions()
161 {
162 $legacy = $this->getUIFactory()->legacy("Legacy content");
163 $actions = $this->getUIFactory()->dropdown()->standard(array(
164 $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
165 $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
166 ));
167
168 $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)->withActions($actions);
169
170 $html = $this->getDefaultRenderer()->render($sec);
171
172 $expected_html = <<<EOT
173<div class="panel panel-secondary panel-flex">
174 <div class="panel-heading ilHeader">
175 <h4>Title</h4>
176 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span></button>
177 <ul class="dropdown-menu">
178 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
179 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">Github</button></li>
180 </ul>
181 </div>
182 </div>
183 <div class="panel-body">
184 Legacy content
185 </div>
186</div>
187EOT;
188 $this->assertHTMLEquals(
189 $this->cleanHTML($expected_html),
190 $this->cleanHTML($html)
191 );
192 }
193
195 {
196 $legacy = $this->getUIFactory()->legacy("Legacy content");
197 $sort_options = array(
198 'a' => 'A',
199 'b' => 'B'
200 );
201 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
202 $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)
203 ->withViewControls([$sortation]);
204
205 $html = $this->getDefaultRenderer()->render($sec);
206
207 $expected_html = <<<EOT
208<div class="panel panel-secondary panel-flex">
209 <div class="panel-heading ilHeader">
210 <h4>Title</h4>
211 <div class="il-viewcontrol-sortation" id="id_1">
212 <div class="dropdown">
213 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false">
214 <span class="caret"></span>
215 </button>
216 <ul class="dropdown-menu">
217 <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
218 <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
219 </ul>
220 </div>
221 </div>
222 </div>
223 <div class="panel-body">
224 Legacy content
225 </div>
226</div>
227EOT;
228 $this->assertHTMLEquals(
229 $this->cleanHTML($expected_html),
230 $this->cleanHTML($html)
231 );
232 }
233
235 {
236 $legacy = $this->getUIFactory()->legacy("Legacy content");
237
238 $pagination = $this->getUIFactory()->viewControl()->pagination()
239 ->withTargetURL('http://ilias.de', 'page')
240 ->withTotalEntries(10)
241 ->withPageSize(2)
242 ->withCurrentPage(1);
243
244 $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)
245 ->withViewControls([$pagination]);
246
247 $html = $this->getDefaultRenderer()->render($sec);
248
249 $expected_html = <<<EOT
250<div class="panel panel-secondary panel-flex">
251 <div class="panel-heading ilHeader">
252 <h4>Title</h4>
253 <div class="il-viewcontrol-pagination">
254 <span class="browse previous">
255 <a class="glyph" href="http://ilias.de?page=0" aria-label="back">
256 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
257 </a>
258 </span>
259 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
260 <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
261 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
262 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
263 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
264 <span class="browse next">
265 <a class="glyph" href="http://ilias.de?page=2" aria-label="next">
266 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
267 </a>
268 </span>
269 </div>
270 </div>
271 <div class="panel-body">
272 Legacy content
273 </div>
274</div>
275EOT;
276 $this->assertHTMLEquals(
277 $this->cleanHTML($expected_html),
278 $this->cleanHTML($html)
279 );
280 }
281
282 public function test_render_with_section()
283 {
284 $legacy = $this->getUIFactory()->legacy("Legacy content");
285 $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
286 $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
287 $current = $this->getUIFactory()->button()->standard("current", "");
288 $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
289
290 $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy)
291 ->withViewControls([$section]);
292
293 $html = $this->getDefaultRenderer()->render($secondary_panel);
294
295 $expected_html = <<<EOT
296<div class="panel panel-secondary panel-flex">
297 <div class="panel-heading ilHeader">
298 <h4>Title</h4>
299 <div class="il-viewcontrol-section">
300 <a class="btn btn-default " href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de" id="id_1">
301 <span class="glyphicon glyphicon-chevron-left"></span>
302 </a>
303 <button class="btn btn-default" data-action="">
304 current
305 </button>
306 <a class="btn btn-default " href="http://www.github.com" aria-label="next" data-action="http://www.github.com" id="id_2">
307 <span class="glyphicon glyphicon-chevron-right"></span>
308 </a>
309 </div>
310 </div>
311 <div class="panel-body">
312 Legacy content
313 </div>
314</div>
315EOT;
316 $this->assertHTMLEquals(
317 $this->cleanHTML($expected_html),
318 $this->cleanHTML($html)
319 );
320 }
321
322 public function test_render_with_footer()
323 {
324 $legacy = $this->getUIFactory()->legacy("Legacy content");
325 $footer_shy_button = $this->getUIFactory()->button()->shy("Action", "");
326
327 $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy)
328 ->withFooter($footer_shy_button);
329
330 $html = $this->getDefaultRenderer()->render($secondary_panel);
331
332 $expected_html = <<<EOT
333<div class="panel panel-secondary panel-flex">
334 <div class="panel-heading ilHeader">
335 <h4>Title</h4>
336 </div>
337 <div class="panel-body">
338 Legacy content
339 </div>
340 <div class="panel-footer ilBlockInfo">
341 <button class="btn btn-link" data-action="">Action</button>
342 </div>
343</div>
344EOT;
345 $this->assertHTMLEquals(
346 $this->cleanHTML($expected_html),
347 $this->cleanHTML($html)
348 );
349 }
350
352 {
353 $legacy = $this->getUIFactory()->legacy("Legacy content");
354
355 $secondary_panel = $this->getUIFactory()->legacyPanel("", $legacy);
356
357 $html = $this->getDefaultRenderer()->render($secondary_panel);
358
359 $expected_html = <<<EOT
360<div class="panel panel-secondary panel-flex">
361 <div class="panel-body">
362 Legacy content
363 </div>
364</div>
365EOT;
366 $this->assertHTMLEquals(
367 $this->cleanHTML($expected_html),
368 $this->cleanHTML($html)
369 );
370 }
371}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:263
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Test secondary legacy panels.
Title class.
Definition: Title.php:37
legacy()
Definition: legacy.php:3
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.