ILIAS  release_8 Revision v8.24
IconTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
27
32{
33 public const ICON_PATH = __DIR__ . '/../../../../../templates/default/images/';
34 public const ICON_PATH_REL = './templates/default/images/';
35
36 private function getIconFactory(): I\Component\Symbol\Icon\Factory
37 {
38 return new I\Component\Symbol\Icon\Factory();
39 }
40
41 public function testConstruction(): void
42 {
43 $f = $this->getIconFactory();
44 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Icon\\Factory", $f);
45
46 $si = $f->standard('course', 'Kurs');
47 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Icon\\Standard", $si);
48
49 $ci = $f->custom('course', 'Kurs');
50 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Icon\\Custom", $ci);
51 }
52
53 public function testAttributes(): void
54 {
55 $f = $this->getIconFactory();
56
57 $ico = $f->standard('course', 'Kurs');
58 $this->assertEquals('Kurs', $ico->getLabel());
59 $this->assertEquals('course', $ico->getName());
60 $this->assertEquals('small', $ico->getSize());
61 $this->assertEquals(false, $ico->isDisabled());
62
63 $this->assertNull($ico->getAbbreviation());
64
65 $ico = $ico->withAbbreviation('K');
66 $this->assertEquals('K', $ico->getAbbreviation());
67 }
68
69 public function testSizeModification(): void
70 {
71 $f = $this->getIconFactory();
72 $ico = $f->standard('course', 'Kurs');
73
74 $ico = $ico->withSize('medium');
75 $this->assertEquals('medium', $ico->getSize());
76
77 $ico = $ico->withSize('large');
78 $this->assertEquals('large', $ico->getSize());
79
80 $ico = $ico->withSize('small');
81 $this->assertEquals('small', $ico->getSize());
82 }
83
84 public function testSizeModificationWrongParam(): void
85 {
86 try {
87 $f = $this->getIconFactory();
88 $ico = $f->standard('course', 'Kurs');
89 $ico->withSize('tiny');
90 $this->assertFalse("This should not happen");
91 } catch (InvalidArgumentException $e) {
92 $this->assertTrue(true);
93 }
94 }
95
96 public function testDisabledModification(): void
97 {
98 $f = $this->getIconFactory();
99 $ico = $f->standard('course', 'Kurs');
100
101 $ico = $ico->withDisabled(false);
102 $this->assertEquals(false, $ico->isDisabled());
103
104 $ico = $ico->withDisabled(true);
105 $this->assertEquals(true, $ico->isDisabled());
106 }
107
109 {
110 $f = $this->getIconFactory();
111 $ico = $f->standard('course', 'Kurs');
112 $this->expectException(TypeError::class);
113 $ico->withDisabled('true');
114 }
115
116 public function testCustomPath(): void
117 {
118 $f = $this->getIconFactory();
119
120 $ico = $f->custom('/some/path/', 'Custom Icon');
121 $this->assertEquals('/some/path/', $ico->getIconPath());
122 }
123
125 {
126 $ico = $this->getIconFactory()->standard('crs', 'Course', 'medium');
127 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
128 $path = self::ICON_PATH_REL . 'icon_crs.svg';
129 $expected = "<img class=\"icon crs medium\" src=\"$path\" alt=\"Course\"/>";
130 $this->assertEquals($expected, $html);
131 return $ico;
132 }
133
137 public function testRenderingStandardDisabled(Standard $ico): void
138 {
139 $ico = $ico->withDisabled(true);
140 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
141 $path = self::ICON_PATH_REL . 'icon_crs.svg';
142 $expected = "<img class=\"icon crs medium disabled\" src=\"$path\" alt=\"Course\" aria-disabled=\"true\"/>";
143 $this->assertEquals($expected, $html);
144 }
145
149 public function testRenderingStandardAbbreviation(Standard $ico): void
150 {
151 $ico = $ico->withAbbreviation('CRS');
152 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
153 $expected = <<<imgtag
154<img class="icon crs medium" src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDMyMCAzMj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DUwLjZsLTM5LjksODYuOWMtMS43LDMuOC0wLjEsOC4yLDMuNyw5LjljMSwwLjUsMi4xLDAuNywzLjEsMC43DQoJCQljMi44LDAsNS42LTEuNiw2LjgtNC40bDE3LjUtMzguMWgxMDYuM2wxNy41LDM4LjFjMS4zLDIuOCw0LDQuNCw2LjgsNC40YzEsMCwyLjEtMC4yLDMuMS0wLjdjMy44LTEuNyw1LjQtNi4yLDMuNy05LjlMMjA0LjQsMTgwDQoJCQlIMjU1QzI2MC41LDE4MCwyNjUsMTc1LjUsMjY1LDE3MCIvPg0KCTwvZz4NCjwvZz4NCjxyZWN0IGNsYXNzPSJzdDEiIHdpZHRoPSIzMjAiIGhlaWdodD0iMzIwIi8+DQo8dGV4dAogICBzdHlsZT0iCiAgICAgIGZvbnQtc3R5bGU6bm9ybWFsOwogICAgICBmb250LXdlaWdodDpub3JtYWw7CiAgICAgIGZvbnQtc2l6ZTo4cmVtOwogICAgICBmb250LWZhbWlseTpzYW5zLXNlcmlmOwogICAgICBsZXR0ZXItc3BhY2luZzowcHg7CiAgICAgIGZpbGw6IzAwMDsKICAgICAgZmlsbC1vcGFjaXR5OjE7CiAgICAiCiAgICB4PSI1MCUiCiAgICB5PSI1NSUiCiAgICBkb21pbmFudC1iYXNlbGluZT0ibWlkZGxlIgogICAgdGV4dC1hbmNob3I9Im1pZGRsZSIKICA+Q1JTPC90ZXh0Pjwvc3ZnPg==" alt="Course" data-abbreviation="CRS"/>
155imgtag;
156 $this->assertEquals(trim($expected), trim($html));
157 }
158
159 public function testRenderingCustom(): Custom
160 {
161 $path = './templates/default/images/icon_fold.svg';
162 $ico = $this->getIconFactory()->custom($path, 'Custom', 'medium');
163 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
164 $expected = '<img class="icon custom medium" src="./templates/default/images/icon_fold.svg" alt="Custom"/>';
165 $this->assertEquals($expected, $html);
166 return $ico;
167 }
168
169 public function testAllStandardIconsExist(): void
170 {
171 $f = $this->getIconFactory();
172 $default_icons_abr = $f->standard("nothing", "nothing")->getAllStandardHandles();
173
174 foreach ($default_icons_abr as $icon_abr) {
175 $path = self::ICON_PATH . "icon_" . $icon_abr . ".svg";
176 $this->assertTrue(file_exists($path), "Missing Standard Icon: " . $path);
177 }
178 }
179
183 public function testRenderingStandardJSBindable($ico): void
184 {
185 $ico = $ico->withAdditionalOnLoadCode(function ($id) {
186 return 'alert();';
187 });
188 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
189 $path = self::ICON_PATH_REL . 'icon_crs.svg';
190 $expected = "<img aria-disabled=\"true\"/>";
191 $expected = $this->normalizeHTML("<img id=\"id_1\" class=\"icon crs medium\" src=\"$path\" alt=\"Course\"/>");
192 $this->assertEquals($expected, $html);
193 }
194
195 public function testSetCustomLabel(): Custom
196 {
197 $path = './templates/default/images/icon_fold.svg';
198 $ico = $this->getIconFactory()->custom($path, 'Custom', 'medium');
199 $ico->setLabel("New Custom Icon Label");
200 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
201 $expected = '<img class="icon custom medium" src="./templates/default/images/icon_fold.svg" alt="New Custom Icon Label"/>';
202 $this->assertEquals($expected, $html);
203
204 return $ico;
205 }
206
207 public function testHTMLInName(): void
208 {
209 $ico = $this->getIconFactory()->standard('<h1>name</h1>', 'label');
210 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
211 $expected = '<img class="icon &lt;h1&gt;name&lt;/h1&gt; small" src="./templates/default/images/icon_default.svg" alt="label"/>';
212 $this->assertEquals($expected, $html);
213 }
214
215 public function testHTMLInLabel(): void
216 {
217 $ico = $this->getIconFactory()->standard('name', '<h1>label</h1>');
218 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
219 $expected = '<img class="icon name small" src="./templates/default/images/icon_default.svg" alt="&lt;h1&gt;label&lt;/h1&gt;"/>';
220 $this->assertEquals($expected, $html);
221 }
222
226 public function testHTMLInAbbreviation(): void
227 {
228 $ico = $this->getIconFactory()->standard('name', 'label')->withAbbreviation('<h1>abbreviation</h1>');
229 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
230 $expected = '<img class="icon name small" src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDMyMCAzMjAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyMCAzMjA7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+DQoJLnN0MHtjbGlwLXBhdGg6dXJsKCNTVkdJRF8wMDAwMDA0Nzc1MTgzNzAxNzcyMjkwMzQ5MDAwMDAwOTM5MjQyNjM5Mzc4Mzc4Mzg1N18pO2ZpbGw6IzRDNjU4Njt9DQo8L3N0eWxlPg0KPGc+DQoJPGc+DQoJCTxkZWZzPg0KCQkJPHJlY3QgaWQ9IlNWR0lEXzFfIiB3aWR0aD0iMzIwIiBoZWlnaHQ9IjMyMCIvPg0KCQk8L2RlZnM+DQoJCTxjbGlwUGF0aCBpZD0iU1ZHSURfMDAwMDAxNjU5Mjc3Njk0MzI5ODM0MDA2OTAwMDAwMTQyOTU5NjQxMjMxNjc4OTQ5MjBfIj4NCgkJCTx1c2UgeGxpbms6aHJlZj0iI1NWR0lEXzFfIiAgc3R5bGU9Im92ZXJmbG93OnZpc2libGU7Ii8+DQoJCTwvY2xpcFBhdGg+DQoJCTxwYXRoIHN0eWxlPSJjbGlwLXBhdGg6dXJsKCNTVkdJRF8wMDAwMDE2NTkyNzc2OTQzMjk4MzQwMDY5MDAwMDAxNDI5NTk2NDEyMzE2Nzg5NDkyMF8pO2ZpbGw6IzRDNjU4NjsiIGQ9Ik05MCw1MEg2MA0KCQkJYy01LjUsMC0xMCw0LjUtMTAsMTB2MjAwYzAsNS41LDQuNSwxMCwxMCwxMGgzMHYtMTVINjVWNjVoMjVWNTB6IE0yNzAsMjYwVjYwYzAtNS41LTQuNS0xMC0xMC0xMGgtMzB2MTVoMjV2MTkwaC0yNXYxNWgzMA0KCQkJQzI2NS41LDI3MCwyNzAsMjY1LjUsMjcwLDI2MCIvPg0KCTwvZz4NCjwvZz4NCjx0ZXh0CiAgIHN0eWxlPSIKICAgICAgZm9udC1zdHlsZTpub3JtYWw7CiAgICAgIGZvbnQtd2VpZ2h0Om5vcm1hbDsKICAgICAgZm9udC1zaXplOjhyZW07CiAgICAgIGZvbnQtZmFtaWx5OnNhbnMtc2VyaWY7CiAgICAgIGxldHRlci1zcGFjaW5nOjBweDsKICAgICAgZmlsbDojMDAwOwogICAgICBmaWxsLW9wYWNpdHk6MTsKICAgICIKICAgIHg9IjUwJSIKICAgIHk9IjU1JSIKICAgIGRvbWluYW50LWJhc2VsaW5lPSJtaWRkbGUiCiAgICB0ZXh0LWFuY2hvcj0ibWlkZGxlIgogID4mbHQ7aDEmZ3Q7YWJicmV2aWF0aW9uJmx0Oy9oMSZndDs8L3RleHQ+PC9zdmc+" alt="label" data-abbreviation="&lt;h1&gt;abbreviation&lt;/h1&gt;"/>';
231 $this->assertEquals($expected, $html);
232 }
233
234 public function testHTMLInCustomImage(): void
235 {
236 $ico = $this->getIconFactory()->custom('<h1>path</h1>', 'label');
237 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
238 $expected = '<img class="icon custom small" src="&lt;h1&gt;path&lt;/h1&gt;" alt="label"/>';
239 $this->assertEquals($expected, $html);
240 }
241}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides common functionality for UI tests.
Definition: Base.php:299
normalizeHTML(string $html)
Definition: Base.php:422
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 icon implementation.
Definition: IconTest.php:32
testRenderingStandardJSBindable($ico)
@depends testRenderingStandard
Definition: IconTest.php:183
testRenderingStandard()
Definition: IconTest.php:124
testRenderingStandardDisabled(Standard $ico)
@depends testRenderingStandard
Definition: IconTest.php:137
testSizeModificationWrongParam()
Definition: IconTest.php:84
testHTMLInCustomImage()
Definition: IconTest.php:234
testSizeModification()
Definition: IconTest.php:69
testCustomPath()
Definition: IconTest.php:116
testAttributes()
Definition: IconTest.php:53
const ICON_PATH_REL
Definition: IconTest.php:34
getIconFactory()
Definition: IconTest.php:36
testSetCustomLabel()
Definition: IconTest.php:195
const ICON_PATH
Definition: IconTest.php:33
testRenderingCustom()
Definition: IconTest.php:159
testRenderingStandardAbbreviation(Standard $ico)
@depends testRenderingStandard
Definition: IconTest.php:149
testHTMLInLabel()
Definition: IconTest.php:215
testHTMLInAbbreviation()
@depends testRenderingStandard
Definition: IconTest.php:226
testHTMLInName()
Definition: IconTest.php:207
testConstruction()
Definition: IconTest.php:41
testDisabledModification()
Definition: IconTest.php:96
testAllStandardIconsExist()
Definition: IconTest.php:169
testDisabledModificationWrongParam()
Definition: IconTest.php:108
This describes the behavior of an custom icon.
Definition: Custom.php:27
withAbbreviation(string $abbreviation)
Set the abbreviation for this icon.
withDisabled(bool $is_disabled)
Get an icon like this, but marked as disabled.
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:27
$path
Definition: ltiservices.php:32
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...