ILIAS  release_7 Revision v7.30-3-g800a261c036
PanelTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> 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
13{
14 public function __construct($id = "")
15 {
16 $this->id = $id;
17 }
18 public function getCanonicalName()
19 {
20 return "Component Dummy";
21 }
22}
23
28{
29 public function getUIFactory()
30 {
31 $factory = new class extends NoUIFactory {
32 public function panelSecondary()
33 {
34 return new I\Component\Panel\Secondary\Factory();
35 }
36 public function dropdown()
37 {
38 return new I\Component\Dropdown\Factory();
39 }
40 public function viewControl()
41 {
42 return new I\Component\ViewControl\Factory(new SignalGenerator());
43 }
44 public function button()
45 {
46 return new I\Component\Button\Factory();
47 }
48 public function symbol() : C\Symbol\Factory
49 {
50 return new I\Component\Symbol\Factory(
51 new I\Component\Symbol\Icon\Factory(),
52 new I\Component\Symbol\Glyph\Factory(),
53 new I\Component\Symbol\Avatar\Factory()
54 );
55 }
56 };
57 return $factory;
58 }
59
63 public function getPanelFactory()
64 {
65 return new I\Component\Panel\Factory(
66 $this->createMock(C\Panel\Listing\Factory::class)
67 );
68 }
69
71 {
72 $f = $this->getPanelFactory();
73
74 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Factory", $f);
75 $this->assertInstanceOf(
76 "ILIAS\\UI\\Component\\Panel\\Standard",
77 $f->standard("Title", array(new ComponentDummy()))
78 );
79 $this->assertInstanceOf(
80 "ILIAS\\UI\\Component\\Panel\\Sub",
81 $f->sub("Title", array(new ComponentDummy()))
82 );
83 $this->assertInstanceOf(
84 "ILIAS\\UI\\Component\\Panel\\Report",
85 $f->report("Title", $f->sub("Title", array(new ComponentDummy())))
86 );
87 }
88
89 public function test_standard_get_title()
90 {
91 $f = $this->getPanelFactory();
92 $p = $f->standard("Title", array(new ComponentDummy()));
93
94 $this->assertEquals($p->getTitle(), "Title");
95 }
96
97 public function test_standard_get_content()
98 {
99 $f = $this->getPanelFactory();
100 $c = new ComponentDummy();
101 $p = $f->standard("Title", array($c));
102
103 $this->assertEquals($p->getContent(), array($c));
104 }
105
107 {
108 $fp = $this->getPanelFactory();
109
110 $p = $fp->standard("Title", array(new ComponentDummy()));
111
112 $actions = new I\Component\Dropdown\Standard(array(
113 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
114 new I\Component\Button\Shy("GitHub", "https://www.github.com")
115 ));
116
117 $p = $p->withActions($actions);
118
119 $this->assertEquals($p->getActions(), $actions);
120 }
121
122 public function test_sub_with_actions()
123 {
124 $fp = $this->getPanelFactory();
125
126 $p = $fp->sub("Title", array(new ComponentDummy()));
127
128 $actions = new I\Component\Dropdown\Standard(array(
129 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
130 new I\Component\Button\Shy("GitHub", "https://www.github.com")
131 ));
132
133 $p = $p->withActions($actions);
134
135 $this->assertEquals($p->getActions(), $actions);
136 }
137
138 public function test_sub_with_card()
139 {
140 $fp = $this->getPanelFactory();
141
142 $p = $fp->sub("Title", array(new ComponentDummy()));
143
144 $card = new I\Component\Card\Card("Card Title");
145
146 $p = $p->withCard($card);
147
148 $this->assertEquals($p->getCard(), $card);
149 }
150
151 public function test_report_get_title()
152 {
153 $f = $this->getPanelFactory();
154 $sub = $f->sub("Title", array(new ComponentDummy()));
155 $p = $f->report("Title", array($sub));
156
157 $this->assertEquals($p->getTitle(), "Title");
158 }
159
160 public function test_report_get_content()
161 {
162 $f = $this->getPanelFactory();
163 $sub = $f->sub("Title", array(new ComponentDummy()));
164 $p = $f->report("Title", $sub);
165
166 $this->assertEquals($p->getContent(), array($sub));
167 }
168 public function test_render_standard()
169 {
170 $f = $this->getPanelFactory();
171 $r = $this->getDefaultRenderer();
172
173 $actions = new I\Component\Dropdown\Standard(array(
174 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
175 new I\Component\Button\Shy("GitHub", "https://www.github.com")
176 ));
177
178 $p = $f->standard("Title", array())->withActions($actions);
179
180 $html = $r->render($p);
181
182 $expected_html = <<<EOT
183<div class="panel panel-primary panel-flex">
184 <div class="panel-heading ilHeader">
185 <h2>Title</h2>
186 <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>
187 <ul class="dropdown-menu">
188 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
189 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
190 </ul>
191 </div>
192 </div>
193 <div class="panel-body"></div>
194</div>
195EOT;
196 $this->assertHTMLEquals($expected_html, $html);
197 }
198
199 public function test_render_sub()
200 {
201 $fp = $this->getPanelFactory();
202 $r = $this->getDefaultRenderer();
203
204 $actions = new I\Component\Dropdown\Standard(array(
205 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
206 new I\Component\Button\Shy("GitHub", "https://www.github.com")
207 ));
208
209 $p = $fp->sub("Title", array())->withActions($actions);
210 $card = new I\Component\Card\Card("Card Title");
211 $p = $p->withCard($card);
212 $html = $this->brutallyTrimHTML($r->render($p));
213
214 $expected_html = <<<EOT
215<div class="panel panel-sub panel-flex">
216 <div class="panel-heading ilBlockHeader">
217 <h4>Title</h4>
218 <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>
219 <ul class="dropdown-menu">
220 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
221 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
222 </ul>
223 </div>
224 </div>
225 <div class="panel-body">
226 <div class="row">
227 <div class="col-sm-8"></div>
228 <div class="col-sm-4">
229 <div class="il-card thumbnail">
230 <div class="card-no-highlight"></div>
231 <div class="caption card-title">Card Title</div>
232 </div>
233 </div>
234 </div>
235 </div>
236</div>
237EOT;
238
239 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
240 }
241
242 public function test_render_report()
243 {
244 $fp = $this->getPanelFactory();
245 $r = $this->getDefaultRenderer();
246 $sub = $fp->sub("Title", array());
247 $card = new I\Component\Card\Card("Card Title");
248 $sub = $sub->withCard($card);
249 $report = $fp->report("Title", $sub);
250
251 $html = $this->brutallyTrimHTML($r->render($report));
252
253 $expected_html = <<<EOT
254<div class="panel panel-primary il-panel-report panel-flex">
255 <div class="panel-heading ilHeader">
256 <h3>Title</h3>
257 </div>
258 <div class="panel-body">
259 <div class="panel panel-sub panel-flex">
260 <div class="panel-heading ilBlockHeader">
261 <h4>Title</h4>
262 </div>
263 <div class="panel-body"><div class="row">
264 <div class="col-sm-8"></div>
265 <div class="col-sm-4">
266 <div class="il-card thumbnail">
267 <div class="card-no-highlight"></div>
268 <div class="caption card-title">Card Title</div>
269 </div>
270 </div>
271 </div>
272 </div>
273 </div>
274 </div>
275</div>
276EOT;
277
278 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
279 }
280
281 public function test_with_view_controls()
282 {
283 $sort_options = [
284 'a' => 'A',
285 'b' => 'B'
286 ];
287 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
288 $f = $this->getPanelFactory();
289 $p = $f->standard("Title", [])
290 ->withViewControls([$sortation]);
291 ;
292
293 $this->assertEquals($p->getViewControls(), [$sortation]);
294 }
295
297 {
298 $sort_options = [
299 'a' => 'A',
300 'b' => 'B'
301 ];
302 $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
303
304 $f = $this->getPanelFactory();
305 $r = $this->getDefaultRenderer();
306
307
308 $p = $f->standard("Title", [])
309 ->withViewControls([$sortation]);
310 ;
311
312 $html = $r->render($p);
313
314 $expected_html = <<<EOT
315<div class="panel panel-primary panel-flex">
316 <div class="panel-heading ilHeader">
317 <h2>Title</h2>
318 <div class="il-viewcontrol-sortation" id="id_1">
319<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>
320<ul class="dropdown-menu">
321 <li><button class="btn btn-link" data-action="?sortation=a" id="id_2">A</button>
322</li>
323 <li><button class="btn btn-link" data-action="?sortation=b" id="id_3">B</button>
324</li>
325</ul>
326</div>
327</div>
328 </div>
329 <div class="panel-body"></div>
330</div>
331EOT;
332 $this->assertHTMLEquals($expected_html, $html);
333 }
334
336 {
337 $pagination = $this->getUIFactory()->viewControl()->pagination()
338 ->withTargetURL('http://ilias.de', 'page')
339 ->withTotalEntries(10)
340 ->withPageSize(2)
341 ->withCurrentPage(1);
342
343 $f = $this->getPanelFactory();
344 $r = $this->getDefaultRenderer();
345
346
347 $p = $f->standard("Title", [])
348 ->withViewControls([$pagination]);
349
350 $html = $r->render($p);
351
352 $expected_html = <<<EOT
353<div class="panel panel-primary panel-flex">
354 <div class="panel-heading ilHeader">
355 <h2>Title</h2>
356 <div class="il-viewcontrol-pagination">
357<span class="browse previous"><a class="glyph" href="http://ilias.de?page=0" aria-label="back">
358<span class="glyphicon
359 glyphicon-chevron-left
360" aria-hidden="true"></span>
361</a>
362</span>
363 <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
364 <button class="btn btn-link engaged" aria-pressed="true" data-action="http://ilias.de?page=1" id="id_2">2</button>
365 <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_3">3</button>
366 <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_4">4</button>
367 <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_5">5</button>
368<span class="browse next"><a class="glyph" href="http://ilias.de?page=2" aria-label="next">
369<span class="glyphicon
370 glyphicon-chevron-right
371" aria-hidden="true"></span>
372</a>
373</span>
374</div>
375
376 </div>
377 <div class="panel-body"></div>
378</div>
379EOT;
380 $this->assertHTMLEquals($expected_html, $html);
381 }
382}
An exception for terminatinating execution or to throw for unit testing.
__construct($id="")
Definition: PanelTest.php:14
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:18
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
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
Test on button implementation.
Definition: PanelTest.php:28
getPanelFactory()
Definition: PanelTest.php:63
test_standard_with_actions()
Definition: PanelTest.php:106
test_render_with_pagination()
Definition: PanelTest.php:335
test_standard_get_content()
Definition: PanelTest.php:97
test_sub_with_card()
Definition: PanelTest.php:138
test_report_get_title()
Definition: PanelTest.php:151
getUIFactory()
Definition: PanelTest.php:29
test_with_view_controls()
Definition: PanelTest.php:281
test_render_report()
Definition: PanelTest.php:242
test_report_get_content()
Definition: PanelTest.php:160
test_render_standard()
Definition: PanelTest.php:168
test_render_with_sortation()
Definition: PanelTest.php:296
test_render_sub()
Definition: PanelTest.php:199
test_sub_with_actions()
Definition: PanelTest.php:122
test_standard_get_title()
Definition: PanelTest.php:89
test_implements_factory_interface()
Definition: PanelTest.php:70
Title class.
Definition: Title.php:37
$c
Definition: cli.php:37
A component is the most general form of an entity in the UI.
Definition: Component.php:14
$factory
Definition: metadata.php:58
Class ChatMainBarProvider \MainMenu\Provider.