ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilSystemStyleSkinContainerTest.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/Utilities/class.ilSystemStyleMessageStack.php");
10include_once("Services/Utilities/classes/class.ilUtil.php");
11
12use PHPUnit\Framework\TestCase;
13
19class ilSystemStyleSkinContainerTest extends TestCase
20{
21
22
26 protected $skin;
27
31 protected $style1 = null;
32
36 protected $style2 = null;
37
42
43 protected $save_dic = null;
44
45 protected function setUp() : void
46 {
47 global $DIC;
48
49 $this->save_dic = $DIC;
51
52 if (!defined('PATH_TO_LESSC')) {
53 if (file_exists("ilias.ini.php")) {
54 $ini = parse_ini_file("ilias.ini.php", true);
55 define('PATH_TO_LESSC', $ini['tools']['lessc']);
56 } else {
57 define('PATH_TO_LESSC', "");
58 }
59 }
60
61 $this->skin = new ilSkinXML("skin1", "skin 1");
62
63 $this->style1 = new ilSkinStyleXML("style1", "Style 1");
64 $this->style1->setCssFile("style1css");
65 $this->style1->setImageDirectory("style1image");
66 $this->style1->setSoundDirectory("style1sound");
67 $this->style1->setFontDirectory("style1font");
68
69 $this->style2 = new ilSkinStyleXML("style2", "Style 2");
70 $this->style2->setCssFile("style2css");
71 $this->style2->setImageDirectory("style2image");
72 $this->style2->setSoundDirectory("style2sound");
73 $this->style2->setFontDirectory("style2font");
74
75 $this->system_style_config = new ilSystemStyleConfigMock();
76
77 mkdir($this->system_style_config->test_skin_temp_path);
78 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
79 }
80
81 protected function tearDown() : void
82 {
83 global $DIC;
85
86 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
87 }
88
89 public function testGenerateFromId()
90 {
91 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
92 $this->assertEquals($container->getSkin()->getId(), $this->skin->getId());
93 $this->assertEquals($container->getSkin()->getName(), $this->skin->getName());
94
95 $this->assertEquals($container->getSkin()->getStyle($this->style1->getId()), $this->style1);
96 $this->assertEquals($container->getSkin()->getStyle($this->style2->getId()), $this->style2);
97 }
98
99 public function testCreateDelete()
100 {
101 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
102
103 $container->getSkin()->setId("newSkin");
105
106 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin"));
107 $container->delete();
108 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin"));
109 }
110
111 public function testUpdateSkin()
112 {
113 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
114 $old_skin = clone $container->getSkin();
115 $container->getSkin()->setId("newSkin2");
116 $container->updateSkin($old_skin);
117 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin2"));
118 $old_skin = clone $container->getSkin();
119 $container->getSkin()->setId($this->skin->getId());
120 $container->updateSkin($old_skin);
121 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . "newSkin2"));
122 }
123
124 public function testAddStyle()
125 {
126 $new_style = new ilSkinStyleXML("style1new", "new Style");
127 $new_style->setCssFile("style1new");
128 $new_style->setImageDirectory("style1newimage");
129 $new_style->setSoundDirectory("style1newsound");
130 $new_style->setFontDirectory("style1newfont");
131
132 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
133
134 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
135 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
136 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
137 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
138 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
139 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
140
141 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newimage"));
142 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newsound"));
143 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newfont"));
144 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.css"));
145 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.less"));
146 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new-variables.less"));
147
148 $container->addStyle($new_style);
149
150 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
151 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
152 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
153 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
154 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
155 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
156
157 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newimage"));
158 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newsound"));
159 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newfont"));
160 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.css"));
161 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.less"));
162 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new-variables.less"));
163 }
164
165 public function testDeleteStyle()
166 {
167 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
168
169 $container->deleteStyle($this->style1);
170
171 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
172 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
173 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
174 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
175 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
176 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
177
178 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2image"));
179 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2sound"));
180 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2font"));
181 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2css.css"));
182 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2css.less"));
183 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style2css-variables.less"));
184 }
185
186 public function testUpdateStyle()
187 {
188 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
189 $skin = $container->getSkin();
190
191 $old_style = clone $skin->getStyle($this->style1->getId());
192 $new_style = $skin->getStyle($this->style1->getId());
193
194 $new_style->setId("style1new");
195 $new_style->setName("new Style");
196 $new_style->setCssFile("style1new");
197 $new_style->setImageDirectory("style1newimage");
198 $new_style->setSoundDirectory("style1newsound");
199 $new_style->setFontDirectory("style1newfont");
200
201 $container->updateStyle($new_style->getId(), $old_style);
202
203 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1image"));
204 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1sound"));
205 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1font"));
206 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.css"));
207 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css.less"));
208 $this->assertFalse(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1css-variables.less"));
209
210 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newimage"));
211 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newsound"));
212 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1newfont"));
213 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.css"));
214 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new.less"));
215 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $this->skin->getId() . "/style1new-variables.less"));
216 }
217
218 public function testDeleteSkin()
219 {
220 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
221 $skin = $container->getSkin();
222
223 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId()));
224 $container->delete();
225 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId()));
226 }
227
228 public function testCopySkin()
229 {
230 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
231 $skin = $container->getSkin();
232
233 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
234
235 $container_copy = $container->copy();
236 $skin_copy = $container_copy->getSkin();
237
238 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
239 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
240 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1image"));
241 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1sound"));
242 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1font"));
243 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.css"));
244 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.less"));
245 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css-variables.less"));
246 }
247
248 public function testImportSkin()
249 {
250 if (!defined('PATH_TO_ZIP')) {
251 if (file_exists("ilias.ini.php")) {
252 $ini = parse_ini_file("ilias.ini.php", true);
253 define('PATH_TO_ZIP', $ini['tools']['zip']);
254 } elseif (is_executable("/usr/bin/zip")) {
255 define('PATH_TO_ZIP', "/usr/bin/zip");
256 } else {
257 define('PATH_TO_ZIP', "");
258 }
259 }
260
261 if (!defined('PATH_TO_UNZIP')) {
262 if (file_exists("ilias.ini.php")) {
263 $ini = parse_ini_file("ilias.ini.php", true);
264 define('PATH_TO_UNZIP', $ini['tools']['unzip']);
265 } elseif (is_executable("/usr/bin/unzip")) {
266 define('PATH_TO_UNZIP', "/usr/bin/unzip");
267 } else {
268 define('PATH_TO_UNZIP', "");
269 }
270 }
271
272 //Only perform this test, if an unzip path has been found.
273 if (PATH_TO_UNZIP != "") {
274 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config);
275 $skin = $container->getSkin();
276
277 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
278
279 $container_import = $container->import($container->createTempZip(), $this->skin->getId() . ".zip", null, $this->system_style_config, false);
280 $skin_copy = $container_import->getSkin();
281
282 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy"));
283 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
284 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1image"));
285 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1sound"));
286 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1font"));
287 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.css"));
288 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.less"));
289 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css-variables.less"));
290 } else {
291 $this->markTestIncomplete('No unzip has been detected on the system');
292 }
293 }
294}
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.
$ini
Definition: raiseError.php:4
$container
Definition: wac.php:13
$DIC
Definition: xapitoken.php:46