ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
10 
17 {
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() : void
43  {
44  global $DIC;
45 
46  $this->save_dic = $DIC;
47 
48  $this->skin = new ilSkinXML("skin1", "skin 1");
49 
50  $this->style1 = new ilSkinStyleXML("style1", "Style 1");
51  $this->style1->setCssFile("style1css");
52  $this->style1->setImageDirectory("style1image");
53  $this->style1->setSoundDirectory("style1sound");
54  $this->style1->setFontDirectory("style1font");
55 
56  $this->style2 = new ilSkinStyleXML("style2", "Style 2");
57  $this->style2->setCssFile("style2css");
58  $this->style2->setImageDirectory("style2image");
59  $this->style2->setSoundDirectory("style2sound");
60  $this->style2->setFontDirectory("style2font");
61 
62  $this->system_style_config = new ilSystemStyleConfigMock();
63 
64  mkdir($this->system_style_config->test_skin_temp_path);
65  ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
66  }
67 
68  protected function tearDown() : void
69  {
70  global $DIC;
71  $DIC = $this->save_dic;
72 
73  ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
74  }
75 
76  public function testSkinNameAndId()
77  {
78  $this->assertEquals("skin1", $this->skin->getId());
79  $this->assertEquals("skin 1", $this->skin->getName());
80  }
81 
82  public function testAddStyle()
83  {
84  $this->assertEquals(count($this->skin), 0);
85  $this->assertEquals(count($this->skin->getStyles()), 0);
86  $this->skin->addStyle($this->style1);
87  $this->assertEquals(count($this->skin), 1);
88  $this->assertEquals(count($this->skin->getStyles()), 1);
89  $this->skin->addStyle($this->style1);
90  $this->assertEquals(count($this->skin), 2);
91  $this->assertEquals(count($this->skin->getStyles()), 2);
92  $this->skin->addStyle($this->style2);
93  $this->assertEquals(count($this->skin), 3);
94  $this->assertEquals(count($this->skin->getStyles()), 3);
95  }
96 
97  public function testGetStyles()
98  {
99  $this->skin->addStyle($this->style1);
100  $this->skin->addStyle($this->style2);
101 
102  $this->assertNotEquals($this->skin->getStyle("style2"), $this->style1);
103  $this->assertEquals($this->skin->getStyle("style2"), $this->style2);
104  }
105 
106  public function testRemoveStyles()
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  }
116 
117  public function testRemoveTestTwice()
118  {
119  $this->skin->addStyle($this->style1);
120  $this->skin->addStyle($this->style2);
121  $this->assertEquals(count($this->skin), 2);
122  $this->skin->removeStyle("style1");
123  $this->assertEquals(count($this->skin), 1);
124  $this->skin->removeStyle("style2");
125  $this->assertEquals(count($this->skin), 0);
126  try {
127  $this->skin->removeStyle("style2");
128  $this->assertTrue(false);
129  } catch (ilSystemStyleException $e) {
130  $this->assertEquals($e->getCode(), ilSystemStyleException::INVALID_ID);
131  }
132  }
133 
134  public function testAsXML()
135  {
136  $this->skin->addStyle($this->style1);
137  $this->skin->addStyle($this->style2);
138  $this->assertEquals($this->skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
139  }
140 
141  public function testWriteXML()
142  {
143  $this->skin->addStyle($this->style1);
144  $this->skin->addStyle($this->style2);
145  $this->skin->writeToXMLFile($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
146  $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"));
147  unlink($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
148  }
149 
150  public function testReadXML()
151  {
152  $skin = ilSkinXML::parseFromXML($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml");
153  $this->assertEquals($skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
154  }
155 }
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.
global $DIC
Definition: goto.php:24
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.