ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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;
9
14{
15
19 public function getFactory()
20 {
21 return new \ILIAS\UI\Implementation\Factory();
22 }
23
25 {
26 $f = $this->getFactory();
27
28 $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Standard", $f->item()->standard("title"));
29 }
30
31 public function test_get_title()
32 {
33 $f = $this->getFactory();
34 $c = $f->item()->standard("title");
35
36 $this->assertEquals($c->getTitle(), "title");
37 }
38
39 public function test_with_description()
40 {
41 $f = $this->getFactory();
42
43 $c = $f->item()->standard("title")->withDescription("description");
44
45 $this->assertEquals($c->getDescription(), "description");
46 }
47
48 public function test_with_properties()
49 {
50 $f = $this->getFactory();
51
52 $props = array("prop1" => "val1", "prop2" => "val2");
53 $c = $f->item()->standard("title")->withProperties($props);
54
55 $this->assertEquals($c->getProperties(), $props);
56 }
57
58 public function test_with_actions()
59 {
60 $f = $this->getFactory();
61
62 $actions = $f->dropdown()->standard(array(
63 $f->button()->shy("ILIAS", "https://www.ilias.de"),
64 $f->button()->shy("GitHub", "https://www.github.com")
65 ));
66 $c = $f->item()->standard("title")->withActions($actions);
67
68 $this->assertEquals($c->getActions(), $actions);
69 }
70
71 public function test_with_color()
72 {
73 $f = $this->getFactory();
74 $df = new \ILIAS\Data\Factory();
75
76 $color = $df->color('#ff00ff');
77
78 $c = $f->item()->standard("title")->withColor($color);
79
80 $this->assertEquals($c->getColor(), $color);
81 }
82
83 public function test_with_lead_image()
84 {
85 $f = $this->getFactory();
86
87 $image = $f->image()->standard("src", "str");
88
89 $c = $f->item()->standard("title")->withLeadImage($image);
90
91 $this->assertEquals($c->getLead(), $image);
92 }
93
94 public function test_with_lead_text()
95 {
96 $f = $this->getFactory();
97
98 $c = $f->item()->standard("title")->withLeadText("text");
99
100 $this->assertEquals($c->getLead(), "text");
101 }
102
103 public function test_with_no_lead()
104 {
105 $f = $this->getFactory();
106
107 $c = $f->item()->standard("title")->withLeadText("text")->withNoLead();
108
109 $this->assertEquals($c->getLead(), null);
110 }
111
112 public function test_render_base()
113 {
114 $f = $this->getFactory();
115 $r = $this->getDefaultRenderer();
116
117 $actions = $f->dropdown()->standard(array(
118 $f->button()->shy("ILIAS", "https://www.ilias.de"),
119 $f->button()->shy("GitHub", "https://www.github.com")
120 ));
121 $c = $f->item()->standard("Item Title")
122 ->withActions($actions)
123 ->withProperties(array(
124 "Origin" => "Course Title 1",
125 "Last Update" => "24.11.2011",
126 "Location" => "Room 123, Main Street 44, 3012 Bern"))
127 ->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.");
128
129 $html = $r->render($c);
130 $expected = <<<EOT
131 <div class="il-item il-std-item ">
132 <h5>Item Title</h5>
133 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" > <span class="caret"></span></button>
134<ul class="dropdown-menu">
135 <li><a class="btn btn-link" href="https://www.ilias.de" data-action="https://www.ilias.de" >ILIAS</a></li>
136 <li><a class="btn btn-link" href="https://www.github.com" data-action="https://www.github.com" >GitHub</a></li>
137</ul>
138</div>
139 <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>
140 <hr class="il-item-divider" />
141 <div class="row">
142 <div class="col-md-6">
143 <div class="row">
144 <div class="col-sm-5 il-item-property-name">Origin</div>
145 <div class="col-sm-7 il-item-property-value il-multi-line-cap-3">Course Title 1</div>
146 </div>
147 </div>
148 <div class="col-md-6">
149 <div class="row">
150 <div class="col-sm-5 il-item-property-name">Last Update</div>
151 <div class="col-sm-7 il-item-property-value il-multi-line-cap-3">24.11.2011</div>
152 </div>
153 </div>
154 </div>
155 <div class="row">
156 <div class="col-md-6">
157 <div class="row">
158 <div class="col-sm-5 il-item-property-name">Location</div>
159 <div class="col-sm-7 il-item-property-value il-multi-line-cap-3">Room 123, Main Street 44, 3012 Bern</div>
160 </div>
161 </div>
162 <div class="col-md-6">
163 <div class="row">
164 <div class="col-sm-5 il-item-property-name"></div>
165 <div class="col-sm-7 il-item-property-value il-multi-line-cap-3"></div>
166 </div>
167 </div>
168 </div>
169</div>
170EOT;
171
172 $this->assertHTMLEquals($expected, $html);
173 }
174
175 public function test_render_lead_image()
176 {
177 $f = $this->getFactory();
178 $r = $this->getDefaultRenderer();
179
180 $image = $f->image()->standard("src", "str");
181
182 $c = $f->item()->standard("title")->withLeadImage($image);
183
184 $html = $r->render($c);
185
186 $expected = <<<EOT
187<div class="il-item il-std-item ">
188 <div class="row">
189 <div class="col-sm-3">
190 <img src="src" class="img-standard" alt="str" />
191 </div>
192 <div class="col-sm-9">
193 <h5>title</h5>
194 </div>
195 </div>
196</div>
197EOT;
198
199 $this->assertHTMLEquals($expected, $html);
200 }
201
203 {
204 $f = $this->getFactory();
205 $r = $this->getDefaultRenderer();
206 $df = new \ILIAS\Data\Factory();
207
208 $color = $df->color('#ff00ff');
209
210 $c = $f->item()->standard("title")->withColor($color)->withLeadText("lead");
211
212 $html = $r->render($c);
213
214 $expected = <<<EOT
215<div class="il-item il-std-item il-item-marker " style="border-color:#ff00ff">
216 <div class="row">
217 <div class="col-sm-3">
218 <h5>lead</h5>
219 </div>
220 <div class="col-sm-9">
221 <h5>title</h5>
222 </div>
223 </div>
224</div>
225EOT;
226
227 $this->assertHTMLEquals($expected, $html);
228 }
229
231 {
232 $f = $this->getFactory();
233 $r = $this->getDefaultRenderer();
234 $df = new \ILIAS\Data\Factory();
235
236 $color = $df->color('#ff00ff');
237
238 $c = $f->item()->standard($f->button()->shy("ILIAS", "https://www.ilias.de"))
239 ->withProperties(array("test" => $f->button()->shy("GitHub", "https://www.github.com")));
240
241 $html = $r->render($c);
242 $expected = <<<EOT
243<div class="il-item il-std-item ">
244 <h5><a class="btn btn-link" href="https://www.ilias.de" data-action="https://www.ilias.de" >ILIAS</a></h5>
245 <hr class="il-item-divider" />
246 <div class="row">
247 <div class="col-md-6">
248 <div class="row">
249 <div class="col-sm-5 il-item-property-name">test</div>
250 <div class="col-sm-7 il-item-property-value il-multi-line-cap-3"><a class="btn btn-link" href="https://www.github.com" data-action="https://www.github.com" >GitHub</a></div>
251 </div>
252 </div>
253 <div class="col-md-6">
254 <div class="row">
255 <div class="col-sm-5 il-item-property-name"></div>
256 <div class="col-sm-7 il-item-property-value il-multi-line-cap-3"></div>
257 </div>
258 </div>
259 </div>
260</div>
261EOT;
262
263 $this->assertHTMLEquals($expected, $html);
264 }
265}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:178
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
Test items.
Definition: ItemTest.php:14
test_with_properties()
Definition: ItemTest.php:48
test_get_title()
Definition: ItemTest.php:31
test_render_lead_text_and_color()
Definition: ItemTest.php:202
test_render_lead_image()
Definition: ItemTest.php:175
test_with_lead_text()
Definition: ItemTest.php:94
test_with_no_lead()
Definition: ItemTest.php:103
test_implements_factory_interface()
Definition: ItemTest.php:24
test_shy_title_and_property()
Definition: ItemTest.php:230
getFactory()
Definition: ItemTest.php:19
test_with_lead_image()
Definition: ItemTest.php:83
test_with_actions()
Definition: ItemTest.php:58
test_with_color()
Definition: ItemTest.php:71
test_render_base()
Definition: ItemTest.php:112
test_with_description()
Definition: ItemTest.php:39
Title class.
Definition: Title.php:37
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
Class BaseForm.
$this data['403_header']