ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IconTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
27
32{
33 public const ICON_PATH = __DIR__ . '/../../../../../../../public/assets/images/standard/';
34 public const ICON_PATH_REL = './assets/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 . 'standard/icon_crs.svg';
129 $expected = "<img class=\"icon crs medium\" src=\"$path\" alt=\"Course\"/>";
130 $this->assertEquals($expected, $html);
131 return $ico;
132 }
133
134 #[\PHPUnit\Framework\Attributes\Depends('testRenderingStandard')]
135 public function testRenderingStandardDisabled(Standard $ico): void
136 {
137 $ico = $ico->withDisabled(true);
138 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
139 $path = self::ICON_PATH_REL . 'standard/icon_crs.svg';
140 $expected = "<img class=\"icon crs medium disabled\" src=\"$path\" alt=\"Course\" aria-disabled=\"true\"/>";
141 $this->assertEquals($expected, $html);
142 }
143
144 #[\PHPUnit\Framework\Attributes\Depends('testRenderingStandard')]
145 public function testRenderingStandardAbbreviation(Standard $ico): void
146 {
147 $ico = $ico->withAbbreviation('CRS');
148 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
149 $expected = <<<imgtag
150<img class="icon crs medium" src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG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xNzBWNTBjMC01LjUtNC41LTEwLTEwLTEwDQoJCQlINjVjLTUuNSwwLTEwLDQuNS0xMCwxMHYxMjBjMCw1LjUsNC41LDEwLDEwLDEwaDUwLjZsLTM5LjksODYuOWMtMS43LDMuOC0wLjEsOC4yLDMuNyw5LjljMSwwLjUsMi4xLDAuNywzLjEsMC43DQoJCQljMi44LDAsNS42LTEuNiw2LjgtNC40bDE3LjUtMzguMWgxMDYuM2wxNy41LDM4LjFjMS4zLDIuOCw0LDQuNCw2LjgsNC40YzEsMCwyLjEtMC4yLDMuMS0wLjdjMy44LTEuNyw1LjQtNi4yLDMuNy05LjlMMjA0LjQsMTgwDQoJCQlIMjU1QzI2MC41LDE4MCwyNjUsMTc1LjUsMjY1LDE3MCIvPg0KCTwvZz4NCjwvZz4NCjxyZWN0IGNsYXNzPSJzdDEiIHdpZHRoPSIzMjAiIGhlaWdodD0iMzIwIi8+DQo8dGV4dAogICBzdHlsZT0iCiAgICAgIGZvbnQtc3R5bGU6bm9ybWFsOwogICAgICBmb250LXdlaWdodDpub3JtYWw7CiAgICAgIGZvbnQtc2l6ZTo4cmVtOwogICAgICBmb250LWZhbWlseTpzYW5zLXNlcmlmOwogICAgICBsZXR0ZXItc3BhY2luZzowcHg7CiAgICAgIGZpbGw6IzAwMDsKICAgICAgZmlsbC1vcGFjaXR5OjE7CiAgICAiCiAgICB4PSI1MCUiCiAgICB5PSI1NSUiCiAgICBkb21pbmFudC1iYXNlbGluZT0ibWlkZGxlIgogICAgdGV4dC1hbmNob3I9Im1pZGRsZSIKICA+Q1JTPC90ZXh0Pjwvc3ZnPg==" alt="Course" data-abbreviation="CRS"/>
151imgtag;
152 $this->assertEquals(trim($expected), trim($html));
153 }
154
155 public function testRenderingCustom(): Custom
156 {
157 $path = './assets/images/standard/icon_fold.svg';
158 $ico = $this->getIconFactory()->custom($path, 'Custom', 'medium');
159 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
160 $expected = '<img class="icon custom medium" src="./assets/images/standard/icon_fold.svg" alt="Custom"/>';
161 $this->assertEquals($expected, $html);
162 return $ico;
163 }
164
165 public function testAllStandardIconsExist(): void
166 {
167 $f = $this->getIconFactory();
168 $default_icons_abr = $f->standard("nothing", "nothing")->getAllStandardHandles();
169
170 foreach ($default_icons_abr as $icon_abr) {
171 $path = self::ICON_PATH . "icon_" . $icon_abr . ".svg";
172 $this->assertTrue(file_exists($path), "Missing Standard Icon: " . $path);
173 }
174 }
175
176 #[\PHPUnit\Framework\Attributes\Depends('testRenderingStandard')]
177 public function testRenderingStandardJSBindable($ico): void
178 {
179 $ico = $ico->withAdditionalOnLoadCode(function ($id) {
180 return 'alert();';
181 });
182 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
183 $path = self::ICON_PATH_REL . 'standard/icon_crs.svg';
184 $expected = "<img aria-disabled=\"true\"/>";
185 $expected = $this->normalizeHTML("<img id=\"id_1\" class=\"icon crs medium\" src=\"$path\" alt=\"Course\"/>");
186 $this->assertEquals($expected, $html);
187 }
188
189 public function testSetCustomLabel(): Custom
190 {
191 $path = './assets/images/icon_fold.svg';
192 $ico = $this->getIconFactory()->custom($path, 'Custom', 'medium');
193 $ico->setLabel("New Custom Icon Label");
194 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
195 $expected = '<img class="icon custom medium" src="./assets/images/icon_fold.svg" alt="New Custom Icon Label"/>';
196 $this->assertEquals($expected, $html);
197
198 return $ico;
199 }
200
201 public function testHTMLInName(): void
202 {
203 $ico = $this->getIconFactory()->standard('<h1>name</h1>', 'label');
204 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
205 $expected = '<img class="icon &lt;h1&gt;name&lt;/h1&gt; small" src="./assets/images/standard/icon_default.svg" alt="label"/>';
206 $this->assertEquals($expected, $html);
207 }
208
209 public function testHTMLInLabel(): void
210 {
211 $ico = $this->getIconFactory()->standard('name', '<h1>label</h1>');
212 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
213 $expected = '<img class="icon name small" src="./assets/images/standard/icon_default.svg" alt="&lt;h1&gt;label&lt;/h1&gt;"/>';
214 $this->assertEquals($expected, $html);
215 }
216
217 #[\PHPUnit\Framework\Attributes\Depends('testRenderingStandard')]
218 public function testHTMLInAbbreviation(): void
219 {
220 $ico = $this->getIconFactory()->standard('name', 'label')->withAbbreviation('<h1>abbreviation</h1>');
221 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
222 $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;"/>';
223 $this->assertEquals($expected, $html);
224 }
225
226 public function testHTMLInCustomImage(): void
227 {
228 $ico = $this->getIconFactory()->custom('<h1>path</h1>', 'label');
229 $html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($ico));
230 $expected = '<img class="icon custom small" src="&lt;h1&gt;path&lt;/h1&gt;" alt="label"/>';
231 $this->assertEquals($expected, $html);
232 }
233}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides common functionality for UI tests.
Definition: Base.php:337
Test on icon implementation.
Definition: IconTest.php:32
testRenderingStandardJSBindable($ico)
Definition: IconTest.php:177
testRenderingStandard()
Definition: IconTest.php:124
testRenderingStandardDisabled(Standard $ico)
Definition: IconTest.php:135
testSizeModificationWrongParam()
Definition: IconTest.php:84
testHTMLInCustomImage()
Definition: IconTest.php:226
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:189
const ICON_PATH
Definition: IconTest.php:33
testRenderingCustom()
Definition: IconTest.php:155
testRenderingStandardAbbreviation(Standard $ico)
Definition: IconTest.php:145
testHTMLInLabel()
Definition: IconTest.php:209
testHTMLInAbbreviation()
Definition: IconTest.php:218
testHTMLInName()
Definition: IconTest.php:201
testConstruction()
Definition: IconTest.php:41
testDisabledModification()
Definition: IconTest.php:96
testAllStandardIconsExist()
Definition: IconTest.php:165
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:30