ILIAS  release_7 Revision v7.30-3-g800a261c036
ilSystemStyleIconFolderTest.php
Go to the documentation of this file.
1<?php
2
3include_once("Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
4include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
5include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
6include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
7include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleDICMock.php");
8
9include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIcon.php");
10include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconFolder.php");
11
12use PHPUnit\Framework\TestCase;
13
19class ilSystemStyleIconFolderTest extends TestCase
20{
21
26
30 protected $container;
31
35 protected $style;
36
40 protected $icon_name = "test_image_1.svg";
41
45 protected $icon_type = "svg";
46
47 protected $save_dic = null;
48
49 protected function setUp() : void
50 {
51 global $DIC;
52
53 $this->save_dic = $DIC;
55
56 $this->system_style_config = new ilSystemStyleConfigMock();
57
58 mkdir($this->system_style_config->test_skin_temp_path);
59 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
60
61 $this->container = ilSystemStyleSkinContainer::generateFromId("skin1", null, $this->system_style_config);
62 $this->style = $this->container->getSkin()->getStyle("style1");
63 }
64
65 protected function tearDown() : void
66 {
67 global $DIC;
69
70 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
71 }
72
73 public function testConstruct()
74 {
75 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
76
77 $this->assertEquals($this->container->getImagesSkinPath($this->style->getId()), $folder->getPath());
78 }
79
80 public function testSetPath()
81 {
82 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
83 $folder->setPath("pathnew");
84
85 $this->assertEquals("pathnew", $folder->getPath());
86 }
87
88
89 public function testReadRecursiveCount()
90 {
91 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
92 $this->assertEquals(5, count($folder->getIcons()));
93 }
94
95 public function testFolderDoesNotExist()
96 {
97 try {
98 new ilSystemStyleIconFolder("Does not exist");
99 $this->assertTrue(false);
101 $this->assertEquals(ilSystemStyleIconException::IMAGES_FOLDER_DOES_NOT_EXIST, $e->getCode());
102 }
103 }
104
105 public function testFolderGetIconByName()
106 {
107 $style_path = $this->container->getImagesSkinPath($this->style->getId());
108
109 $path1 = $style_path . "/test_image_1.svg";
110 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
111 $folder = new ilSystemStyleIconFolder($style_path);
112 $this->assertEquals($icon1, $folder->getIconByName("test_image_1.svg"));
113 }
114
115 public function testFolderGetIconByPath()
116 {
117 $style_path = $this->container->getImagesSkinPath($this->style->getId());
118
119 $path1 = $style_path . "/test_image_1.svg";
120 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
121 $folder = new ilSystemStyleIconFolder($style_path);
122 $this->assertEquals($icon1, $folder->getIconByPath($path1));
123 }
124
125 public function testIconDoesNotExist()
126 {
127 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
128
129 try {
130 $folder->getIconByName("doesNotExist.svg");
131 $this->assertTrue(false);
133 $this->assertEquals(ilSystemStyleIconException::ICON_DOES_NOT_EXIST, $e->getCode());
134 }
135 }
136
138 {
139 $style_path = $this->container->getImagesSkinPath($this->style->getId());
140
141 $path1 = $style_path . "/test_image_1.svg";
142 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
143
144 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
145 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
146
147 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
148 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
149
150 $path4 = $style_path . "/nonsvg.png";
151 $icon4 = new ilSystemStyleIcon("nonsvg.png", $path4, "png");
152
153 $path5 = $style_path . "/icon_accs.svg";
154 $icon5 = new ilSystemStyleIcon("icon_accs.svg", $path5, "svg");
155
156 $expected_icons = [$icon5,$icon2,$icon3,$icon1,$icon4];
157
158 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
159 $this->assertEquals($expected_icons, $folder->getIcons());
160 }
161
163 {
164 $style_path = $this->container->getImagesSkinPath($this->style->getId());
165
166 $path1 = $style_path . "/test_image_1.svg";
167 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
168
169 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
170 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
171
172 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
173 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
174
175 $path4 = $style_path . "/nonsvg.png";
176 $icon4 = new ilSystemStyleIcon("nonsvg.png", $path4, "png");
177
178 $path5 = $style_path . "/icon_accs.svg";
179 $icon5 = new ilSystemStyleIcon("icon_accs.svg", $path5, "svg");
180
181 $expected_icons = [
182 $style_path => [$icon5,$icon1,$icon4],
183 $style_path . "/image_subfolder" => [$icon2,$icon3],
184 ];
185
186 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
187 $this->assertEquals($expected_icons, $folder->getIconsSortedByFolder());
188 }
189
190 public function testExtractColorset()
191 {
192 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
193
194 $expected_color_set = new ilSystemStyleIconColorSet();
195 $color1 = new ilSystemStyleIconColor("id_505050", "505050", "505050", "505050");
196 $color2 = new ilSystemStyleIconColor("id_6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
197 $color3 = new ilSystemStyleIconColor("id_838383", "838383", "838383", "838383");
198 $color4 = new ilSystemStyleIconColor("id_8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
199 $color5 = new ilSystemStyleIconColor("id_303030", "303030", "303030", "303030");
200 $color6 = new ilSystemStyleIconColor("id_404040", "404040", "404040", "404040");
201 $color7 = new ilSystemStyleIconColor("id_000", "000", "000", "000");
202
203 $expected_color_set->addColor($color1);
204 $expected_color_set->addColor($color2);
205 $expected_color_set->addColor($color3);
206 $expected_color_set->addColor($color4);
207 $expected_color_set->addColor($color5);
208 $expected_color_set->addColor($color6);
209 $expected_color_set->addColor($color7);
210
211 $this->assertEquals($expected_color_set, $folder->getColorSet());
212 }
213
214 public function testExtractChangeColors()
215 {
216 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
217 $folder1->changeIconColors(["505050" => "555555"]);
218
219 $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
220
221 $expected_color_set = new ilSystemStyleIconColorSet();
222 $color1 = new ilSystemStyleIconColor("id_555555", "555555", "555555", "555555");
223 $color2 = new ilSystemStyleIconColor("id_6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
224 $color3 = new ilSystemStyleIconColor("id_838383", "838383", "838383", "838383");
225 $color4 = new ilSystemStyleIconColor("id_8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
226 $color5 = new ilSystemStyleIconColor("id_303030", "303030", "303030", "303030");
227 $color6 = new ilSystemStyleIconColor("id_404040", "404040", "404040", "404040");
228 $color7 = new ilSystemStyleIconColor("id_000", "000", "000", "000");
229
230 $expected_color_set->addColor($color2);
231 $expected_color_set->addColor($color3);
232 $expected_color_set->addColor($color4);
233 $expected_color_set->addColor($color5);
234 $expected_color_set->addColor($color6);
235 $expected_color_set->addColor($color1);
236 $expected_color_set->addColor($color7);
237
238 $this->assertEquals($expected_color_set, $folder2->getColorSet());
239 }
240
241 public function testGetUsages()
242 {
243 $style_path = $this->container->getImagesSkinPath($this->style->getId());
244
245 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
246
247 $path1 = $style_path . "/test_image_1.svg";
248 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
249 $icon1->getColorSet();
250
251 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
252 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
253 $icon2->getColorSet();
254
255 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
256 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
257 $icon3->getColorSet();
258
259 $expected_icons_usages = [$icon2,$icon3,$icon1];
260
261 $this->assertEquals($expected_icons_usages, $folder1->getUsagesOfColor("id_6B6B6B"));
262 }
263
265 {
266 $style_path = $this->container->getImagesSkinPath($this->style->getId());
267
268 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
269 $folder1->changeIconColors(["6B6B6B" => "7B6B6B"]);
270
271 $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
272
273 $path1 = $style_path . "/test_image_1.svg";
274 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
275 $icon1->getColorSet();
276
277 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
278 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
279 $icon2->getColorSet();
280
281 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
282 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
283 $icon3->getColorSet();
284
285 $expected_icons_usages = [$icon2,$icon3,$icon1];
286
287 $this->assertEquals($expected_icons_usages, $folder2->getUsagesOfColor("id_7B6B6B"));
288 $this->assertEquals([], $folder2->getUsagesOfColor("id_6B6B6B"));
289 }
290
291 public function testGetUsagesAsString()
292 {
293 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
294
295 $this->assertEquals(
296 'sub_test_image_1; sub_test_image_2; test_image_1; ',
297 $folder1->getUsagesOfColorAsString("id_6B6B6B")
298 );
299 }
300}
An exception for terminatinating execution or to throw for unit testing.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Class ilLanguageMock.
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.
static recursiveRemoveDir($dir)
Recursive delete of a folder.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
static xCopy($src, $dest)
Recursive copy of a folder.
global $DIC
Definition: goto.php:24