ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PanelSecondaryLegacyTest.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 legacyPanel(string $title, C\Legacy\Content $content): I\Component\Panel\Secondary\Legacy
37 {
38 return new I\Component\Panel\Secondary\Legacy($title, $content);
39 }
40
41 public function legacy(): I\Component\Legacy\Factory
42 {
43 return new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
44 }
45
46 public function dropdown(): I\Component\Dropdown\Factory
47 {
48 return new I\Component\Dropdown\Factory();
49 }
50
51 public function viewControl(): I\Component\ViewControl\Factory
52 {
53 return new I\Component\ViewControl\Factory(new SignalGenerator());
54 }
55
56 public function button(): I\Component\Button\Factory
57 {
58 return new I\Component\Button\Factory();
59 }
60
61 public function symbol(): I\Component\Symbol\Factory
62 {
63 return new I\Component\Symbol\Factory(
64 new I\Component\Symbol\Icon\Factory(),
65 new I\Component\Symbol\Glyph\Factory(),
66 new I\Component\Symbol\Avatar\Factory()
67 );
68 }
69 };
70 }
71
72 protected function cleanHTML(string $html): string
73 {
74 $html = str_replace(["\n", "\t"], "", $html);
75
76 return trim($html);
77 }
78
79 public function testImplementsFactoryInterface(): void
80 {
81 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
82 $secondary_panel = $this->getUIFactory()->legacyPanel("List Title", $legacy);
83
84 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Secondary\\Legacy", $secondary_panel);
85 }
86
87 public function testGetTitle(): void
88 {
89 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
90 $secondary_panel = $this->getUIFactory()->legacyPanel("Title", $legacy);
91
92 $this->assertEquals("Title", $secondary_panel->getTitle());
93 }
94
95 public function testGetLegacyComponent(): void
96 {
97 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
98 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy);
99
100 $this->assertEquals($secondary_panel->getLegacyComponent(), $legacy);
101 }
102
103 public function testWithActions(): void
104 {
105 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
106 $actions = $this->getUIFactory()->dropdown()->standard(array(
107 $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
108 $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
109 ));
110
111 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
112 ->withActions($actions);
113
114 $this->assertEquals($secondary_panel->getActions(), $actions);
115 }
116
117 public function testWithoutViewControls(): void
118 {
119 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
120 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy);
121 $array_vc = $secondary_panel->getViewControls();
122
123 $this->assertEquals(null, $array_vc);
124 }
125
126 public function testWithSortationViewControl(): void
127 {
128 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
129 $sort_options = array(
130 'internal_rating' => 'Best',
131 'date_desc' => 'Most Recent',
132 'date_asc' => 'Oldest',
133 );
134 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'internal_rating');
135
136 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
137 ->withViewControls([$sortation]);
138
139 $array_vc = $secondary_panel->getViewControls();
140
141 $this->assertEquals($array_vc[0], $sortation);
142 }
143
144 public function testWithPaginationViewControl(): void
145 {
146 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
147 $pagination = $this->getUIFactory()->viewControl()->pagination()
148 ->withTargetURL("http://ilias.de", 'page')
149 ->withTotalEntries(98)
150 ->withPageSize(10)
151 ->withCurrentPage(1);
152
153 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
154 ->withViewControls([$pagination]);
155
156 $array_vc = $secondary_panel->getViewControls();
157
158 $this->assertEquals($array_vc[0], $pagination);
159 }
160
161 public function testWithSectionViewControl(): void
162 {
163 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
164 $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
165 $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
166 $current = $this->getUIFactory()->button()->standard("current", "");
167 $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
168
169 $secondary_panel = $this->getUIFactory()->legacyPanel("title", $legacy)
170 ->withViewControls([$section]);
171
172 $array_vc = $secondary_panel->getViewControls();
173
174 $this->assertEquals($array_vc[0], $section);
175 }
176
177 //RENDER
178
180 {
181 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
182 $actions = $this->getUIFactory()->dropdown()->standard(array(
183 $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
184 $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
185 ));
186
187 $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)->withActions($actions);
188
189 $html = $this->getDefaultRenderer()->render($sec);
190
191 $expected_html = <<<EOT
192<div class="panel panel-secondary panel-flex">
193 <div class="panel-heading ilHeader">
194 <div class="panel-title"><h2>Title</h2></div>
195 <div class="panel-controls">
196 <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>
197 <ul id="id_3_menu" class="dropdown-menu">
198 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
199 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">Github</button></li>
200 </ul>
201 </div>
202 </div>
203 </div>
204
205 <div class="panel-body">
206 Legacy content
207 </div>
208</div>
209EOT;
210 $this->assertHTMLEquals(
211 $this->brutallyTrimHTML($expected_html),
212 $this->brutallyTrimHTML($html)
213 );
214 }
215
217 {
218 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
219 $sort_options = array(
220 'a' => 'A',
221 'b' => 'B'
222 );
223 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options, 'b');
224 $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)
225 ->withViewControls([$sortation]);
226
227 $html = $this->getDefaultRenderer()->render($sec);
228
229 $expected_html = <<<EOT
230<div class="panel panel-secondary panel-flex">
231 <div class="panel-heading ilHeader">
232 <div class="panel-title"><h2>Title</h2></div>
233 <div class="panel-viewcontrols l-bar__space-keeper">
234 <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_1">
235 <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">
236 <span class="label">vc_sort B</span>
237 <span class="glyphicon-sort"></span>
238 </button>
239 <ul id="id_1_ctrl" class="dropdown-menu">
240 <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button></li>
241 <li class="selected"><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button></li>
242 </ul>
243 </div>
244 </div>
245 <div class="panel-controls"></div>
246 </div>
247 <div class="panel-body">Legacy content</div>
248</div>
249EOT;
250 $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
251 }
252
254 {
255 $legacy = $this->getUIfactory()->legacy()->content("Legacy content");
256
257 $pagination = $this->getUIFactory()->viewControl()->pagination()
258 ->withTargetURL('http://ilias.de', 'page')
259 ->withTotalEntries(10)
260 ->withPageSize(2)
261 ->withCurrentPage(1);
262
263 $sec = $this->getUIFactory()->legacyPanel("Title", $legacy)
264 ->withViewControls([$pagination]);
265
266 $html = $this->getDefaultRenderer()->render($sec);
267
268 $expected_html = <<<EOT
269<div class="panel panel-secondary panel-flex">
270 <div class="panel-heading ilHeader">
271 <div class="panel-title"><h2>Title</h2></div>
272 <div class="panel-viewcontrols l-bar__space-keeper">
273 <div class="il-viewcontrol-pagination l-bar__element">
274 <button class="btn btn-default" data-action="http://ilias.de?page=0" id="id_6">
275 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
276 </button>
277 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
278 <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
279 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
280 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
281 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
282 <button class="btn btn-default" data-action="http://ilias.de?page=2" id="id_7">
283 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
284 </button>
285 </div>
286 </div>
287 <div class="panel-controls"></div>
288 </div>
289 <div class="panel-body">Legacy content</div>
290</div>
291EOT;
292 $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
293 }
294
296 {
297 $legacy = $this->getUIfactory()->legacy()->content("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>
323EOT;
324 $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
325 }
326
328 {
329 $legacy = $this->getUIfactory()->legacy()->content("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>
350EOT;
351 $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
352 }
353
355 {
356 $legacy = $this->getUIfactory()->legacy()->content("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">Legacy content</div>
365</div>
366EOT;
367 $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
368 }
369}
Provides common functionality for UI tests.
Definition: Base.php:337
Test secondary legacy panels.
Title class.
Definition: Title.php:42
button(string $caption, string $cmd)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.