ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
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
15
16
20 protected $skin;
21
25 protected $style1 = null;
26
30 protected $style2 = null;
31
36
37 protected $save_dic = null;
38
39 protected function setUp(){
40 global $DIC;
41
42 $this->save_dic = $DIC;
43
44 $this->skin = new ilSkinXML("skin1", "skin 1");
45
46 $this->style1 = new ilSkinStyleXML("style1", "Style 1");
47 $this->style1->setCssFile("style1css");
48 $this->style1->setImageDirectory("style1image");
49 $this->style1->setSoundDirectory("style1sound");
50 $this->style1->setFontDirectory("style1font");
51
52 $this->style2 = new ilSkinStyleXML("style2", "Style 2");
53 $this->style2->setCssFile("style2css");
54 $this->style2->setImageDirectory("style2image");
55 $this->style2->setSoundDirectory("style2sound");
56 $this->style2->setFontDirectory("style2font");
57
58 $this->system_style_config = new ilSystemStyleConfigMock();
59
60 mkdir($this->system_style_config->test_skin_temp_path);
61 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path,$this->system_style_config->test_skin_temp_path);
62 }
63
64 protected function tearDown(){
65 global $DIC;
67
68 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
69 }
70
71 public function testSkinNameAndId() {
72 $this->assertEquals("skin1", $this->skin->getId());
73 $this->assertEquals("skin 1", $this->skin->getName());
74
75 }
76
77 public function testAddStyle() {
78 $this->assertEquals(count($this->skin),0);
79 $this->assertEquals(count($this->skin->getStyles()),0);
80 $this->skin->addStyle($this->style1);
81 $this->assertEquals(count($this->skin),1);
82 $this->assertEquals(count($this->skin->getStyles()),1);
83 $this->skin->addStyle($this->style1);
84 $this->assertEquals(count($this->skin),2);
85 $this->assertEquals(count($this->skin->getStyles()),2);
86 $this->skin->addStyle($this->style2);
87 $this->assertEquals(count($this->skin),3);
88 $this->assertEquals(count($this->skin->getStyles()),3);
89 }
90
91 public function testGetStyles() {
92 $this->skin->addStyle($this->style1);
93 $this->skin->addStyle($this->style2);
94
95 $this->assertNotEquals($this->skin->getStyle("style2"),$this->style1);
96 $this->assertEquals($this->skin->getStyle("style2"),$this->style2);
97 }
98
99 public function testRemoveStyles() {
100 $this->skin->addStyle($this->style1);
101 $this->skin->addStyle($this->style2);
102 $this->assertEquals(count($this->skin),2);
103 $this->skin->removeStyle("style1");
104 $this->assertEquals(count($this->skin),1);
105 $this->skin->removeStyle("style2");
106 $this->assertEquals(count($this->skin),0);
107 }
108
109 public function testRemoveTestTwice() {
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
126 public function testAsXML() {
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 $this->skin->addStyle($this->style1);
134 $this->skin->addStyle($this->style2);
135 $this->skin->writeToXMLFile($this->system_style_config->getCustomizingSkinPath()."skin1/template-copy.xml");
136 $this->assertEquals(file_get_contents($this->system_style_config->getCustomizingSkinPath()."skin1/template-copy.xml")
137 ,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 $skin = ilSkinXML::parseFromXML($this->system_style_config->getCustomizingSkinPath()."skin1/template.xml");
143 $this->assertEquals($skin->asXML(),file_get_contents($this->system_style_config->getCustomizingSkinPath()."skin1/template.xml"));
144 }
145}
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.
global $DIC