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 12/** 13 * 14 * @author Timon Amstutz <timon.amstutz@ilub.unibe.ch> 15 * @version $Id$* 16 */ 17class ilSystemStyleSkinContainerTest extends PHPUnit_Framework_TestCase 18{ 19 20 21 /** 22 * @var ilSkinXML 23 */ 24 protected $skin; 25 26 /** 27 * @var ilSkinStyleXML 28 */ 29 protected $style1 = null; 30 31 /** 32 * @var ilSkinStyleXML 33 */ 34 protected $style2 = null; 35 36 /** 37 * @var ilSystemStyleConfigMock 38 */ 39 protected $system_style_config; 40 41 protected $save_dic = null; 42 43 protected function setUp() 44 { 45 global $DIC; 46 47 $this->save_dic = $DIC; 48 $DIC = new ilSystemStyleDICMock(); 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; 82 $DIC = $this->save_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"); 102 $container->create(new ilSystemStyleMessageStack()); 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 } elseif (is_executable("/usr/bin/zip")) { 253 define('PATH_TO_ZIP', "/usr/bin/zip"); 254 } else { 255 define('PATH_TO_ZIP', ""); 256 } 257 } 258 259 if (!defined('PATH_TO_UNZIP')) { 260 if (file_exists("ilias.ini.php")) { 261 $ini = parse_ini_file("ilias.ini.php", true); 262 define('PATH_TO_UNZIP', $ini['tools']['unzip']); 263 } elseif (is_executable("/usr/bin/unzip")) { 264 define('PATH_TO_UNZIP', "/usr/bin/unzip"); 265 } else { 266 define('PATH_TO_UNZIP', ""); 267 } 268 } 269 270 //Only perform this test, if an unzip path has been found. 271 if (PATH_TO_UNZIP != "") { 272 $container = ilSystemStyleSkinContainer::generateFromId($this->skin->getId(), null, $this->system_style_config); 273 $skin = $container->getSkin(); 274 275 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy")); 276 277 $container_import = $container->import($container->createTempZip(), $this->skin->getId() . ".zip", null, $this->system_style_config, false); 278 $skin_copy = $container_import->getSkin(); 279 280 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . "Copy")); 281 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId())); 282 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1image")); 283 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1sound")); 284 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1font")); 285 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.css")); 286 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css.less")); 287 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . "/style1css-variables.less")); 288 } else { 289 $this->markTestIncomplete('No unzip has been detected on the system'); 290 } 291 } 292} 293