ILIAS  release_8 Revision v8.24
ilSystemStyleIconFolderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once('libs/composer/vendor/autoload.php');
22
24{
25 protected string $icon_name = 'test_image_1.svg';
26 protected string $icon_type = 'svg';
27
28 public function testConstruct(): void
29 {
30 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
31
32 $this->assertEquals($this->container->getImagesSkinPath($this->style->getId()), $folder->getPath());
33 }
34
35 public function testSetPath(): void
36 {
37 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
38 $folder->setPath('pathnew');
39
40 $this->assertEquals('pathnew', $folder->getPath());
41 }
42
43 public function testReadRecursiveCount(): void
44 {
45 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
46 $this->assertCount(5, $folder->getIcons());
47 }
48
49 public function testFolderDoesNotExist(): void
50 {
51 try {
52 new ilSystemStyleIconFolder('Does not exist');
53 $this->fail();
55 $this->assertEquals(ilSystemStyleIconException::IMAGES_FOLDER_DOES_NOT_EXIST, $e->getCode());
56 }
57 }
58
59 public function testFolderGetIconByName(): void
60 {
61 $style_path = $this->container->getImagesSkinPath($this->style->getId());
62
63 $path1 = $style_path . '/test_image_1.svg';
64 $icon1 = new ilSystemStyleIcon('test_image_1.svg', $path1, 'svg');
65 $folder = new ilSystemStyleIconFolder($style_path);
66 $this->assertEquals($icon1, $folder->getIconByName('test_image_1.svg'));
67 }
68
69 public function testFolderGetIconByPath(): void
70 {
71 $style_path = $this->container->getImagesSkinPath($this->style->getId());
72
73 $path1 = $style_path . '/test_image_1.svg';
74 $icon1 = new ilSystemStyleIcon('test_image_1.svg', $path1, 'svg');
75 $folder = new ilSystemStyleIconFolder($style_path);
76 $this->assertEquals($icon1, $folder->getIconByPath($path1));
77 }
78
79 public function testIconDoesNotExist(): void
80 {
81 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
82
83 try {
84 $folder->getIconByName('doesNotExist.svg');
85 $this->fail();
87 $this->assertEquals(ilSystemStyleIconException::ICON_DOES_NOT_EXIST, $e->getCode());
88 }
89 }
90
91 public function testReadRecursiveAndSortByName(): void
92 {
93 $style_path = $this->container->getImagesSkinPath($this->style->getId());
94
95 $path1 = $style_path . '/test_image_1.svg';
96 $icon1 = new ilSystemStyleIcon('test_image_1.svg', $path1, 'svg');
97
98 $path2 = $style_path . '/image_subfolder/sub_test_image_1.svg';
99 $icon2 = new ilSystemStyleIcon('sub_test_image_1.svg', $path2, 'svg');
100
101 $path3 = $style_path . '/image_subfolder/sub_test_image_2.svg';
102 $icon3 = new ilSystemStyleIcon('sub_test_image_2.svg', $path3, 'svg');
103
104 $path4 = $style_path . '/nonsvg.png';
105 $icon4 = new ilSystemStyleIcon('nonsvg.png', $path4, 'png');
106
107 $path5 = $style_path . '/icon_accs.svg';
108 $icon5 = new ilSystemStyleIcon('icon_accs.svg', $path5, 'svg');
109
110 $expected_icons = [$icon5, $icon2, $icon3, $icon1, $icon4];
111
112 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
113 $this->assertEquals($expected_icons, $folder->getIcons());
114 }
115
116 public function testReadRecursiveAndSortByFolder(): void
117 {
118 $style_path = $this->container->getImagesSkinPath($this->style->getId());
119
120 $path1 = $style_path . '/test_image_1.svg';
121 $icon1 = new ilSystemStyleIcon('test_image_1.svg', $path1, 'svg');
122
123 $path2 = $style_path . '/image_subfolder/sub_test_image_1.svg';
124 $icon2 = new ilSystemStyleIcon('sub_test_image_1.svg', $path2, 'svg');
125
126 $path3 = $style_path . '/image_subfolder/sub_test_image_2.svg';
127 $icon3 = new ilSystemStyleIcon('sub_test_image_2.svg', $path3, 'svg');
128
129 $path4 = $style_path . '/nonsvg.png';
130 $icon4 = new ilSystemStyleIcon('nonsvg.png', $path4, 'png');
131
132 $path5 = $style_path . '/icon_accs.svg';
133 $icon5 = new ilSystemStyleIcon('icon_accs.svg', $path5, 'svg');
134
135 $expected_icons = [
136 $style_path => [$icon5, $icon1, $icon4],
137 $style_path . '/image_subfolder' => [$icon2, $icon3],
138 ];
139
140 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
141 $this->assertEquals($expected_icons, $folder->getIconsSortedByFolder());
142 }
143
144 public function testExtractColorset(): void
145 {
146 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
147
148 $expected_color_set = new ilSystemStyleIconColorSet();
149 $color1 = new ilSystemStyleIconColor('id_505050', '505050', '505050', '505050');
150 $color2 = new ilSystemStyleIconColor('id_6B6B6B', '6B6B6B', '6B6B6B', '6B6B6B');
151 $color3 = new ilSystemStyleIconColor('id_838383', '838383', '838383', '838383');
152 $color4 = new ilSystemStyleIconColor('id_8C8C8C', '8C8C8C', '8C8C8C', '8C8C8C');
153 $color5 = new ilSystemStyleIconColor('id_303030', '303030', '303030', '303030');
154 $color6 = new ilSystemStyleIconColor('id_404040', '404040', '404040', '404040');
155 $color7 = new ilSystemStyleIconColor('id_000', '000', '000', '000');
156
157 $expected_color_set->addColor($color1);
158 $expected_color_set->addColor($color2);
159 $expected_color_set->addColor($color3);
160 $expected_color_set->addColor($color4);
161 $expected_color_set->addColor($color5);
162 $expected_color_set->addColor($color6);
163 $expected_color_set->addColor($color7);
164
165 $this->assertEquals($expected_color_set, $folder->getColorSet());
166 }
167
168 public function testExtractChangeColors(): void
169 {
170 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
171 $folder1->changeIconColors(['505050' => '555555']);
172
173 $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
174
175 $expected_color_set = new ilSystemStyleIconColorSet();
176 $color1 = new ilSystemStyleIconColor('id_555555', '555555', '555555', '555555');
177 $color2 = new ilSystemStyleIconColor('id_6B6B6B', '6B6B6B', '6B6B6B', '6B6B6B');
178 $color3 = new ilSystemStyleIconColor('id_838383', '838383', '838383', '838383');
179 $color4 = new ilSystemStyleIconColor('id_8C8C8C', '8C8C8C', '8C8C8C', '8C8C8C');
180 $color5 = new ilSystemStyleIconColor('id_303030', '303030', '303030', '303030');
181 $color6 = new ilSystemStyleIconColor('id_404040', '404040', '404040', '404040');
182 $color7 = new ilSystemStyleIconColor('id_000', '000', '000', '000');
183
184 $expected_color_set->addColor($color2);
185 $expected_color_set->addColor($color3);
186 $expected_color_set->addColor($color4);
187 $expected_color_set->addColor($color5);
188 $expected_color_set->addColor($color6);
189 $expected_color_set->addColor($color1);
190 $expected_color_set->addColor($color7);
191
192 $this->assertEquals($expected_color_set, $folder2->getColorSet());
193 }
194
195 public function testGetUsages(): void
196 {
197 $style_path = $this->container->getImagesSkinPath($this->style->getId());
198
199 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
200
201 $path1 = $style_path . '/test_image_1.svg';
202 $icon1 = new ilSystemStyleIcon('test_image_1.svg', $path1, 'svg');
203 $icon1->getColorSet();
204
205 $path2 = $style_path . '/image_subfolder/sub_test_image_1.svg';
206 $icon2 = new ilSystemStyleIcon('sub_test_image_1.svg', $path2, 'svg');
207 $icon2->getColorSet();
208
209 $path3 = $style_path . '/image_subfolder/sub_test_image_2.svg';
210 $icon3 = new ilSystemStyleIcon('sub_test_image_2.svg', $path3, 'svg');
211 $icon3->getColorSet();
212
213 $expected_icons_usages = [$icon2, $icon3, $icon1];
214
215 $this->assertEquals($expected_icons_usages, $folder1->getUsagesOfColor('id_6B6B6B'));
216 }
217
218 public function testGetUsagesAfterChangeColor(): void
219 {
220 $style_path = $this->container->getImagesSkinPath($this->style->getId());
221
222 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
223 $folder1->changeIconColors(['6B6B6B' => '7B6B6B']);
224
225 $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
226
227 $path1 = $style_path . '/test_image_1.svg';
228 $icon1 = new ilSystemStyleIcon('test_image_1.svg', $path1, 'svg');
229 $icon1->getColorSet();
230
231 $path2 = $style_path . '/image_subfolder/sub_test_image_1.svg';
232 $icon2 = new ilSystemStyleIcon('sub_test_image_1.svg', $path2, 'svg');
233 $icon2->getColorSet();
234
235 $path3 = $style_path . '/image_subfolder/sub_test_image_2.svg';
236 $icon3 = new ilSystemStyleIcon('sub_test_image_2.svg', $path3, 'svg');
237 $icon3->getColorSet();
238
239 $expected_icons_usages = [$icon2, $icon3, $icon1];
240
241 $this->assertEquals($expected_icons_usages, $folder2->getUsagesOfColor('id_7B6B6B'));
242 $this->assertEquals([], $folder2->getUsagesOfColor('id_6B6B6B'));
243 }
244
245 public function testGetUsagesAsString(): void
246 {
247 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
248
249 $this->assertEquals(
250 'sub_test_image_1; sub_test_image_2; test_image_1; ',
251 $folder1->getUsagesOfColorAsString('id_6B6B6B')
252 );
253 }
254}
Class for advanced editing exception handling in ILIAS.
Abstracts a folder containing a set of icons.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon.