ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ItemGroupTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Alex Killing <killing@leifos.de> 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;
10
15{
16
20 public function getFactory()
21 {
22 return new I\Component\Item\Factory;
23 }
24
26 {
27 $f = $this->getFactory();
28
29 $group = $f->group("group", array(
30 $f->standard("title1"),
31 $f->standard("title2")
32 ));
33
34 $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Group", $group);
35 }
36
37 public function test_get_title()
38 {
39 $f = $this->getFactory();
40 $c = $f->group("group", array(
41 $f->standard("title1"),
42 $f->standard("title2")
43 ));
44
45 $this->assertEquals($c->getTitle(), "group");
46 }
47
48 public function test_get_items()
49 {
50 $f = $this->getFactory();
51
52 $items = array(
53 $f->standard("title1"),
54 $f->standard("title2")
55 );
56
57 $c = $f->group("group", $items);
58
59 $this->assertEquals($c->getItems(), $items);
60 }
61
62 public function test_with_actions()
63 {
64 $f = $this->getFactory();
65
66 $actions = new I\Component\Dropdown\Standard(array(
67 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
68 new I\Component\Button\Shy("GitHub", "https://www.github.com")
69 ));
70 $items = array(
71 $f->standard("title1"),
72 $f->standard("title2")
73 );
74
75 $c = $f->group("group", $items)->withActions($actions);
76
77 $this->assertEquals($c->getActions(), $actions);
78 }
79
80 public function test_render_base()
81 {
82 $f = $this->getFactory();
83 $r = $this->getDefaultRenderer();
84
85 $items = array(
86 $f->standard("title1"),
87 $f->standard("title2")
88 );
89
90 $c = $f->group("group", $items);
91
92 $html = $r->render($c);
93
94 $expected = <<<EOT
95<div class="il-item-group">
96 <h3>group</h3>
97 <div class="il-item-group-items">
98 <div class="il-std-item-container"><div class="il-item il-std-item ">
99 <div class="il-item-title">title1</div>
100 </div></div><div class="il-std-item-container"><div class="il-item il-std-item ">
101 <div class="il-item-title">title2</div>
102 </div></div>
103 </div>
104</div>
105EOT;
106 $this->assertHTMLEquals(
107 $this->brutallyTrimHTML($expected),
108 $this->brutallyTrimHTML($html)
109 );
110 }
111
112 public function test_render_with_actions()
113 {
114 $f = $this->getFactory();
115 $r = $this->getDefaultRenderer();
116
117 $actions = new I\Component\Dropdown\Standard(array(
118 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
119 new I\Component\Button\Shy("GitHub", "https://www.github.com")
120 ));
121 $items = array(
122 $f->standard("title1"),
123 $f->standard("title2")
124 );
125
126 $c = $f->group("group", $items)->withActions($actions);
127
128 $html = $r->render($c);
129
130 $expected = <<<EOT
131<div class="il-item-group">
132<h3>group</h3><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>
133 <ul class="dropdown-menu">
134 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
135 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
136 </ul>
137 </div>
138 <div class="il-item-group-items">
139 <div class="il-std-item-container"><div class="il-item il-std-item ">
140 <div class="il-item-title">title1</div>
141 </div></div><div class="il-std-item-container"><div class="il-item il-std-item ">
142 <div class="il-item-title">title2</div>
143 </div></div>
144 </div>
145</div>
146EOT;
147 $this->assertHTMLEquals(
148 $this->brutallyTrimHTML($expected),
149 $this->brutallyTrimHTML($html)
150 );
151 }
152}
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
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:346
Test items groups.
test_implements_factory_interface()
Class ChatMainBarProvider \MainMenu\Provider.