ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSystemStyleIconFolderTest.php
Go to the documentation of this file.
1 <?php
2 
3 include_once("Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
4 include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
5 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
6 include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
7 include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleDICMock.php");
8 
9 include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIcon.php");
10 include_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;
53  $DIC = new ilSystemStyleDICMock();
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;
67  $DIC = $this->save_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 
115  public function testIconDoesNotExist()
116  {
117  $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
118 
119  try{
120  $folder->getIconByName("doesNotExist.svg");
121  $this->assertTrue(false);
122  }catch(ilSystemStyleIconException $e){
123  $this->assertEquals(ilSystemStyleIconException::ICON_DOES_NOT_EXIST,$e->getCode());
124  }
125  }
126 
128  {
129  $style_path = $this->container->getImagesSkinPath($this->style->getId());
130 
131  $path1 = $style_path . "/test_image_1.svg";
132  $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
133 
134  $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
135  $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
136 
137  $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
138  $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
139 
140  $path4 = $style_path . "/nonsvg.png";
141  $icon4 = new ilSystemStyleIcon("nonsvg.png", $path4, "png");
142 
143  $expected_icons = [$icon2,$icon3,$icon1,$icon4];
144 
145  $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
146  $this->assertEquals($expected_icons,$folder->getIcons());
147  }
148 
150  {
151  $style_path = $this->container->getImagesSkinPath($this->style->getId());
152 
153  $path1 = $style_path. "/test_image_1.svg";
154  $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
155 
156  $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
157  $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
158 
159  $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
160  $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
161 
162  $path4 = $style_path . "/nonsvg.png";
163  $icon4 = new ilSystemStyleIcon("nonsvg.png", $path4, "png");
164 
165  $expected_icons = [
166  $style_path => [$icon1,$icon4],
167  $style_path."/image_subfolder" => [$icon2,$icon3],
168  ];
169 
170  $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
171  $this->assertEquals($expected_icons,$folder->getIconsSortedByFolder());
172  }
173 
174  public function testExtractColorset()
175  {
176  $folder = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
177 
178  $expected_color_set = new ilSystemStyleIconColorSet();
179  $color1 = new ilSystemStyleIconColor("505050", "505050", "505050", "505050");
180  $color2 = new ilSystemStyleIconColor("6B6B6B", "6B6B6B", "6B6B6B", "6B6B6B");
181  $color3 = new ilSystemStyleIconColor("838383", "838383", "838383", "838383");
182  $color4 = new ilSystemStyleIconColor("8C8C8C", "8C8C8C", "8C8C8C", "8C8C8C");
183  $color5 = new ilSystemStyleIconColor("303030", "303030", "303030", "303030");
184  $color6 = new ilSystemStyleIconColor("404040", "404040", "404040", "404040");
185 
186  $expected_color_set->addColor($color1);
187  $expected_color_set->addColor($color2);
188  $expected_color_set->addColor($color3);
189  $expected_color_set->addColor($color4);
190  $expected_color_set->addColor($color5);
191  $expected_color_set->addColor($color6);
192 
193  $this->assertEquals($expected_color_set, $folder->getColorSet());
194  }
195 
196  public function testExtractChangeColors(){
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  $style_path = $this->container->getImagesSkinPath($this->style->getId());
222 
223  $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
224 
225  $path1 = $style_path . "/test_image_1.svg";
226  $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
227  $icon1->getColorSet();
228 
229  $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
230  $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
231  $icon2->getColorSet();
232 
233  $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
234  $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
235  $icon3->getColorSet();
236 
237  $expected_icons_usages = [$icon2,$icon3,$icon1];
238 
239  $this->assertEquals($expected_icons_usages,$folder1->getUsagesOfColor("6B6B6B"));
240  }
241 
242  public function testGetUsagesAfterChangeColor(){
243  $style_path = $this->container->getImagesSkinPath($this->style->getId());
244 
245  $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
246  $folder1->changeIconColors(["6B6B6B"=>"7B6B6B"]);
247 
248  $folder2 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
249 
250  $path1 = $style_path . "/test_image_1.svg";
251  $icon1 = new ilSystemStyleIcon("test_image_1.svg", $path1, "svg");
252  $icon1->getColorSet();
253 
254  $path2 = $style_path . "/image_subfolder/sub_test_image_1.svg";
255  $icon2 = new ilSystemStyleIcon("sub_test_image_1.svg", $path2, "svg");
256  $icon2->getColorSet();
257 
258  $path3 = $style_path . "/image_subfolder/sub_test_image_2.svg";
259  $icon3 = new ilSystemStyleIcon("sub_test_image_2.svg", $path3, "svg");
260  $icon3->getColorSet();
261 
262  $expected_icons_usages = [$icon2,$icon3,$icon1];
263 
264  $this->assertEquals($expected_icons_usages,$folder2->getUsagesOfColor("7B6B6B"));
265  $this->assertEquals([],$folder2->getUsagesOfColor("6B6B6B"));
266  }
267 
268  public function testGetUsagesAsString(){
269  $folder1 = new ilSystemStyleIconFolder($this->container->getImagesSkinPath($this->style->getId()));
270 
271  $this->assertEquals('sub_test_image_1; sub_test_image_2; test_image_1; ' ,
272  $folder1->getUsagesOfColorAsString("6B6B6B"));
273  }
274 }
275 
Class for advanced editing exception handling in ILIAS.
Class ilLanguageMock.
"color:#CC0000 style
Definition: example_001.php:92
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.
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
Abstracts a folder containing a set of icons.
global $DIC
static xCopy($src, $dest)
Recursive copy of a folder.