ILIAS  release_8 Revision v8.24
RepositoryObjectTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
32{
36 public function getFactory()
37 {
38 $mocks = [
39 'button' => $this->createMock(C\Button\Factory::class),
40 'divider' => $this->createMock(C\Divider\Factory::class),
41 ];
42 $factory = new class ($mocks) extends NoUIFactory {
43 public function __construct($mocks)
44 {
45 $this->mocks = $mocks;
46 }
47 public function legacy($content): C\Legacy\Legacy
48 {
49 $f = new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
50 return $f->legacy($content);
51 }
52 public function button(): C\Button\Factory
53 {
54 return $this->mocks['button'];
55 }
56 public function divider(): C\Divider\Factory
57 {
58 return $this->mocks['divider'];
59 }
60 public function symbol(): C\Symbol\Factory
61 {
62 return new I\Component\Symbol\Factory(
63 new I\Component\Symbol\Icon\Factory(),
64 new I\Component\Symbol\Glyph\Factory(),
65 new I\Component\Symbol\Avatar\Factory()
66 );
67 }
68 };
69 return $factory;
70 }
71
72 private function getCardFactory(): Factory
73 {
74 return new Factory();
75 }
76
77 private function getBaseCard(): C\Card\RepositoryObject
78 {
79 $cf = $this->getCardFactory();
80 $image = new I\Component\Image\Image("standard", "src", "alt");
81
82 return $cf->repositoryObject("Card Title", $image);
83 }
84
85 public function test_implements_factory_interface(): void
86 {
87 $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\RepositoryObject", $this->getBaseCard());
88 }
89
90 public function test_factory_with_shy_button(): void
91 {
92 $button_factory = new I\Component\Button\Factory();
93 $button = $button_factory->shy("Card Title New", "");
94
95 $cf = $this->getCardFactory();
96 $image = new I\Component\Image\Image("standard", "src", "alt");
97
98 $this->assertEquals($button, $cf->repositoryObject($button, $image)->getTitle());
99 }
100
101 public function test_with_object_icon(): void
102 {
103 $icon = new I\Component\Symbol\Icon\Standard("crs", 'Course', 'medium', false);
104 $card = $this->getBaseCard();
105 $card = $card->withObjectIcon($icon);
106
107 $this->assertEquals($card->getObjectIcon(), $icon);
108 }
109
110 public function test_with_progress(): void
111 {
112 $progressmeter = new I\Component\Chart\ProgressMeter\Mini(100, 70);
113 $card = $this->getBaseCard();
114 $card = $card->withProgress($progressmeter);
115
116 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Mini", $progressmeter);
117 $this->assertEquals($progressmeter, $card->getProgress());
118 }
119
120 public function test_with_certificate_icon(): void
121 {
122 $card = $this->getBaseCard();
123 $card_with_cert_true = $card->withCertificateIcon(true);
124 $card_with_cert_false = $card->withCertificateIcon(false);
125
126 $this->assertNull($card->getCertificateIcon());
127 $this->assertTrue($card_with_cert_true->getCertificateIcon());
128 $this->assertFalse($card_with_cert_false->getCertificateIcon());
129 }
130
131 public function test_with_actions(): void
132 {
133 $f = $this->getFactory();
134 $items = array(
135 $f->button()->shy("Go to Course", "#"),
136 $f->button()->shy("Go to Portfolio", "#"),
137 $f->divider()->horizontal(),
138 $f->button()->shy("ilias.de", "http://www.ilias.de")
139 );
140
141 $dropdown = new I\Component\Dropdown\Standard($items);
142 $card = $this->getBaseCard();
143 $card = $card->withActions($dropdown);
144
145 $this->assertInstanceOf("ILIAS\\UI\\Component\\Dropdown\\Standard", $dropdown);
146 $this->assertEquals($card->getActions(), $dropdown);
147 }
148
149 public function test_with_title_as_shy(): void
150 {
151 $c = $this->getBaseCard();
152 $button_factory = new I\Component\Button\Factory();
153 $button = $button_factory->shy("Card Title New", "");
154
155 $c = $c->withTitle($button);
156 $this->assertEquals($button, $c->getTitle());
157 }
158
159 public function test_render_with_object_icon(): void
160 {
161 $r = $this->getDefaultRenderer();
162
163 $icon = new I\Component\Symbol\Icon\Standard("crs", 'Course', 'medium', false);
164 $c = $this->getBaseCard();
165 $c = $c->withObjectIcon($icon);
166
167 $html = $this->brutallyTrimHTML($r->render($c));
168
169 $expected_html = $this->brutallyTrimHTML(<<<EOT
170<div class="il-card thumbnail">
171 <div class="il-card-repository-head">
172 <div>
173 <img class="icon crs medium" src="./templates/default/images/icon_crs.svg" alt="Course" />
174 </div>
175 <div>
176
177 </div>
178 <div class="il-card-repository-dropdown">
179
180 </div>
181 </div>
182 <div class="il-card-image-container"><img src="src" class="img-standard" alt="open Card Title" /></div>
183 <div class="card-no-highlight"></div>
184 <div class="caption card-title">Card Title</div>
185</div>
186EOT);
187
188 $this->assertHTMLEquals($expected_html, $html);
189 }
190
191 public function test_render_with_certificate_icon(): void
192 {
193 $r = $this->getDefaultRenderer();
194 $c = $this->getBaseCard();
195
196 //TODO get skin fail?
197 $c = $c->withCertificateIcon(true);
198
199 $html = $this->brutallyTrimHTML($r->render($c));
200
201 $expected_html = $this->brutallyTrimHTML(<<<EOT
202<div class="il-card thumbnail">
203
204 <div class="il-card-repository-head">
205 <div>
206
207 </div>
208 <div>
209 <img class="icon cert medium" src="./templates/default/images/icon_cert.svg" alt="Certificate" />
210 </div>
211 <div class="il-card-repository-dropdown">
212
213 </div>
214 </div>
215 <div class="il-card-image-container"><img src="src" class="img-standard" alt="open Card Title" /></div>
216 <div class="card-no-highlight"></div>
217 <div class="caption card-title">Card Title</div>
218</div>
219EOT);
220
221 $this->assertHTMLEquals($expected_html, $html);
222 }
223
224 public function test_render_with_progressmeter(): void
225 {
226 $r = $this->getDefaultRenderer();
227 $c = $this->getBaseCard();
228 $prg = new I\Component\Chart\ProgressMeter\Mini(100, 80);
229 $c = $c->withProgress($prg);
230
231 $html = $this->brutallyTrimHTML($r->render($c));
232
233 $expected_html = $this->brutallyTrimHTML('
234 <div class="il-card thumbnail">
235 <div class="il-card-repository-head">
236 <div></div>
237 <div>
238 <div class="il-chart-progressmeter-box il-chart-progressmeter-mini">
239 <div class="il-chart-progressmeter-container">
240 <svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">
241 <path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" 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>
242 <path class="il-chart-progressmeter-circle no-success" stroke-dasharray="69.2, 100" 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>
243 <path class="il-chart-progressmeter-needle no-needle" stroke-dasharray="100, 100" d="M25,10 l0,15" style="transform: rotate(deg)"></path>
244 </svg>
245 </div>
246 </div>
247 </div>
248 <div class="il-card-repository-dropdown"></div>
249 </div>
250 <div class="il-card-image-container"><img src="src" class="img-standard" alt="open Card Title"/></div>
251 <div class="card-no-highlight"></div>
252 <div class="caption card-title">Card Title</div>
253 </div>');
254
255 $this->assertHTMLEquals($expected_html, $html);
256 }
257
258 public function test_render_with_actions(): void
259 {
260 $r = $this->getDefaultRenderer();
261 $c = $this->getBaseCard();
262 $items = array(
263 new I\Component\Button\Shy("Visit ILIAS", "https://www.ilias.de")
264 );
265 $dropdown = new I\Component\Dropdown\Standard($items);
266 $c = $c->withActions($dropdown);
267 $html = $this->brutallyTrimHTML($r->render($c));
268
269 $expected_html = $this->brutallyTrimHTML('
270 <div class="il-card thumbnail">
271 <div class="il-card-repository-head">
272 <div></div>
273 <div></div>
274 <div class="il-card-repository-dropdown">
275 <div class="dropdown">
276 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="id_3" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu"><span class="caret"></span></button>
277 <ul id="id_3_menu" class="dropdown-menu">
278 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_2">Visit ILIAS</button></li>
279 </ul>
280 </div>
281 </div>
282 </div>
283 <div class="il-card-image-container"><img src="src" class="img-standard" alt="open Card Title" /></div>
284 <div class="card-no-highlight"></div>
285 <div class="caption card-title">Card Title</div>
286 </div>
287 ');
288
289 $this->assertHTMLEquals($expected_html, $html);
290 }
291}
Implementation of factory for cards.
Definition: Factory.php:32
Provides common functionality for UI tests.
Definition: Base.php:299
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Test on Repository Object card implementation.
Title class.
Definition: Title.php:27
$c
Definition: cli.php:38
$factory
Definition: metadata.php:75
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...