ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
PanelSecondaryListingTest.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 panelSecondary()
21 {
22 return new I\Component\Panel\Secondary\Factory();
23 }
24 public function dropdown()
25 {
26 return new I\Component\Dropdown\Factory();
27 }
28 public function viewControl()
29 {
30 return new I\Component\ViewControl\Factory(new SignalGenerator());
31 }
32 public function button()
33 {
34 return new I\Component\Button\Factory();
35 }
36 public function symbol() : C\Symbol\Factory
37 {
38 return new I\Component\Symbol\Factory(
39 new I\Component\Symbol\Icon\Factory(),
40 new I\Component\Symbol\Glyph\Factory(),
41 new I\Component\Symbol\Avatar\Factory()
42 );
43 }
44 };
45 return $factory;
46 }
47
48 protected function cleanHTML($html)
49 {
50 $html = str_replace(["\n", "\t"], "", $html);
51
52 return trim($html);
53 }
54
56 {
57 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("List Title", array(
58
59 new I\Component\Item\Group("Subtitle 1", array(
60 new I\Component\Item\Standard("title1"),
61 new I\Component\Item\Standard("title2")
62 )),
63 new I\Component\Item\Group("Subtitle 2", array(
64 new I\Component\Item\Standard("title3")
65 ))
66 ));
67
68 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Secondary\\Listing", $secondary_panel);
69 }
70
71 public function test_get_title()
72 {
73 $groups = array(
74 new I\Component\Item\Group("Subtitle 1", array(
75 new I\Component\Item\Standard("title1"),
76 new I\Component\Item\Standard("title2")
77 )),
78 new I\Component\Item\Group("Subtitle 2", array(
79 new I\Component\Item\Standard("title3")
80 ))
81 );
82
83 $c = $this->getUIFactory()->panelSecondary()->listing("title", $groups);
84
85 $this->assertEquals($c->getTitle(), "title");
86 }
87
88 public function test_get_item_groups()
89 {
90 $groups = array(
91 new I\Component\Item\Group("Subtitle 1", array(
92 new I\Component\Item\Standard("title1"),
93 new I\Component\Item\Standard("title2")
94 )),
95 new I\Component\Item\Group("Subtitle 2", array(
96 new I\Component\Item\Standard("title3")
97 ))
98 );
99
100 $c = $this->getUIFactory()->panelSecondary()->listing("title", $groups);
101
102 $this->assertEquals($c->getItemGroups(), $groups);
103 }
104
105 public function test_with_actions()
106 {
107 $actions = new I\Component\Dropdown\Standard(array(
108 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
109 new I\Component\Button\Shy("GitHub", "https://www.github.com")
110 ));
111
112 $groups = array();
113
114 $c = $this->getUIFactory()->panelSecondary()->listing("title", $groups)
115 ->withActions($actions);
116
117 $this->assertEquals($c->getActions(), $actions);
118 }
119
120 //RENDER
121
122 public function test_render_with_actions()
123 {
124 $actions = $this->getUIFactory()->dropdown()->standard(array(
125 $this->getUIFactory()->button()->shy("ILIAS", "https://www.ilias.de"),
126 $this->getUIFactory()->button()->shy("Github", "https://www.github.com")
127 ));
128
129 $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())->withActions($actions);
130
131 $html = $this->getDefaultRenderer()->render($sec);
132
133 $expected_html = <<<EOT
134<div class="panel panel-secondary panel-flex">
135 <div class="panel-heading ilHeader">
136 <h4>Title</h4>
137 <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>
138 <ul class="dropdown-menu">
139 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
140 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">Github</button></li>
141 </ul>
142 </div>
143 </div>
144 <div class="panel-body">
145 </div>
146</div>
147EOT;
148 $this->assertHTMLEquals(
149 $this->cleanHTML($expected_html),
150 $this->cleanHTML($html)
151 );
152 }
153
155 {
156 $sort_options = array(
157 'a' => 'A',
158 'b' => 'B'
159 );
160 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
161 $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())
162 ->withViewControls([$sortation]);
163
164 $html = $this->getDefaultRenderer()->render($sec);
165
166 $expected_html = <<<EOT
167<div class="panel panel-secondary panel-flex">
168 <div class="panel-heading ilHeader">
169 <h4>Title</h4>
170 <div class="il-viewcontrol-sortation" id="">
171 <div class="dropdown">
172 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false">
173 <span class="caret"></span>
174 </button>
175 <ul class="dropdown-menu">
176 <li><button class="btn btn-link" data-action="?sortation=a" id="id_1">A</button></li>
177 <li><button class="btn btn-link" data-action="?sortation=b" id="id_2">B</button></li>
178 </ul>
179 </div>
180 </div>
181 </div>
182 <div class="panel-body">
183 </div>
184</div>
185EOT;
186 $this->assertHTMLEquals(
187 $this->cleanHTML($expected_html),
188 $this->cleanHTML($html)
189 );
190 }
191
193 {
194 $pagination = $this->getUIFactory()->viewControl()->pagination()
195 ->withTargetURL('http://ilias.de', 'page')
196 ->withTotalEntries(10)
197 ->withPageSize(2)
198 ->withCurrentPage(1);
199
200 $sec = $this->getUIFactory()->panelSecondary()->listing("Title", array())
201 ->withViewControls([$pagination]);
202
203 $html = $this->getDefaultRenderer()->render($sec);
204
205 $expected_html = <<<EOT
206<div class="panel panel-secondary panel-flex">
207 <div class="panel-heading ilHeader">
208 <h4>Title</h4>
209 <div class="il-viewcontrol-pagination">
210 <span class="browse previous">
211 <a class="glyph" href="http://ilias.de?page=0" aria-label="back">
212 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
213 </a>
214 </span>
215 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
216 <button class="btn btn-link" data-action="http://ilias.de?page=1" disabled="true">2</button>
217 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_2">3</button>
218 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_3">4</button>
219 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_4">5</button>
220 <span class="browse next">
221 <a class="glyph" href="http://ilias.de?page=2" aria-label="next">
222 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
223 </a>
224 </span>
225 </div>
226 </div>
227 <div class="panel-body">
228 </div>
229</div>
230EOT;
231 $this->assertHTMLEquals(
232 $this->cleanHTML($expected_html),
233 $this->cleanHTML($html)
234 );
235 }
236
237 public function test_render_with_section()
238 {
239 $back = $this->getUIFactory()->button()->standard("previous", "http://www.ilias.de");
240 $next = $this->getUIFactory()->button()->standard("next", "http://www.github.com");
241 $current = $this->getUIFactory()->button()->standard("current", "");
242 $section = $this->getUIFactory()->viewControl()->section($back, $current, $next);
243
244 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("Title", array())
245 ->withViewControls([$section]);
246
247 $html = $this->getDefaultRenderer()->render($secondary_panel);
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-section">
254 <a class="btn btn-default " href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de">
255 <span class="glyphicon glyphicon-chevron-left"></span>
256 </a>
257 <button class="btn btn-default" data-action="">
258 current
259 </button>
260 <a class="btn btn-default " href="http://www.github.com" aria-label="next" data-action="http://www.github.com">
261 <span class="glyphicon glyphicon-chevron-right"></span>
262 </a>
263 </div>
264 </div>
265 <div class="panel-body">
266 </div>
267</div>
268EOT;
269 $this->assertHTMLEquals(
270 $this->cleanHTML($expected_html),
271 $this->cleanHTML($html)
272 );
273 }
274 public function test_render_with_footer()
275 {
276 $footer_shy_button = $this->getUIFactory()->button()->shy("Action", "");
277 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array())->withFooter($footer_shy_button);
278
279 $html = $this->getDefaultRenderer()->render($secondary_panel);
280
281 $expected_html = <<<EOT
282<div class="panel panel-secondary panel-flex">\n
283<div class="panel-body"></div>\n
284<div class="panel-footer ilBlockInfo"><button class="btn btn-link" data-action="">Action</button></div>\n
285</div>\n
286
287EOT;
288 $this->assertHTMLEquals(
289 $this->cleanHTML($expected_html),
290 $this->cleanHTML($html)
291 );
292 }
293
295 {
296 $group = new I\Component\Item\Group(
297 "Subtitle 1",
298 array(
299 new I\Component\Item\Standard("title1"),
300 new I\Component\Item\Standard("title2"))
301 );
302
303 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array($group));
304
305 $html = $this->getDefaultRenderer()->render($secondary_panel);
306
307 $expected_html = <<<EOT
308<div class="panel panel-secondary panel-flex">
309<div class="panel-body">
310<div class="il-item-group">\n
311 <h3>Subtitle 1</h3>\n
312<div class="il-item-group-items">\n
313<div class="il-std-item-container">
314<div class="il-item il-std-item ">
315<div class="il-item-title">title1</div>
316</div></div>\n
317<div class="il-std-item-container">
318<div class="il-item il-std-item ">
319<div class="il-item-title">title2</div>
320</div>
321</div>\n
322</div>\n
323</div>
324</div>
325</div>\n
326EOT;
327 $this->assertHTMLEquals(
328 $this->cleanHTML($expected_html),
329 $this->cleanHTML($html)
330 );
331 }
332
334 {
335 $secondary_panel = $this->getUIFactory()->panelSecondary()->listing("", array());
336
337 $html = $this->getDefaultRenderer()->render($secondary_panel);
338
339 $this->assertEquals("", $html);
340 }
341}
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:5
$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:225
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
Test secondary listing panels.
Title class.
Definition: Title.php:37
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.