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