ILIAS  release_7 Revision v7.30-3-g800a261c036
ilSystemStyleSkinContainerTest.php
Go to the documentation of this file.
1<?php
2
19include_once("Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
20include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
21include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
22include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
23include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleDICMock.php");
24
25include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
26include_once("Services/Utilities/classes/class.ilUtil.php");
27
28use PHPUnit\Framework\TestCase;
29
35class ilSystemStyleSkinContainerTest extends TestCase
36{
37
38
42 protected $skin;
43
47 protected $style1 = null;
48
52 protected $style2 = null;
53
58
59 protected $save_dic = null;
60
61 protected function setUp() : void
62 {
63 global $DIC;
64
65 $this->save_dic = $DIC;
67
68 if (!defined('PATH_TO_LESSC')) {
69 if (file_exists("ilias.ini.php")) {
70 $ini = parse_ini_file("ilias.ini.php", true);
71 define('PATH_TO_LESSC', $ini['tools']['lessc'] ?? '');
72 } else {
73 define('PATH_TO_LESSC', "");
74 }
75 }
76
77 $this->skin = new ilSkinXML("skin1", "skin 1");
78
79 $this->style1 = new ilSkinStyleXML("style1", "Style 1");
80 $this->style1->setCssFile("style1css");
81 $this->style1->setImageDirectory("style1image");
82 $this->style1->setSoundDirectory("style1sound");
83 $this->style1->setFontDirectory("style1font");
84
85 $this->style2 = new ilSkinStyleXML("style2", "Style 2");
86 $this->style2->setCssFile("style2css");
87 $this->style2->setImageDirectory("style2image");
88 $this->style2->setSoundDirectory("style2sound");
89 $this->style2->setFontDirectory("style2font");
90
91 $this->system_style_config = new ilSystemStyleConfigMock();
92
93 mkdir($this->system_style_config->test_skin_temp_path);
94 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
95 }
96
97 protected function tearDown() : void
98 {
99 global $DIC;
101
102 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
103 }
104
105 public function testGenerateFromId()
106 {
107 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
108 $this->assertEquals($container->getSkin()->getId(), $this->skin->getId());
109 $this->assertEquals($container->getSkin()->getName(), $this->skin->getName());
110
111 $this->assertEquals($container->getSkin()->getStyle($this->style1->getId()), $this->style1);
112 $this->assertEquals($container->getSkin()->getStyle($this->style2->getId()), $this->style2);
113 }
114
115 public function testCreateDelete()
116 {
117 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
118
119 $container->getSkin()->setId("newSkin");
121
122 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin"));
123 $container->delete();
124 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin"));
125 }
126
127 public function testUpdateSkinNoIdChange()
128 {
129 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
130 $container->updateSkin();
131 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId()));
132 }
133
135 {
136 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
137 $old_skin = clone $container->getSkin();
138 $container->getSkin()->setId("newSkin2");
139 $container->updateSkin($old_skin);
140 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin2"));
141 $old_skin = clone $container->getSkin();
142 $container->getSkin()->setId($this->skin->getId());
143 $container->updateSkin($old_skin);
144 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin2"));
145 }
146
147 public function testAddStyle()
148 {
149 $new_style = new ilSkinStyleXML("style1new", "new Style");
150 $new_style->setCssFile("style1new");
151 $new_style->setImageDirectory("style1newimage");
152 $new_style->setSoundDirectory("style1newsound");
153 $new_style->setFontDirectory("style1newfont");
154
155 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
156
157 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
158 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
159 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
160 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
161 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
162 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
163
164 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newimage"));
165 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newsound"));
166 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newfont"));
167 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.css"));
168 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.less"));
169 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new-variables.less"));
170
171 $container->addStyle($new_style);
172
173 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
174 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
175 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
176 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
177 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
178 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
179
180 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newimage"));
181 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newsound"));
182 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newfont"));
183 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.css"));
184 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.less"));
185 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new-variables.less"));
186 }
187
188 public function testDeleteStyle()
189 {
190 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
191
192 $container->deleteStyle($this->style1);
193
194 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
195 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
196 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
197 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
198 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
199 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
200
201 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2image"));
202 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2sound"));
203 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2font"));
204 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2css.css"));
205 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2css.less"));
206 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2css-variables.less"));
207 }
208
209 public function testUpdateStyle()
210 {
211 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
212 $skin = $container->getSkin();
213
214 $old_style = clone $skin->getStyle($this->style1->getId());
215 $new_style = $skin->getStyle($this->style1->getId());
216
217 $new_style->setId("style1new");
218 $new_style->setName("new Style");
219 $new_style->setCssFile("style1new");
220 $new_style->setImageDirectory("style1newimage");
221 $new_style->setSoundDirectory("style1newsound");
222 $new_style->setFontDirectory("style1newfont");
223
224 $container->updateStyle($new_style->getId(), $old_style);
225
226 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
227 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
228 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
229 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
230 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
231 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
232
233 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newimage"));
234 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newsound"));
235 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newfont"));
236 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.css"));
237 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.less"));
238 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new-variables.less"));
239 }
240
241 public function testDeleteSkin()
242 {
243 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
244 $skin = $container->getSkin();
245
246 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId()));
247 $container->delete();
248 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId()));
249 }
250
251 public function testCopySkin()
252 {
253 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
254 $skin = $container->getSkin();
255
256 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
257
258 $container_copy = $container->copy();
259 $skin_copy = $container_copy->getSkin();
260
261 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
262 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
263 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1image"));
264 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1sound"));
265 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1font"));
266 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.css"));
267 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.less"));
268 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css-variables.less"));
269
270 $this->assertEquals($skin->getName() . " Copy", $skin_copy->getName());
271 $this->assertEquals("0.1", $skin_copy->getVersion());
272 }
273
275 {
276 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
277 $skin = $container->getSkin();
278 $container_copy = $container->copy("inject");
279 $skin_copy = $container_copy->getSkin();
280
281 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "inject"));
282 $this->assertEquals($skin->getName() . " inject", $skin_copy->getName());
283 $this->assertEquals("0.1", $skin_copy->getVersion());
284 }
285
286 public function testImportSkin()
287 {
288 $this->markTestSkipped('Unzipping is not possible due to missing dependencies');
289 return;
290 if (!defined('PATH_TO_ZIP')) {
291 if (file_exists("ilias.ini.php")) {
292 $ini = parse_ini_file("ilias.ini.php", true);
293 define('PATH_TO_ZIP', $ini['tools']['zip']);
294 } elseif (is_executable("/usr/bin/zip")) {
295 define('PATH_TO_ZIP', "/usr/bin/zip");
296 } else {
297 define('PATH_TO_ZIP', "");
298 }
299 }
300
301 if (!defined('PATH_TO_UNZIP')) {
302 if (file_exists("ilias.ini.php")) {
303 $ini = parse_ini_file("ilias.ini.php", true);
304 define('PATH_TO_UNZIP', $ini['tools']['unzip']);
305 } elseif (is_executable("/usr/bin/unzip")) {
306 define('PATH_TO_UNZIP', "/usr/bin/unzip");
307 } else {
308 define('PATH_TO_UNZIP', "");
309 }
310 }
311
312 //Only perform this test, if an unzip and zip path has been found.
313 if (PATH_TO_UNZIP !== "" && PATH_TO_ZIP !== "") {
314 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
315 $skin = $container->getSkin();
316
317 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
318
319 $container_import = $container->import($container->createTempZip(), $this->skin->getId() . ".zip", null, $this->system_style_config, false);
320 $skin_copy = $container_import->getSkin();
321
322 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
323 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
324 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1image"));
325 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1sound"));
326 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1font"));
327 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.css"));
328 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.less"));
329 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css-variables.less"));
330 } else {
331 $this->markTestIncomplete('No unzip has been detected on the system');
332 }
333 }
334}
An exception for terminatinating execution or to throw for unit testing.
ilSkinXml holds an manages the basic data of a skin as provide by the template of the skin.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Class ilLanguageMock.
Used to stack messages to be shown to the user.
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
$ini
Definition: raiseError.php:4
$container
Definition: wac.php:13