ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ItemTest.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 $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Standard", $f->standard("title"));
30 }
31
32 public function test_get_title()
33 {
34 $f = $this->getFactory();
35 $c = $f->standard("title");
36
37 $this->assertEquals($c->getTitle(), "title");
38 }
39
40 public function test_with_description()
41 {
42 $f = $this->getFactory();
43
44 $c = $f->standard("title")->withDescription("description");
45
46 $this->assertEquals($c->getDescription(), "description");
47 }
48
49 public function test_with_properties()
50 {
51 $f = $this->getFactory();
52
53 $props = array("prop1" => "val1", "prop2" => "val2");
54 $c = $f->standard("title")->withProperties($props);
55
56 $this->assertEquals($c->getProperties(), $props);
57 }
58
59 public function test_with_actions()
60 {
61 $f = $this->getFactory();
62
63 $actions = new I\Component\Dropdown\Standard(array(
64 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
65 new I\Component\Button\Shy("GitHub", "https://www.github.com")
66 ));
67 $c = $f->standard("title")->withActions($actions);
68
69 $this->assertEquals($c->getActions(), $actions);
70 }
71
72 public function test_with_color()
73 {
74 $f = $this->getFactory();
75 $df = new \ILIAS\Data\Factory();
76
77 $color = $df->color('#ff00ff');
78
79 $c = $f->standard("title")->withColor($color);
80
81 $this->assertEquals($c->getColor(), $color);
82 }
83
84 public function test_with_lead_image()
85 {
86 $f = $this->getFactory();
87
88 $image = new I\Component\Image\Image("standard", "src", "str");
89
90 $c = $f->standard("title")->withLeadImage($image);
91
92 $this->assertEquals($c->getLead(), $image);
93 }
94
95 public function test_with_lead_icon()
96 {
97 $f = $this->getFactory();
98
99 $icon = new I\Component\Icon\Standard("name", "aria_label", "small", false);
100
101 $c = $f->standard("title")->withLeadIcon($icon);
102
103 $this->assertEquals($c->getLead(), $icon);
104 }
105
106 public function test_with_lead_text()
107 {
108 $f = $this->getFactory();
109
110 $c = $f->standard("title")->withLeadText("text");
111
112 $this->assertEquals($c->getLead(), "text");
113 }
114
115 public function test_with_no_lead()
116 {
117 $f = $this->getFactory();
118
119 $c = $f->standard("title")->withLeadText("text")->withNoLead();
120
121 $this->assertEquals($c->getLead(), null);
122 }
123
124 public function test_render_base()
125 {
126 $f = $this->getFactory();
127 $r = $this->getDefaultRenderer();
128
129 $actions = new I\Component\Dropdown\Standard(array(
130 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
131 new I\Component\Button\Shy("GitHub", "https://www.github.com")
132 ));
133 $c = $f->standard("Item Title")
134 ->withActions($actions)
135 ->withProperties(array(
136 "Origin" => "Course Title 1",
137 "Last Update" => "24.11.2011",
138 "Location" => "Room 123, Main Street 44, 3012 Bern"))
139 ->withDescription("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.");
140
141 $html = $r->render($c);
142
143 $expected = <<<EOT
144<div class="il-item il-std-item ">
145 <h5>Item Title</h5>
146 <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>
147<ul class="dropdown-menu">
148 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1" >ILIAS</button>
149</li>
150 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2" >GitHub</button>
151</li>
152</ul>
153</div>
154 <div class="il-item-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</div>
155 <hr class="il-item-divider" />
156 <div class="row">
157 <div class="col-md-6">
158 <div class="row">
159 <div class="col-sm-5 col-lg-4 il-item-property-name">Origin</div>
160 <div class="col-sm-7 col-lg-8 il-item-property-value il-multi-line-cap-3">Course Title 1</div>
161 </div>
162 </div>
163 <div class="col-md-6">
164 <div class="row">
165 <div class="col-sm-5 col-lg-4 il-item-property-name">Last Update</div>
166 <div class="col-sm-7 col-lg-8 il-item-property-value il-multi-line-cap-3">24.11.2011</div>
167 </div>
168 </div>
169 </div>
170 <div class="row">
171 <div class="col-md-6">
172 <div class="row">
173 <div class="col-sm-5 col-lg-4 il-item-property-name">Location</div>
174 <div class="col-sm-7 col-lg-8 il-item-property-value il-multi-line-cap-3">Room 123, Main Street 44, 3012 Bern</div>
175 </div>
176 </div>
177 <div class="col-md-6">
178 <div class="row">
179 <div class="col-sm-5 col-lg-4 il-item-property-name"></div>
180 <div class="col-sm-7 col-lg-8 il-item-property-value il-multi-line-cap-3"></div>
181 </div>
182 </div>
183 </div>
184</div>
185EOT;
186
187 $this->assertHTMLEquals($expected, $html);
188 }
189
190 public function test_render_lead_image()
191 {
192 $f = $this->getFactory();
193 $r = $this->getDefaultRenderer();
194
195 $image = new I\Component\Image\Image("standard", "src", "str");
196
197 $c = $f->standard("title")->withLeadImage($image);
198
199 $html = $r->render($c);
200 $expected = <<<EOT
201<div class="il-item il-std-item ">
202 <div class="row">
203 <div class="col-sm-3">
204 <img src="src" class="img-standard" alt="str" />
205 </div>
206 <div class="col-sm-9">
207 <h5>title</h5>
208 </div>
209 </div>
210</div>
211EOT;
212
213 $this->assertHTMLEquals($expected, $html);
214 }
215
216 public function test_render_lead_icon()
217 {
218 $f = $this->getFactory();
219 $r = $this->getDefaultRenderer();
220
221 $icon = new I\Component\Icon\Standard("name", "aria_label", "small", false);
222
223 $c = $f->standard("title")->withLeadIcon($icon);
224
225 $html = $r->render($c);
226 $expected = <<<EOT
227<div class="il-item il-std-item ">
228 <div class="media">
229 <div class="media-left">
230 <div class="icon name small" aria-label="aria_label"></div></div>
231 <div class="media-body">
232 <h5>title</h5>
233 </div>
234 </div>
235</div>
236EOT;
237
238 $this->assertHTMLEquals($expected, $html);
239 }
240
242 {
243 $f = $this->getFactory();
244 $r = $this->getDefaultRenderer();
245 $df = new \ILIAS\Data\Factory();
246
247 $color = $df->color('#ff00ff');
248
249 $c = $f->standard("title")->withColor($color)->withLeadText("lead");
250
251 $html = $r->render($c);
252
253 $expected = <<<EOT
254<div class="il-item il-std-item il-item-marker " style="border-color:#ff00ff">
255 <div class="row">
256 <div class="col-sm-3">
257 <h5>lead</h5>
258 </div>
259 <div class="col-sm-9">
260 <h5>title</h5>
261 </div>
262 </div>
263</div>
264EOT;
265
266 $this->assertHTMLEquals($expected, $html);
267 }
268
270 {
271 $f = $this->getFactory();
272 $r = $this->getDefaultRenderer();
273 $df = new \ILIAS\Data\Factory();
274
275 $color = $df->color('#ff00ff');
276
277 $c = $f->standard(new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"))
278 ->withProperties(array("test" => new I\Component\Button\Shy("GitHub", "https://www.github.com")));
279
280 $html = $r->render($c);
281 $expected = <<<EOT
282<div class="il-item il-std-item ">
283 <h5><button class="btn btn-link" data-action="https://www.ilias.de" id="id_2" >ILIAS</button>
284</h5>
285 <hr class="il-item-divider" />
286 <div class="row">
287 <div class="col-md-6">
288 <div class="row">
289 <div class="col-sm-5 col-lg-4 il-item-property-name">test</div>
290 <div class="col-sm-7 col-lg-8 il-item-property-value il-multi-line-cap-3"><button class="btn btn-link" data-action="https://www.github.com" id="id_1">GitHub</button></div>
291 </div>
292 </div>
293 <div class="col-md-6">
294 <div class="row">
295 <div class="col-sm-5 col-lg-4 il-item-property-name"></div>
296 <div class="col-sm-7 col-lg-8 il-item-property-value il-multi-line-cap-3"></div>
297 </div>
298 </div>
299 </div>
300</div>
301EOT;
302
303 $this->assertHTMLEquals($expected, $html);
304 }
305}
test()
Definition: build.php:107
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:192
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
Test items.
Definition: ItemTest.php:15
test_with_properties()
Definition: ItemTest.php:49
test_get_title()
Definition: ItemTest.php:32
test_render_lead_text_and_color()
Definition: ItemTest.php:241
test_render_lead_image()
Definition: ItemTest.php:190
test_with_lead_text()
Definition: ItemTest.php:106
test_with_no_lead()
Definition: ItemTest.php:115
test_implements_factory_interface()
Definition: ItemTest.php:25
test_with_lead_icon()
Definition: ItemTest.php:95
test_shy_title_and_property()
Definition: ItemTest.php:269
getFactory()
Definition: ItemTest.php:20
test_with_lead_image()
Definition: ItemTest.php:84
test_with_actions()
Definition: ItemTest.php:59
test_render_lead_icon()
Definition: ItemTest.php:216
test_with_color()
Definition: ItemTest.php:72
test_render_base()
Definition: ItemTest.php:124
test_with_description()
Definition: ItemTest.php:40
Title class.
Definition: Title.php:37
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
Class BaseForm.
$this data['403_header']