ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSkinXMLTest.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 function setUp()
39  {
40  $this->skin = new ilSkinXML("skin1", "skin 1");
41 
42  $this->style1 = new ilSkinStyleXML("style1", "Style 1");
43  $this->style1->setCssFile("style1css");
44  $this->style1->setImageDirectory("style1image");
45  $this->style1->setSoundDirectory("style1sound");
46  $this->style1->setFontDirectory("style1font");
47 
48  $this->style2 = new ilSkinStyleXML("style2", "Style 2");
49  $this->style2->setCssFile("style2css");
50  $this->style2->setImageDirectory("style2image");
51  $this->style2->setSoundDirectory("style2sound");
52  $this->style2->setFontDirectory("style2font");
53 
54  $this->system_style_config = new ilSystemStyleConfigMock();
55 
56  mkdir($this->system_style_config->test_skin_temp_path);
57  ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
58  }
59 
60  protected function tearDown()
61  {
62  ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
63  }
64 
65  public function testSkinNameAndId()
66  {
67  $this->assertEquals("skin1", $this->skin->getId());
68  $this->assertEquals("skin 1", $this->skin->getName());
69  }
70 
71  public function testAddStyle()
72  {
73  $this->assertEquals(count($this->skin), 0);
74  $this->assertEquals(count($this->skin->getStyles()), 0);
75  $this->skin->addStyle($this->style1);
76  $this->assertEquals(count($this->skin), 1);
77  $this->assertEquals(count($this->skin->getStyles()), 1);
78  $this->skin->addStyle($this->style1);
79  $this->assertEquals(count($this->skin), 2);
80  $this->assertEquals(count($this->skin->getStyles()), 2);
81  $this->skin->addStyle($this->style2);
82  $this->assertEquals(count($this->skin), 3);
83  $this->assertEquals(count($this->skin->getStyles()), 3);
84  }
85 
86  public function testGetStyles()
87  {
88  $this->skin->addStyle($this->style1);
89  $this->skin->addStyle($this->style2);
90 
91  $this->assertNotEquals($this->skin->getStyle("style2"), $this->style1);
92  $this->assertEquals($this->skin->getStyle("style2"), $this->style2);
93  }
94 
95  public function testRemoveStyles()
96  {
97  $this->skin->addStyle($this->style1);
98  $this->skin->addStyle($this->style2);
99  $this->assertEquals(count($this->skin), 2);
100  $this->skin->removeStyle("style1");
101  $this->assertEquals(count($this->skin), 1);
102  $this->skin->removeStyle("style2");
103  $this->assertEquals(count($this->skin), 0);
104  }
105 
106  public function testRemoveTestTwice()
107  {
108  $this->skin->addStyle($this->style1);
109  $this->skin->addStyle($this->style2);
110  $this->assertEquals(count($this->skin), 2);
111  $this->skin->removeStyle("style1");
112  $this->assertEquals(count($this->skin), 1);
113  $this->skin->removeStyle("style2");
114  $this->assertEquals(count($this->skin), 0);
115  try {
116  $this->skin->removeStyle("style2");
117  $this->assertTrue(false);
118  } catch (ilSystemStyleException $e) {
119  $this->assertEquals($e->getCode(), ilSystemStyleException::INVALID_ID);
120  }
121  }
122 
123  public function testAsXML()
124  {
125  $this->skin->addStyle($this->style1);
126  $this->skin->addStyle($this->style2);
127  $this->assertEquals($this->skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
128  }
129 
130  public function testWriteXML()
131  {
132  $this->skin->addStyle($this->style1);
133  $this->skin->addStyle($this->style2);
134  $this->skin->writeToXMLFile($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
135  $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"));
136  unlink($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
137  }
138 
139  public function testReadXML()
140  {
141  $skin = ilSkinXML::parseFromXML($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml");
142  $this->assertEquals($skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
143  }
144 }
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.