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