ILIAS  release_8 Revision v8.24
ItemTest.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
26use ILIAS\Data;
29
34{
35 public function getFactory(): C\Item\Factory
36 {
37 return new I\Component\Item\Factory();
38 }
39
40 public function test_implements_factory_interface(): void
41 {
42 $f = $this->getFactory();
43
44 $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Standard", $f->standard("title"));
45 }
46
47 public function test_get_title(): void
48 {
49 $f = $this->getFactory();
50 $c = $f->standard("title");
51
52 $this->assertEquals("title", $c->getTitle());
53 }
54
55 public function test_with_description(): void
56 {
57 $f = $this->getFactory();
58
59 $c = $f->standard("title")->withDescription("description");
60
61 $this->assertEquals("description", $c->getDescription());
62 }
63
64 public function test_with_properties(): void
65 {
66 $f = $this->getFactory();
67
68 $props = array("prop1" => "val1", "prop2" => "val2");
69 $c = $f->standard("title")->withProperties($props);
70
71 $this->assertEquals($c->getProperties(), $props);
72 }
73
74 public function test_with_progress(): void
75 {
76 $f = $this->getFactory();
77 $chart = new I\Component\Chart\ProgressMeter\ProgressMeter(100, 50);
78
79 $c = $f->standard("title")->withProgress($chart);
80
81 $this->assertEquals($c->getProgress(), $chart);
82 }
83
84 public function test_with_actions(): void
85 {
86 $f = $this->getFactory();
87
88 $actions = new I\Component\Dropdown\Standard(array(
89 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
90 new I\Component\Button\Shy("GitHub", "https://www.github.com")
91 ));
92 $c = $f->standard("title")->withActions($actions);
93
94 $this->assertEquals($c->getActions(), $actions);
95 }
96
97 public function test_with_color(): void
98 {
99 $f = $this->getFactory();
100 $df = new Data\Factory();
101
102 $color = $df->color('#ff00ff');
103
104 $c = $f->standard("title")->withColor($color);
105
106 $this->assertEquals($c->getColor(), $color);
107 }
108
109 public function test_with_lead_image(): void
110 {
111 $f = $this->getFactory();
112
113 $image = new I\Component\Image\Image("standard", "src", "str");
114
115 $c = $f->standard("title")->withLeadImage($image);
116
117 $this->assertEquals($c->getLead(), $image);
118 }
119
120 public function test_with_lead_icon(): void
121 {
122 $f = $this->getFactory();
123
124 $icon = new I\Component\Symbol\Icon\Standard("name", "aria_label", "small", false);
125
126 $c = $f->standard("title")->withLeadIcon($icon);
127
128 $this->assertEquals($icon, $c->getLead());
129 }
130
131 public function test_with_lead_letter_avatar(): void
132 {
133 $f = $this->getFactory();
134
135 $avatar = new Letter('il');
136
137 $c = $f->standard("title")->withLeadAvatar($avatar);
138
139 $this->assertEquals($avatar, $c->getLead());
140 }
141
142 public function test_with_lead_picture_avatar(): void
143 {
144 $f = $this->getFactory();
145
146 $avatar = new Picture('./templates/default/images/no_photo_xsmall.jpg', 'demo.user');
147
148 $c = $f->standard("title")->withLeadAvatar($avatar);
149
150 $this->assertEquals($avatar, $c->getLead());
151 }
152
153 public function test_with_lead_text(): void
154 {
155 $f = $this->getFactory();
156
157 $c = $f->standard("title")->withLeadText("text");
158
159 $this->assertEquals("text", $c->getLead());
160 }
161
162 public function test_with_no_lead(): void
163 {
164 $f = $this->getFactory();
165
166 $c = $f->standard("title")->withLeadText("text")->withNoLead();
167
168 $this->assertEquals(null, $c->getLead());
169 }
170
171 public function test_with_audio_player(): void
172 {
173 $f = $this->getFactory();
174
175 $audio = new I\Component\Player\Audio("src", "transcript");
176 $c = $f->standard("title")->withAudioPlayer($audio);
177
178 $this->assertEquals($c->getAudioPlayer(), $audio);
179 }
180
181 public function test_render_base(): void
182 {
183 $f = $this->getFactory();
184 $r = $this->getDefaultRenderer();
185
186 $actions = new I\Component\Dropdown\Standard(array(
187 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
188 new I\Component\Button\Shy("GitHub", "https://www.github.com")
189 ));
190 $c = $f->standard("Item Title")
191 ->withActions($actions)
192 ->withProperties(array(
193 "Origin" => "Course Title 1",
194 "Last Update" => "24.11.2011",
195 "Location" => "Room 123, Main Street 44, 3012 Bern"))
196 ->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.");
197
198 $html = $r->render($c);
199
200 $expected = <<<EOT
201 <div class="il-item il-std-item ">
202 <div class="il-item-title">Item Title</div>
203 <div class="dropdown"><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>
204 <ul id="id_3_menu" class="dropdown-menu">
205 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1" >ILIAS</button>
206 </li>
207 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2" >GitHub</button>
208 </li>
209 </ul>
210 </div>
211 <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>
212 <hr class="il-item-divider" />
213 <div class="row">
214 <div class="col-md-6 il-multi-line-cap-3">
215 <span class="il-item-property-name">Origin</span><span class="il-item-property-value">Course Title 1</span>
216 </div>
217 <div class="col-md-6 il-multi-line-cap-3">
218 <span class="il-item-property-name">Last Update</span><span class="il-item-property-value">24.11.2011</span>
219 </div>
220 </div>
221 <div class="row">
222 <div class="col-md-6 il-multi-line-cap-3">
223 <span class="il-item-property-name">Location</span><span class="il-item-property-value">Room 123, Main Street 44, 3012 Bern</span>
224 </div>
225 <div class="col-md-6 il-multi-line-cap-3">
226 <span class="il-item-property-name"></span><span class="il-item-property-value"></span>
227 </div>
228 </div>
229 </div>
230EOT;
231
232 $this->assertHTMLEquals(
233 $this->brutallyTrimHTML($expected),
234 $this->brutallyTrimHTML($html)
235 );
236 }
237
238 public function test_render_lead_image(): void
239 {
240 $f = $this->getFactory();
241 $r = $this->getDefaultRenderer();
242
243 $image = new I\Component\Image\Image("standard", "src", "str");
244
245 $c = $f->standard("title")->withLeadImage($image);
246
247 $html = $r->render($c);
248 $expected = <<<EOT
249<div class="il-item il-std-item ">
250 <div class="row">
251 <div class="col-xs-2 col-sm-3">
252 <img src="src" class="img-standard" alt="str" />
253 </div>
254 <div class="col-xs-10 col-sm-9">
255 <div class="il-item-title">title</div>
256 </div>
257 </div>
258</div>
259EOT;
260
261 $this->assertHTMLEquals(
262 $this->brutallyTrimHTML($expected),
263 $this->brutallyTrimHTML($html)
264 );
265 }
266
267 public function test_render_lead_icon(): void
268 {
269 $f = $this->getFactory();
270 $r = $this->getDefaultRenderer();
271
272 $icon = new I\Component\Symbol\Icon\Standard("name", "aria_label", "small", false);
273
274 $c = $f->standard("title")->withLeadIcon($icon);
275
276 $html = $r->render($c);
277 $expected = <<<EOT
278<div class="il-item il-std-item ">
279 <div class="media">
280 <div class="media-left">
281 <img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label" />
282 </div>
283 <div class="media-body">
284 <div class="il-item-title">title</div>
285 </div>
286 </div>
287</div>
288EOT;
289
290 $this->assertHTMLEquals(
291 $this->brutallyTrimHTML($expected),
292 $this->brutallyTrimHTML($html)
293 );
294 }
295
296 public function test_render_lead_letter_avatar(): void
297 {
298 $f = $this->getFactory();
299 $r = $this->getDefaultRenderer();
300
301 $avatar = new Letter('il');
302
303 $c = $f->standard("title")->withLeadAvatar($avatar);
304
305 $html = $r->render($c);
306
307 $expected = <<<EOT
308<div class="il-item il-std-item ">
309 <div class="media">
310 <div class="media-left">
311 <span class="il-avatar il-avatar-letter il-avatar-size-large il-avatar-letter-color-11" aria-label="user_avatar" role="img">
312 <span class="abbreviation">il</span>
313 </span>
314 </div>
315 <div class="media-body">
316 <div class="il-item-title">title</div>
317 </div>
318 </div>
319</div>
320EOT;
321
322 $this->assertHTMLEquals(
323 $this->brutallyTrimHTML($expected),
324 $this->brutallyTrimHTML($html)
325 );
326 }
327
328 public function test_render_lead_picture_avatar(): void
329 {
330 $f = $this->getFactory();
331 $r = $this->getDefaultRenderer();
332
333 $avatar = new Picture('./templates/default/images/no_photo_xsmall.jpg', 'demo.user');
334
335 $c = $f->standard("title")->withLeadAvatar($avatar);
336
337 $html = $r->render($c);
338 $expected = <<<EOT
339<div class="il-item il-std-item ">
340 <div class="media">
341 <div class="media-left">
342 <span class="il-avatar il-avatar-picture il-avatar-size-large">
343 <img src="./templates/default/images/no_photo_xsmall.jpg" alt="user_avatar"/>
344 </span>
345 </div>
346 <div class="media-body">
347 <div class="il-item-title">title</div>
348 </div>
349 </div>
350</div>
351EOT;
352
353 $this->assertHTMLEquals(
354 $this->brutallyTrimHTML($expected),
355 $this->brutallyTrimHTML($html)
356 );
357 }
358
359 public function test_render_progress(): void
360 {
361 $f = $this->getFactory();
362 $r = $this->getDefaultRenderer();
363
364 $chart = new I\Component\Chart\ProgressMeter\Standard(100, 75);
365
366 $c = $f->standard("title")->withProgress($chart);
367
368 $html = $r->render($c);
369 $expected = <<<EOT
370<div class="il-item il-std-item ">
371 <div class="row">
372 <div class="col-sm-9">
373 <div class="il-item-title">title</div>
374 </div>
375 <div class="col-xs-3 col-sm-2 col-lg-2">
376 <div class="il-chart-progressmeter-box ">
377 <div class="il-chart-progressmeter-container">
378 <svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">
379 <path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" d="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>
380 <g class="il-chart-progressmeter-monocircle">
381 <path class="il-chart-progressmeter-circle no-success" stroke-dasharray="75, 100" d="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>
382 </g>
383 <g class="il-chart-progressmeter-text">
384 <text class="text-score-info" x="25" y="16"></text>
385 <text class="text-score" x="25" y="25">75 %</text>
386 <text class="text-comparision" x="25" y="31"></text>
387 <text class="text-comparision-info" x="25" y="34"></text>
388 </g>
389 <g class="il-chart-progressmeter-needle no-needle" style="transform: rotate(deg)">
390 <polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>
391 <polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>
392 </g>
393 </svg>
394 </div>
395 </div>
396 </div>
397 </div>
398</div>
399EOT;
400
401 $this->assertHTMLEquals(
402 $this->brutallyTrimHTML($expected),
403 $this->brutallyTrimHTML($html)
404 );
405 }
406
408 {
409 $f = $this->getFactory();
410 $r = $this->getDefaultRenderer();
411
412 $image = new I\Component\Image\Image("standard", "src", "str");
413 $chart = new I\Component\Chart\ProgressMeter\Standard(100, 75);
414
415 $c = $f->standard("title")->withLeadImage($image)->withProgress($chart);
416
417 $html = $r->render($c);
418 $expected = <<<EOT
419<div class="il-item il-std-item ">
420 <div class="row">
421 <div class="col-xs-3 col-sm-3 col-lg-2">
422 <img src="src" class="img-standard" alt="str" />
423 </div>
424 <div class="col-xs-6 col-sm-7 col-lg-8">
425 <div class="il-item-title">title</div>
426 </div>
427 <div class="col-xs-3 col-sm-2 col-lg-2">
428 <div class="il-chart-progressmeter-box ">
429 <div class="il-chart-progressmeter-container">
430 <svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">
431 <path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" d="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>
432 <g class="il-chart-progressmeter-monocircle">
433 <path class="il-chart-progressmeter-circle no-success" stroke-dasharray="75, 100" d="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>
434 </g>
435 <g class="il-chart-progressmeter-text">
436 <text class="text-score-info" x="25" y="16"></text>
437 <text class="text-score" x="25" y="25">75 %</text>
438 <text class="text-comparision" x="25" y="31"></text>
439 <text class="text-comparision-info" x="25" y="34"></text>
440 </g>
441 <g class="il-chart-progressmeter-needle no-needle" style="transform: rotate(deg)">
442 <polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>
443 <polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>
444 </g>
445 </svg>
446 </div>
447 </div>
448 </div>
449 </div>
450</div>
451EOT;
452
453 $this->assertHTMLEquals(
454 $this->brutallyTrimHTML($expected),
455 $this->brutallyTrimHTML($html)
456 );
457 }
458
460 {
461 $f = $this->getFactory();
462 $r = $this->getDefaultRenderer();
463
464 $icon = new I\Component\Symbol\Icon\Standard("name", "aria_label", "small", false);
465 $chart = new I\Component\Chart\ProgressMeter\Standard(100, 75);
466
467 $c = $f->standard("title")->withLeadIcon($icon)->withProgress($chart);
468
469 $html = $r->render($c);
470 $expected = <<<EOT
471<div class="il-item il-std-item ">
472 <div class="media">
473 <div class="media-left">
474 <img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label" />
475 </div>
476 <div class="media-body">
477 <div class="il-item-title">title</div>
478 </div>
479 <div class="media-right">
480 <div class="il-chart-progressmeter-box ">
481 <div class="il-chart-progressmeter-container">
482 <svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">
483 <path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" d="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>
484 <g class="il-chart-progressmeter-monocircle">
485 <path class="il-chart-progressmeter-circle no-success" stroke-dasharray="75, 100" d="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>
486 </g>
487 <g class="il-chart-progressmeter-text">
488 <text class="text-score-info" x="25" y="16"></text>
489 <text class="text-score" x="25" y="25">75 %</text>
490 <text class="text-comparision" x="25" y="31"></text>
491 <text class="text-comparision-info" x="25" y="34"></text>
492 </g>
493 <g class="il-chart-progressmeter-needle no-needle" style="transform: rotate(deg)">
494 <polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>
495 <polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>
496 </g>
497 </svg>
498 </div>
499 </div>
500 </div>
501 </div>
502</div>
503EOT;
504
505 $this->assertHTMLEquals(
506 $this->brutallyTrimHTML($expected),
507 $this->brutallyTrimHTML($html)
508 );
509 }
510
511 public function test_render_lead_text_and_color(): void
512 {
513 $f = $this->getFactory();
514 $r = $this->getDefaultRenderer();
515 $df = new Data\Factory();
516
517 $color = $df->color('#ff00ff');
518
519 $c = $f->standard("title")->withColor($color)->withLeadText("lead");
520
521 $html = $r->render($c);
522
523 $expected = <<<EOT
524<div class="il-item il-std-item il-item-marker " style="border-color:#ff00ff">
525 <div class="row">
526 <div class="col-sm-3">
527 lead
528 </div>
529 <div class="col-sm-9">
530 <div class="il-item-title">title</div>
531 </div>
532 </div>
533</div>
534EOT;
535
536 $this->assertHTMLEquals(
537 $this->brutallyTrimHTML($expected),
538 $this->brutallyTrimHTML($html)
539 );
540 }
541
543 {
544 $f = $this->getFactory();
545 $r = $this->getDefaultRenderer();
546 $df = new Data\Factory();
547
548 $df->color('#ff00ff');
549
550 $c = $f->standard(new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"))
551 ->withProperties([
552 "Property Text" => "Text",
553 "Property HTML" => "<a>Link</a>",
554 "Property Shy" => new I\Component\Button\Shy("GitHub", "https://www.github.com"),
555 "Property Icon" => new I\Component\Symbol\Icon\Standard("name", "aria_label", "small", false)
556 ]);
557
558 $html = $this->brutallyTrimHTML($r->render($c));
559 $expected = $this->brutallyTrimHTML(<<<EOT
560<div class="il-item il-std-item ">
561 <div class="il-item-title"><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></div>
562 <hr class="il-item-divider" />
563 <div class="row">
564 <div class="col-md-6 il-multi-line-cap-3"><span class="il-item-property-name">Property Text</span><span class="il-item-property-value">Text</span></div>
565 <div class="col-md-6 il-multi-line-cap-3"><span class="il-item-property-name">Property HTML</span><span class="il-item-property-value"><a>Link</a></span></div>
566 </div>
567 <div class="row">
568 <div class="col-md-6 il-multi-line-cap-3"><span class="il-item-property-name">Property Shy</span><span class="il-item-property-value"><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></span></div>
569 <div class="col-md-6 il-multi-line-cap-3"><span class="il-item-property-name">Property Icon</span><span class="il-item-property-value"><img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label"/></span></div>
570 </div>
571</div>
572EOT);
573
574 $this->assertEquals($expected, $html);
575 }
576
577 public function test_link_title(): void
578 {
579 $f = $this->getFactory();
580 $r = $this->getDefaultRenderer();
581
582 $c = $f->standard(new I\Component\Link\Standard("ILIAS", "https://www.ilias.de"));
583 $html = $r->render($c);
584
585 $expected = <<<EOT
586<div class="il-item il-std-item "><div class="il-item-title"><a href="https://www.ilias.de">ILIAS</a></div></div>
587EOT;
588
589 $this->assertHTMLEquals($expected, $html);
590 }
591
592 public function test_render_audio_player(): void
593 {
594 $f = $this->getFactory();
595 $r = $this->getDefaultRenderer();
596
597 $audio = new I\Component\Player\Audio("src", "");
598 $c = $f->standard("title")->withAudioPlayer($audio);
599
600 $html = $r->render($c);
601 $expected = <<<EOT
602<div class="il-item il-std-item ">
603 <div class="il-item-title">title</div>
604 <div class="il-item-audio"><div class="il-audio-container">
605 <audio class="il-audio-player" id="id_1" src="src" preload="metadata"></audio>
606</div></div>
607</div>
608EOT;
609 $this->assertHTMLEquals(
610 $this->brutallyTrimHTML($expected),
611 $this->brutallyTrimHTML($html)
612 );
613 }
614}
Builds data types.
Definition: Factory.php:21
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
ILIAS base class perform basic setup: init database handler, load configuration file,...
Definition: class.ilias.php:15
Test items.
Definition: ItemTest.php:34
test_with_properties()
Definition: ItemTest.php:64
test_get_title()
Definition: ItemTest.php:47
test_with_progress()
Definition: ItemTest.php:74
test_render_lead_letter_avatar()
Definition: ItemTest.php:296
test_render_lead_text_and_color()
Definition: ItemTest.php:511
test_render_lead_image()
Definition: ItemTest.php:238
test_with_lead_text()
Definition: ItemTest.php:153
test_shy_title_and_various_properties()
Definition: ItemTest.php:542
test_with_no_lead()
Definition: ItemTest.php:162
test_with_audio_player()
Definition: ItemTest.php:171
test_render_lead_picture_avatar()
Definition: ItemTest.php:328
test_implements_factory_interface()
Definition: ItemTest.php:40
test_with_lead_icon()
Definition: ItemTest.php:120
getFactory()
Definition: ItemTest.php:35
test_render_progress_and_lead_image()
Definition: ItemTest.php:407
test_render_progress_and_lead_icon()
Definition: ItemTest.php:459
test_render_audio_player()
Definition: ItemTest.php:592
test_with_lead_image()
Definition: ItemTest.php:109
test_with_actions()
Definition: ItemTest.php:84
test_render_lead_icon()
Definition: ItemTest.php:267
test_render_progress()
Definition: ItemTest.php:359
test_link_title()
Definition: ItemTest.php:577
test_with_color()
Definition: ItemTest.php:97
test_with_lead_picture_avatar()
Definition: ItemTest.php:142
test_render_base()
Definition: ItemTest.php:181
test_with_description()
Definition: ItemTest.php:55
test_with_lead_letter_avatar()
Definition: ItemTest.php:131
Title class.
Definition: Title.php:27
$c
Definition: cli.php:38
This describes how a picture avatar could be modified during construction of UI.
Definition: Picture.php:27
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...
Class ChatMainBarProvider \MainMenu\Provider.