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