ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
12
19{
20
25
29 protected $container;
30
34 protected $style;
35
39 protected $icon_name = "test_image_1.svg";
40
44 protected $icon_type = "svg";
45
46 protected $save_dic = null;
47
48 protected function setUp()
49 {
50 global $DIC;
51
52 $this->save_dic = $DIC;
54
55 $this->system_style_config = new ilSystemStyleConfigMock();
56
57 mkdir($this->system_style_config->test_skin_temp_path);
58 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
59
60 $this->container = ilSystemStyleSkinContainer::generateFromId("skin1", null, $this->system_style_config);
61 $this->style = $this->container->getSkin()->getStyle("style1");
62 }
63
64 protected function tearDown()
65 {
66 global $DIC;
68
69 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
70 }
71
72 public function testConstruct()
73 {
74 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
75
76 $this->assertEquals($this->container->getImagesSkinPath($this->style->getId()), $folder->getPath());
77 }
78
79 public function testSetPath()
80 {
81 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
82 $folder->setPath("pathnew");
83
84 $this->assertEquals("pathnew", $folder->getPath());
85 }
86
87
88 public function testReadRecursiveCount()
89 {
90 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
91 $this->assertEquals(4, count($folder->getIcons()));
92 }
93
94 public function testFolderDoesNotExist()
95 {
96 try {
97 new ilSystemStyleIconFolder("Does not exist");
98 $this->assertTrue(false);
99 } catch (ilSystemStyleIconException $e) {
100 $this->assertEquals(ilSystemStyleIconException::IMAGES_FOLDER_DOES_NOT_EXIST, $e->getCode());
101 }
102 }
103
104 public function testFolderGetIcon()
105 {
106 $style_path = $this->container->getImagesSkinPath($this->style->getId());
107
108 $path1 = $style_path . "/test_image_1.svg";
109 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
110 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
111 $this->assertEquals($icon1, $folder->getIconByName("test_image_1.svg"));
112 }
113
114 public function testIconDoesNotExist()
115 {
116 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
117
118 try {
119 $folder->getIconByName("doesNotExist.svg");
120 $this->assertTrue(false);
121 } catch (ilSystemStyleIconException $e) {
122 $this->assertEquals(ilSystemStyleIconException::ICON_DOES_NOT_EXIST, $e->getCode());
123 }
124 }
125
127 {
128 $style_path = $this->container->getImagesSkinPath($this->style->getId());
129
130 $path1 = $style_path . "/test_image_1.svg";
131 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
132
133 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
134 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
135
136 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
137 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
138
139 $path4 = $style_path . "/nonsvg.png";
140 $icon4 = new ilSystemStyleIcon("nonsvg.png", $path4, "png");
141
142 $expected_icons = [$icon2,$icon3,$icon1,$icon4];
143
144 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
145 $this->assertEquals($expected_icons, $folder->getIcons());
146 }
147
149 {
150 $style_path = $this->container->getImagesSkinPath($this->style->getId());
151
152 $path1 = $style_path . "/test_image_1.svg";
153 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
154
155 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
156 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
157
158 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
159 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
160
161 $path4 = $style_path . "/nonsvg.png";
162 $icon4 = new ilSystemStyleIcon("nonsvg.png", $path4, "png");
163
164 $expected_icons = [
165 $style_path => [$icon1,$icon4],
166 $style_path . "/image_subfolder" => [$icon2,$icon3],
167 ];
168
169 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
170 $this->assertEquals($expected_icons, $folder->getIconsSortedByFolder());
171 }
172
173 public function testExtractColorset()
174 {
175 $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
176
177 $expected_color_set = new ilSystemStyleIconColorSet();
178 $color1 = new ilSystemStyleIconColor("505050", "505050", "505050", "505050");
179 $color2 = new ilSystemStyleIconColor("6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
180 $color3 = new ilSystemStyleIconColor("838383", "838383", "838383", "838383");
181 $color4 = new ilSystemStyleIconColor("8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
182 $color5 = new ilSystemStyleIconColor("303030", "303030", "303030", "303030");
183 $color6 = new ilSystemStyleIconColor("404040", "404040", "404040", "404040");
184
185 $expected_color_set->addColor($color1);
186 $expected_color_set->addColor($color2);
187 $expected_color_set->addColor($color3);
188 $expected_color_set->addColor($color4);
189 $expected_color_set->addColor($color5);
190 $expected_color_set->addColor($color6);
191
192 $this->assertEquals($expected_color_set, $folder->getColorSet());
193 }
194
195 public function testExtractChangeColors()
196 {
197 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
198 $folder1->changeIconColors(["505050" => "555555"]);
199
200 $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
201
202 $expected_color_set = new ilSystemStyleIconColorSet();
203 $color1 = new ilSystemStyleIconColor("555555", "555555", "555555", "555555");
204 $color2 = new ilSystemStyleIconColor("6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
205 $color3 = new ilSystemStyleIconColor("838383", "838383", "838383", "838383");
206 $color4 = new ilSystemStyleIconColor("8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
207 $color5 = new ilSystemStyleIconColor("303030", "303030", "303030", "303030");
208 $color6 = new ilSystemStyleIconColor("404040", "404040", "404040", "404040");
209
210 $expected_color_set->addColor($color2);
211 $expected_color_set->addColor($color3);
212 $expected_color_set->addColor($color4);
213 $expected_color_set->addColor($color5);
214 $expected_color_set->addColor($color6);
215 $expected_color_set->addColor($color1);
216
217 $this->assertEquals($expected_color_set, $folder2->getColorSet());
218 }
219
220 public function testGetUsages()
221 {
222 $style_path = $this->container->getImagesSkinPath($this->style->getId());
223
224 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
225
226 $path1 = $style_path . "/test_image_1.svg";
227 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
228 $icon1->getColorSet();
229
230 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
231 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
232 $icon2->getColorSet();
233
234 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
235 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
236 $icon3->getColorSet();
237
238 $expected_icons_usages = [$icon2,$icon3,$icon1];
239
240 $this->assertEquals($expected_icons_usages, $folder1->getUsagesOfColor("6B6B6B"));
241 }
242
244 {
245 $style_path = $this->container->getImagesSkinPath($this->style->getId());
246
247 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
248 $folder1->changeIconColors(["6B6B6B" => "7B6B6B"]);
249
250 $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
251
252 $path1 = $style_path . "/test_image_1.svg";
253 $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
254 $icon1->getColorSet();
255
256 $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
257 $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
258 $icon2->getColorSet();
259
260 $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
261 $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
262 $icon3->getColorSet();
263
264 $expected_icons_usages = [$icon2,$icon3,$icon1];
265
266 $this->assertEquals($expected_icons_usages, $folder2->getUsagesOfColor("7B6B6B"));
267 $this->assertEquals([], $folder2->getUsagesOfColor("6B6B6B"));
268 }
269
270 public function testGetUsagesAsString()
271 {
272 $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
273
274 $this->assertEquals(
275 'sub_test_image_1; sub_test_image_2; test_image_1; ',
276 $folder1->getUsagesOfColorAsString("6B6B6B")
277 );
278 }
279}
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: saml.php:7