ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSystemStyleSkinXMLTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
5 include_once("./Services/Style/System/classes/Utilities/class.ilSkinXML.php");
6 include_once("./Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
7 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
8 
15 {
16 
17 
21  protected $skin;
22 
26  protected $style1 = null;
27 
31  protected $style2 = null;
32 
37 
38  protected $save_dic = null;
39 
40  protected function setUp()
41  {
42  global $DIC;
43 
44  $this->save_dic = $DIC;
45 
46  $this->skin = new ilSkinXML("skin1", "skin 1");
47 
48  $this->style1 = new ilSkinStyleXML("style1", "Style 1");
49  $this->style1->setCssFile("style1css");
50  $this->style1->setImageDirectory("style1image");
51  $this->style1->setSoundDirectory("style1sound");
52  $this->style1->setFontDirectory("style1font");
53 
54  $this->style2 = new ilSkinStyleXML("style2", "Style 2");
55  $this->style2->setCssFile("style2css");
56  $this->style2->setImageDirectory("style2image");
57  $this->style2->setSoundDirectory("style2sound");
58  $this->style2->setFontDirectory("style2font");
59 
60  $this->system_style_config = new ilSystemStyleConfigMock();
61 
62  mkdir($this->system_style_config->test_skin_temp_path);
63  ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
64  }
65 
66  protected function tearDown()
67  {
68  global $DIC;
69  $DIC = $this->save_dic;
70 
71  ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
72  }
73 
74  public function testSkinNameAndId()
75  {
76  $this->assertEquals("skin1", $this->skin->getId());
77  $this->assertEquals("skin 1", $this->skin->getName());
78  }
79 
80  public function testAddStyle()
81  {
82  $this->assertEquals(count($this->skin), 0);
83  $this->assertEquals(count($this->skin->getStyles()), 0);
84  $this->skin->addStyle($this->style1);
85  $this->assertEquals(count($this->skin), 1);
86  $this->assertEquals(count($this->skin->getStyles()), 1);
87  $this->skin->addStyle($this->style1);
88  $this->assertEquals(count($this->skin), 2);
89  $this->assertEquals(count($this->skin->getStyles()), 2);
90  $this->skin->addStyle($this->style2);
91  $this->assertEquals(count($this->skin), 3);
92  $this->assertEquals(count($this->skin->getStyles()), 3);
93  }
94 
95  public function testGetStyles()
96  {
97  $this->skin->addStyle($this->style1);
98  $this->skin->addStyle($this->style2);
99 
100  $this->assertNotEquals($this->skin->getStyle("style2"), $this->style1);
101  $this->assertEquals($this->skin->getStyle("style2"), $this->style2);
102  }
103 
104  public function testRemoveStyles()
105  {
106  $this->skin->addStyle($this->style1);
107  $this->skin->addStyle($this->style2);
108  $this->assertEquals(count($this->skin), 2);
109  $this->skin->removeStyle("style1");
110  $this->assertEquals(count($this->skin), 1);
111  $this->skin->removeStyle("style2");
112  $this->assertEquals(count($this->skin), 0);
113  }
114 
115  public function testRemoveTestTwice()
116  {
117  $this->skin->addStyle($this->style1);
118  $this->skin->addStyle($this->style2);
119  $this->assertEquals(count($this->skin), 2);
120  $this->skin->removeStyle("style1");
121  $this->assertEquals(count($this->skin), 1);
122  $this->skin->removeStyle("style2");
123  $this->assertEquals(count($this->skin), 0);
124  try {
125  $this->skin->removeStyle("style2");
126  $this->assertTrue(false);
127  } catch (ilSystemStyleException $e) {
128  $this->assertEquals($e->getCode(), ilSystemStyleException::INVALID_ID);
129  }
130  }
131 
132  public function testAsXML()
133  {
134  $this->skin->addStyle($this->style1);
135  $this->skin->addStyle($this->style2);
136  $this->assertEquals($this->skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
137  }
138 
139  public function testWriteXML()
140  {
141  $this->skin->addStyle($this->style1);
142  $this->skin->addStyle($this->style2);
143  $this->skin->writeToXMLFile($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
144  $this->assertEquals(file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml"), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
145  unlink($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
146  }
147 
148  public function testReadXML()
149  {
150  $skin = ilSkinXML::parseFromXML($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml");
151  $this->assertEquals($skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
152  }
153 }
global $DIC
Definition: saml.php:7
ilSkinXml holds an manages the basic data of a skin as provide by the template of the skin...
static recursiveRemoveDir($dir)
Recursive delete of a folder.
Class for advanced editing exception handling in ILIAS.
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
static xCopy($src, $dest)
Recursive copy of a folder.