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