ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RepositoryObjectTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Jesús López <lopez@leifos.com> 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
16{
17
21 public function getFactory()
22 {
23 return new \ILIAS\UI\Implementation\Factory(
24 $this->createMock(C\Counter\Factory::class),
25 $this->createMock(C\Glyph\Factory::class),
26 $this->createMock(C\Button\Factory::class),
27 $this->createMock(C\Listing\Factory::class),
28 $this->createMock(C\Image\Factory::class),
29 $this->createMock(C\Panel\Factory::class),
30 $this->createMock(C\Modal\Factory::class),
31 $this->createMock(C\Dropzone\Factory::class),
32 $this->createMock(C\Popover\Factory::class),
33 $this->createMock(C\Divider\Factory::class),
34 $this->createMock(C\Link\Factory::class),
35 $this->createMock(C\Dropdown\Factory::class),
36 $this->createMock(C\Item\Factory::class),
37 $this->createMock(C\Icon\Factory::class),
38 $this->createMock(C\ViewControl\Factory::class),
39 $this->createMock(C\Chart\Factory::class),
40 $this->createMock(C\Input\Factory::class),
41 $this->createMock(C\Table\Factory::class),
42 $this->createMock(C\MessageBox\Factory::class),
43 $this->createMock(C\Card\Factory::class)
44 );
45 }
46
47 private function getCardFactory()
48 {
49 return new \ILIAS\UI\Implementation\Component\Card\Factory();
50 }
51
52 private function getBaseCard()
53 {
54 $cf = $this->getCardFactory();
55 $image = new I\Component\Image\Image("standard", "src", "alt");
56
57 return $cf->repositoryObject("Card Title", $image);
58 }
59
61 {
62 $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\RepositoryObject", $this->getBaseCard());
63 }
64
65 public function test_with_object_icon()
66 {
67 $icon = new I\Component\Icon\Standard("crs", 'Course', 'medium', false);
68 $card = $this->getBaseCard();
69 $card = $card->withObjectIcon($icon);
70
71 $this->assertEquals($card->getObjectIcon(), $icon);
72 }
73
74 public function test_with_progress()
75 {
76 $progressmeter = new I\Component\Chart\ProgressMeter\Mini(100, 70);
77 $card = $this->getBaseCard();
78 $card = $card->withProgress($progressmeter);
79
80 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Mini", $progressmeter);
81 $this->assertEquals($progressmeter, $card->getProgress());
82 }
83
85 {
86 $card = $this->getBaseCard();
87 $card_with_cert_true = $card->withCertificateIcon(true);
88 $card_with_cert_false = $card->withCertificateIcon(false);
89
90 $this->assertNull($card->getCertificateIcon());
91 $this->assertTrue($card_with_cert_true->getCertificateIcon());
92 $this->assertFalse($card_with_cert_false->getCertificateIcon());
93 }
94
95 public function test_with_actions()
96 {
97 $f = $this->getFactory();
98 $items = array(
99 $f->button()->shy("Go to Course", "#"),
100 $f->button()->shy("Go to Portfolio", "#"),
101 $f->divider()->horizontal(),
102 $f->button()->shy("ilias.de", "http://www.ilias.de")
103 );
104
105 $dropdown = new I\Component\Dropdown\Standard($items);
106 $card = $this->getBaseCard();
107 $card = $card->withActions($dropdown);
108
109 $this->assertInstanceOf("ILIAS\\UI\\Component\\Dropdown\\Standard", $dropdown);
110 $this->assertEquals($card->getActions(), $dropdown);
111 }
112
114 {
115 $r = $this->getDefaultRenderer();
116
117 $icon = new I\Component\Icon\Standard("crs", 'Course', 'medium', false);
118 $c = $this->getBaseCard();
119 $c = $c->withObjectIcon($icon);
120
121 $html = $r->render($c);
122
123 $expected_html = <<<EOT
124<div class="il-card thumbnail">
125
126 <div class="il-card-repository-head">
127 <div>
128 <div class="icon crs medium" aria-label="Course">
129
130
131</div>
132
133 </div>
134 <div>
135
136 </div>
137 <div class="il-card-repository-dropdown">
138
139 </div>
140 </div>
141<img src="src" class="img-standard" alt="alt" />
142 <div class="card-no-highlight"></div>
143 <div class="caption">
144 <h5 class="card-title">Card Title</h5>
145 </div>
146
147</div>
148EOT;
149
150 $this->assertHTMLEquals($expected_html, $html);
151 }
152
154 {
155 $r = $this->getDefaultRenderer();
156 $c = $this->getBaseCard();
157
158 //TODO get skin fail?
159 $c = $c->withCertificateIcon(true);
160
161 $html = $r->render($c);
162
163 $expected_html = <<<EOT
164<div class="il-card thumbnail">
165
166 <div class="il-card-repository-head">
167 <div>
168
169 </div>
170 <div>
171 <div class="icon cert medium outlined" aria-label="Certificate">
172
173
174</div>
175
176 </div>
177 <div class="il-card-repository-dropdown">
178
179 </div>
180 </div>
181<img src="src" class="img-standard" alt="alt" />
182 <div class="card-no-highlight"></div>
183 <div class="caption">
184 <h5 class="card-title">Card Title</h5>
185 </div>
186
187</div>
188EOT;
189
190 $this->assertHTMLEquals($expected_html, $html);
191 }
192
194 {
195 $r = $this->getDefaultRenderer();
196 $c = $this->getBaseCard();
197 $prg = new I\Component\Chart\ProgressMeter\Mini(100, 80);
198 $c = $c->withProgress($prg);
199
200 $html = $r->render($c);
201
202 $expected_html = <<<EOT
203<div class="il-card thumbnail">
204
205 <div class="il-card-repository-head">
206 <div>
207
208 </div>
209 <div>
210 <div class="il-chart-progressmeter-box il-chart-progressmeter-mini">
211<div class="il-chart-progressmeter-container">
212<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">
213<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100"
214d="M9,35 q-4.3934,-4.3934 -4.3934,-10.6066 a1,1 0 1,1 40,0 q0,6.2132 -4.3934,10.6066"></path>
215<path class="il-chart-progressmeter-circle no-success" stroke-dasharray="69.2, 100"
216d="M9,35 q-4.3934,-4.3934 -4.3934,-10.6066 a1,1 0 1,1 40,0 q0,6.2132 -4.3934,10.6066"></path>
217<path class="il-chart-progressmeter-needle no-needle" stroke-dasharray="100, 100"
218d="M25,10 l0,15" style="transform: rotate(deg)"></path>
219</svg>
220</div>
221</div>
222 </div>
223 <div class="il-card-repository-dropdown">
224
225 </div>
226 </div>
227<img src="src" class="img-standard" alt="alt" />
228 <div class="card-no-highlight"></div>
229 <div class="caption">
230 <h5 class="card-title">Card Title</h5>
231 </div>
232
233</div>
234EOT;
235
236 $this->assertHTMLEquals($expected_html, $html);
237 }
238
239 public function test_render_with_actions()
240 {
241 $f = $this->getFactory();
242 $r = $this->getDefaultRenderer();
243 $c = $this->getBaseCard();
244 $items = array(
245 new I\Component\Button\Shy("Visit ILIAS", "https://www.ilias.de")
246 );
247 $dropdown = new I\Component\Dropdown\Standard($items);
248 $c = $c->withActions($dropdown);
249 $html = $r->render($c);
250
251 $expected_html = <<<EOT
252<div class="il-card thumbnail">
253
254 <div class="il-card-repository-head">
255 <div>
256
257 </div>
258 <div>
259
260 </div>
261 <div class="il-card-repository-dropdown">
262 <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>
263<ul class="dropdown-menu">
264 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1" >Visit ILIAS</button>
265</li>
266</ul>
267</div>
268
269 </div>
270 </div>
271<img src="src" class="img-standard" alt="alt" />
272 <div class="card-no-highlight"></div>
273 <div class="caption">
274 <h5 class="card-title">Card Title</h5>
275 </div>
276
277</div>
278EOT;
279
280 $this->assertHTMLEquals($expected_html, $html);
281 }
282}
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
TODO change the custom icons to standard icons Test on Repository Object card implementation.
Title class.
Definition: Title.php:37
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
Class BaseForm.
$this data['403_header']