ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation as I;
10 use \ILIAS\UI\Implementation\Component\SignalGenerator;
11 
12 class ComponentDummy implements C\Component
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 
106  public function test_standard_with_actions()
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>
195 EOT;
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 = $r->render($p);
213 
214  $expected_html = <<<EOT
215 <div class="panel panel-sub panel-flex">
216  <div class="panel-heading ilBlockHeader">
217  <h3>Title</h3>
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">
232  <div class="card-title">Card Title</div>
233  </div>
234  </div>
235  </div>
236  </div>
237  </div>
238 </div>
239 EOT;
240 
241  $this->assertHTMLEquals($expected_html, $html);
242  }
243 
244  public function test_render_report()
245  {
246  $fp = $this->getPanelFactory();
247  $r = $this->getDefaultRenderer();
248  $sub = $fp->sub("Title", array());
249  $card = new I\Component\Card\Card("Card Title");
250  $sub = $sub->withCard($card);
251  $report = $fp->report("Title", $sub);
252 
253  $html = $r->render($report);
254 
255  $expected_html = <<<EOT
256 <div class="panel panel-primary il-panel-report panel-flex">
257  <div class="panel-heading ilHeader">
258  <h3>Title</h3>
259  </div>
260  <div class="panel-body">
261  <div class="panel panel-sub panel-flex">
262  <div class="panel-heading ilBlockHeader">
263  <h3>Title</h3>
264  </div>
265  <div class="panel-body"><div class="row">
266  <div class="col-sm-8"></div>
267  <div class="col-sm-4">
268  <div class="il-card thumbnail">
269  <div class="card-no-highlight"></div>
270  <div class="caption">
271  <div class="card-title">Card Title</div>
272  </div>
273  </div>
274  </div>
275  </div>
276  </div>
277  </div>
278  </div>
279 </div>
280 EOT;
281 
282  $this->assertHTMLEquals($expected_html, $html);
283  }
284 
285  public function test_with_view_controls()
286  {
287  $sort_options = [
288  'a' => 'A',
289  'b' => 'B'
290  ];
291  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
292  $f = $this->getPanelFactory();
293  $p = $f->standard("Title", [])
294  ->withViewControls([$sortation]);
295  ;
296 
297  $this->assertEquals($p->getViewControls(), [$sortation]);
298  }
299 
300  public function test_render_with_sortation()
301  {
302  $sort_options = [
303  'a' => 'A',
304  'b' => 'B'
305  ];
306  $sortation = $this->getUIFactory()->viewControl()->sortation($sort_options);
307 
308  $f = $this->getPanelFactory();
309  $r = $this->getDefaultRenderer();
310 
311 
312  $p = $f->standard("Title", [])
313  ->withViewControls([$sortation]);
314  ;
315 
316  $html = $r->render($p);
317 
318  $expected_html = <<<EOT
319 <div class="panel panel-primary panel-flex">
320  <div class="panel-heading ilHeader">
321  <h2>Title</h2>
322  <div class="il-viewcontrol-sortation" id="">
323 <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>
324 <ul class="dropdown-menu">
325  <li><button class="btn btn-link" data-action="?sortation=a" id="id_1">A</button>
326 </li>
327  <li><button class="btn btn-link" data-action="?sortation=b" id="id_2">B</button>
328 </li>
329 </ul>
330 </div>
331 </div>
332  </div>
333  <div class="panel-body"></div>
334 </div>
335 EOT;
336  $this->assertHTMLEquals($expected_html, $html);
337  }
338 
339  public function test_render_with_pagination()
340  {
341  $pagination = $this->getUIFactory()->viewControl()->pagination()
342  ->withTargetURL('http://ilias.de', 'page')
343  ->withTotalEntries(10)
344  ->withPageSize(2)
345  ->withCurrentPage(1);
346 
347  $f = $this->getPanelFactory();
348  $r = $this->getDefaultRenderer();
349 
350 
351  $p = $f->standard("Title", [])
352  ->withViewControls([$pagination]);
353 
354  $html = $r->render($p);
355 
356  $expected_html = <<<EOT
357 <div class="panel panel-primary panel-flex">
358  <div class="panel-heading ilHeader">
359  <h2>Title</h2>
360  <div class="il-viewcontrol-pagination">
361 <span class="browse previous"><a class="glyph" href="http://ilias.de?page=0" aria-label="back">
362 <span class="glyphicon
363  glyphicon-chevron-left
364 " aria-hidden="true"></span>
365 </a>
366 </span>
367  <button class="btn btn-link" data-action="http://ilias.de?page=0" id="id_1">1</button>
368  <button class="btn btn-link" data-action="http://ilias.de?page=1" disabled="disabled">2</button>
369  <button class="btn btn-link" data-action="http://ilias.de?page=2" id="id_2">3</button>
370  <button class="btn btn-link" data-action="http://ilias.de?page=3" id="id_3">4</button>
371  <button class="btn btn-link" data-action="http://ilias.de?page=4" id="id_4">5</button>
372 <span class="browse next"><a class="glyph" href="http://ilias.de?page=2" aria-label="next">
373 <span class="glyphicon
374  glyphicon-chevron-right
375 " aria-hidden="true"></span>
376 </a>
377 </span>
378 </div>
379 
380  </div>
381  <div class="panel-body"></div>
382 </div>
383 EOT;
384  $this->assertHTMLEquals($expected_html, $html);
385  }
386 }
test_implements_factory_interface()
Definition: PanelTest.php:70
test_standard_get_content()
Definition: PanelTest.php:97
test_standard_get_title()
Definition: PanelTest.php:89
Test on button implementation.
Definition: PanelTest.php:27
test_render_standard()
Definition: PanelTest.php:168
Class ChatMainBarProvider .
test_sub_with_card()
Definition: PanelTest.php:138
test_render_with_sortation()
Definition: PanelTest.php:300
test_standard_with_actions()
Definition: PanelTest.php:106
test_render_report()
Definition: PanelTest.php:244
Title class.
Definition: Title.php:36
A component is the most general form of an entity in the UI.
Definition: Component.php:13
getPanelFactory()
Definition: PanelTest.php:63
test_with_view_controls()
Definition: PanelTest.php:285
test_sub_with_actions()
Definition: PanelTest.php:122
Provides common functionality for UI tests.
Definition: Base.php:224
test_render_sub()
Definition: PanelTest.php:199
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:5
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:18
test_report_get_content()
Definition: PanelTest.php:160
__construct($id="")
Definition: PanelTest.php:14
test_report_get_title()
Definition: PanelTest.php:151
test_render_with_pagination()
Definition: PanelTest.php:339
getUIFactory()
Definition: PanelTest.php:29
$factory
Definition: metadata.php:58