ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4include_once("./Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
5include_once("./Services/Style/System/classes/Utilities/class.ilSkinXML.php");
6include_once("./Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
7include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
8
9use PHPUnit\Framework\TestCase;
10
16class ilSkinXMLTest extends TestCase
17{
18
19
23 protected $skin;
24
28 protected $style1 = null;
29
33 protected $style2 = null;
34
39
40 protected function setUp() : void
41 {
42 $this->skin = new ilSkinXML("skin1", "skin 1");
43
44 $this->style1 = new ilSkinStyleXML("style1", "Style 1");
45 $this->style1->setCssFile("style1css");
46 $this->style1->setImageDirectory("style1image");
47 $this->style1->setSoundDirectory("style1sound");
48 $this->style1->setFontDirectory("style1font");
49
50 $this->style2 = new ilSkinStyleXML("style2", "Style 2");
51 $this->style2->setCssFile("style2css");
52 $this->style2->setImageDirectory("style2image");
53 $this->style2->setSoundDirectory("style2sound");
54 $this->style2->setFontDirectory("style2font");
55
56 $this->system_style_config = new ilSystemStyleConfigMock();
57
58 mkdir($this->system_style_config->test_skin_temp_path);
59 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
60 }
61
62 protected function tearDown() : void
63 {
64 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
65 }
66
67 public function testSkinNameAndId()
68 {
69 $this->assertEquals("skin1", $this->skin->getId());
70 $this->assertEquals("skin 1", $this->skin->getName());
71 }
72
73 public function testAddStyle()
74 {
75 $this->assertEquals(count($this->skin), 0);
76 $this->assertEquals(count($this->skin->getStyles()), 0);
77 $this->skin->addStyle($this->style1);
78 $this->assertEquals(count($this->skin), 1);
79 $this->assertEquals(count($this->skin->getStyles()), 1);
80 $this->skin->addStyle($this->style1);
81 $this->assertEquals(count($this->skin), 2);
82 $this->assertEquals(count($this->skin->getStyles()), 2);
83 $this->skin->addStyle($this->style2);
84 $this->assertEquals(count($this->skin), 3);
85 $this->assertEquals(count($this->skin->getStyles()), 3);
86 }
87
88 public function testGetStyles()
89 {
90 $this->skin->addStyle($this->style1);
91 $this->skin->addStyle($this->style2);
92
93 $this->assertNotEquals($this->skin->getStyle("style2"), $this->style1);
94 $this->assertEquals($this->skin->getStyle("style2"), $this->style2);
95 }
96
97 public function testRemoveStyles()
98 {
99 $this->skin->addStyle($this->style1);
100 $this->skin->addStyle($this->style2);
101 $this->assertEquals(count($this->skin), 2);
102 $this->skin->removeStyle("style1");
103 $this->assertEquals(count($this->skin), 1);
104 $this->skin->removeStyle("style2");
105 $this->assertEquals(count($this->skin), 0);
106 }
107
108 public function testRemoveTestTwice()
109 {
110 $this->skin->addStyle($this->style1);
111 $this->skin->addStyle($this->style2);
112 $this->assertEquals(count($this->skin), 2);
113 $this->skin->removeStyle("style1");
114 $this->assertEquals(count($this->skin), 1);
115 $this->skin->removeStyle("style2");
116 $this->assertEquals(count($this->skin), 0);
117 try {
118 $this->skin->removeStyle("style2");
119 $this->assertTrue(false);
120 } catch (ilSystemStyleException $e) {
121 $this->assertEquals($e->getCode(), ilSystemStyleException::INVALID_ID);
122 }
123 }
124
125 public function testAsXML()
126 {
127 $this->skin->addStyle($this->style1);
128 $this->skin->addStyle($this->style2);
129 $this->assertEquals($this->skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
130 }
131
132 public function testWriteXML()
133 {
134 $this->skin->addStyle($this->style1);
135 $this->skin->addStyle($this->style2);
136 $this->skin->writeToXMLFile($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
137 $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"));
138 unlink($this->system_style_config->getCustomizingSkinPath() . "skin1/template-copy.xml");
139 }
140
141 public function testReadXML()
142 {
143 $skin = ilSkinXML::parseFromXML($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml");
144 $this->assertEquals($skin->asXML(), file_get_contents($this->system_style_config->getCustomizingSkinPath() . "skin1/template.xml"));
145 }
146}
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 for advanced editing exception handling in ILIAS.
static recursiveRemoveDir($dir)
Recursive delete of a folder.
static xCopy($src, $dest)
Recursive copy of a folder.