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