ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSystemStyleStyleLessFileTest.php
Go to the documentation of this file.
1<?php
2include_once("Services/Style/System/classes/Utilities/class.ilSkinStyleXML.php");
3include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
4include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
5include_once("./Services/Style/System/classes/Less/class.ilSystemStyleLessFile.php");
6include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleConfigMock.php");
7include_once("Services/Style/System/test/fixtures/mocks/ilSystemStyleDICMock.php");
8
15
16
21
25 protected $container;
26
30 protected $style;
31
32 protected $save_dic = null;
33
34 protected function setUp()
35 {
36 global $DIC;
37
38 $this->save_dic = $DIC;
40
41 $this->system_style_config = new ilSystemStyleConfigMock();
42
43 mkdir($this->system_style_config->test_skin_temp_path);
44 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
45
46 $this->container = ilSystemStyleSkinContainer::generateFromId("skin1", null, $this->system_style_config);
47 $this->style = $this->container->getSkin()->getStyle("style1");
48 }
49
50 protected function tearDown()
51 {
52 global $DIC;
54
55 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
56 }
57
58 public function testConstructAndRead() {
59 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
60 $this->assertEquals(14,count($file->getItems()));
61 }
62
63 public function testReadCorrectTypes() {
64 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
65
66 $this->assertEquals(2,count($file->getCategories()));
67 $this->assertEquals(6,count($file->getVariablesIds()));
68 $this->assertEquals(6,count($file->getCommentsIds()));
69 }
70
71
72 public function testGetVariableByName(){
73 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
74
75 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "value11", "comment variable 11","Category 1", []);
76 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12","Category 1", []);
77 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13","Category 1", ["variable11"]);
78
79 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21","Category 2", ["variable11"]);
80 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22","Category 2", []);
81 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23","Category 2", ["variable21"]);
82
83 $this->assertEquals($expected_variable11,$file->getVariableByName("variable11"));
84 $this->assertEquals($expected_variable12,$file->getVariableByName("variable12"));
85 $this->assertEquals($expected_variable13,$file->getVariableByName("variable13"));
86
87 $this->assertEquals($expected_variable21,$file->getVariableByName("variable21"));
88 $this->assertEquals($expected_variable22,$file->getVariableByName("variable22"));
89 $this->assertEquals($expected_variable23,$file->getVariableByName("variable23"));
90 }
91
92 public function testGetCategory(){
93 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
94
95 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
96 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
97 $expected_categories = [$expected_category1,$expected_category2];
98
99 $this->assertEquals($expected_categories,$file->getCategories());
100 }
101
102 public function testGetItems(){
103 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
104
105 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
106 $expected_comment2 = new ilSystemStyleLessComment("// Random Section 1");
107 $expected_comment3 = new ilSystemStyleLessComment("");
108 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "value11", "comment variable 11","Category 1", []);
109 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12","Category 1", []);
110 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13","Category 1", ["variable11"]);
111 $expected_comment4 = new ilSystemStyleLessComment("");
112 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
113 $expected_comment6 = new ilSystemStyleLessComment("/**");
114 $expected_comment7 = new ilSystemStyleLessComment(" Random Section 2 **/");
115 $expected_comment8 = new ilSystemStyleLessComment("");
116 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21","Category 2", ["variable11"]);
117 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22","Category 2", []);
118 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23","Category 2", ["variable21"]);
119
120 $expected_items = [$expected_category1,
121 $expected_comment2,$expected_comment3,
122 $expected_variable11,$expected_variable12,$expected_variable13,
123 $expected_comment4,
124 $expected_category2,
125 $expected_comment6,$expected_comment7,$expected_comment8,
126 $expected_variable21,$expected_variable22,$expected_variable23];
127
128 $this->assertEquals($expected_items,$file->getItems());
129 }
130
131 public function testGetContent(){
132 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
133 $expected_content = file_get_contents($this->container->getLessVariablesFilePath($this->style->getId()));
134 $this->assertEquals($expected_content,$file->getContent());
135 }
136
137 public function testReadWriteDouble(){
138 $expected_content = file_get_contents($this->container->getLessVariablesFilePath($this->style->getId()));
139
140 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
141 $file->write();
142 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
143 $file->write();
144 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
145
146 $this->assertEquals($expected_content,$file->getContent());
147 }
148
150 $expected_content = file_get_contents($this->container->getSkinDirectory()."full.less");
151
152 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory()."full.less");
153 $file->write();
154 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory()."full.less");
155 $file->write();
156 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory()."full.less");
157
158 $this->assertEquals($expected_content,$file->getContent());
159 }
160
161 public function testChangeVariable(){
162 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
163 $variable = $file->getVariableByName("variable11");
164 $variable->setValue("newvalue11");
165
166 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
167 $expected_comment2 = new ilSystemStyleLessComment("// Random Section 1");
168 $expected_comment3 = new ilSystemStyleLessComment("");
169 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "newvalue11", "comment variable 11","Category 1", []);
170 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12","Category 1", []);
171 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13","Category 1", ["variable11"]);
172 $expected_comment4 = new ilSystemStyleLessComment("");
173 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
174 $expected_comment6 = new ilSystemStyleLessComment("/**");
175 $expected_comment7 = new ilSystemStyleLessComment(" Random Section 2 **/");
176 $expected_comment8 = new ilSystemStyleLessComment("");
177 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21","Category 2", ["variable11"]);
178 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22","Category 2", []);
179 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23","Category 2", ["variable21"]);
180
181 $expected_items = [$expected_category1,
182 $expected_comment2,$expected_comment3,
183 $expected_variable11,$expected_variable12,$expected_variable13,
184 $expected_comment4,
185 $expected_category2,
186 $expected_comment6,$expected_comment7,$expected_comment8,
187 $expected_variable21,$expected_variable22,$expected_variable23];
188
189 $this->assertEquals($expected_items,$file->getItems());
190
191 }
192
193 public function testAddAndWriteItems(){
194 $empty_less = new ilSystemStyleLessFile($this->container->getSkinDirectory()."empty.less");
195
196 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
197 $expected_comment2 = new ilSystemStyleLessComment("// Random Section 1");
198 $expected_comment3 = new ilSystemStyleLessComment("");
199 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "value11", "comment variable 11","Category 1", []);
200 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12","Category 1", []);
201 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13","Category 1", ["variable11"]);
202 $expected_comment4 = new ilSystemStyleLessComment("");
203 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
204 $expected_comment6 = new ilSystemStyleLessComment("/**");
205 $expected_comment7 = new ilSystemStyleLessComment(" Random Section 2 **/");
206 $expected_comment8 = new ilSystemStyleLessComment("");
207 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21","Category 2", ["variable11"]);
208 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22","Category 2", []);
209 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23","Category 2", ["variable21"]);
210
211 $expected_items = [$expected_category1,
212 $expected_comment2,$expected_comment3,
213 $expected_variable11,$expected_variable12,$expected_variable13,
214 $expected_comment4,
215 $expected_category2,
216 $expected_comment6,$expected_comment7,$expected_comment8,
217 $expected_variable21,$expected_variable22,$expected_variable23];
218
219 foreach($expected_items as $item){
220 $empty_less->addItem($item);
221 }
222 $empty_less->write();
223
224 $new_less = new ilSystemStyleLessFile($this->container->getSkinDirectory()."empty.less");
225 $this->assertEquals($expected_items,$new_less->getItems());
226 }
227
228 public function testGetVariableReferences(){
229 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
230
231 $this->assertEquals(["variable13","variable21"],$file->getReferencesToVariable("variable11"));
232 $this->assertEquals([],$file->getReferencesToVariable("variable12"));
233 $this->assertEquals([],$file->getReferencesToVariable("variable13"));
234
235 $this->assertEquals(["variable23"],$file->getReferencesToVariable("variable21"));
236 $this->assertEquals([],$file->getReferencesToVariable("variable22"));
237 $this->assertEquals([],$file->getReferencesToVariable("variable23"));
238 }
239
241 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
242
243 $this->assertEquals("variable13; variable21; ",$file->getReferencesToVariableAsString("variable11"));
244 $this->assertEquals("",$file->getReferencesToVariableAsString("variable12"));
245 $this->assertEquals("",$file->getReferencesToVariableAsString("variable13"));
246
247 $this->assertEquals("variable23; ",$file->getReferencesToVariableAsString("variable21"));
248 $this->assertEquals("",$file->getReferencesToVariableAsString("variable22"));
249 $this->assertEquals("",$file->getReferencesToVariableAsString("variable23"));
250 }
251
253 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory()."edge-cases.less");
254
255 $this->assertEquals(3,count($file->getCategories()));
256 $this->assertEquals(7,count($file->getVariablesIds()));
257 $this->assertEquals(4,count($file->getCommentsIds()));
258 }
259
260 public function testGetItemsEdgeCases(){
261 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory()."edge-cases.less");
262
263 $expected_comment1 = new ilSystemStyleLessComment("// No Category to start");
264 $expected_comment2 = new ilSystemStyleLessComment("");
265
266 $expected_variable11 = new ilSystemStyleLessVariable("variableNoCategory1", "value11", "comment variable 11","", []);
267 $expected_variable12 = new ilSystemStyleLessVariable("variableNoCategory1NoComment", "value12", "","", []);
268
269 $expected_category1 = new ilSystemStyleLessCategory("Category 1 no valid section", "");
270
271 $expected_variable21 = new ilSystemStyleLessVariable("variableNoValidSection1", "value21", "","Category 1 no valid section", []);
272 $expected_variable22 = new ilSystemStyleLessVariable("variableNoValidSection2", "value22", "comment","Category 1 no valid section", []);
273
274 $expected_comment3 = new ilSystemStyleLessComment("");
275
276 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
277
278 $expected_variable31 = new ilSystemStyleLessVariable("regular", "value", "Hard references id","Category 2", []);
279 $expected_variable32 = new ilSystemStyleLessVariable("variable21", "floor((@regular * 1.6)) * lighten(@regular, 20%)", "Hard references","Category 2", ["regular"]);
280
281 $expected_comment4 = new ilSystemStyleLessComment("");
282
283 $expected_category3 = new ilSystemStyleLessCategory("Category 3", "No Section Between");
284 $expected_variable41 = new ilSystemStyleLessVariable("variable3", "value3", "","Category 3", []);
285
286 $expected_items = [$expected_comment1,$expected_comment2,
287 $expected_variable11,$expected_variable12,
288 $expected_category1,$expected_variable21,$expected_variable22,
289 $expected_comment3,
290 $expected_category2,$expected_variable31,$expected_variable32,
291 $expected_comment4,
292 $expected_category3,$expected_variable41];
293
294 $this->assertEquals($expected_items,$file->getItems());
295 }
296}
An exception for terminatinating execution or to throw for unit testing.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Class ilLanguageMock.
Capsules data of a less category in the variables to less file.
Capsules all data which is neither part of a variable or category structure in the less file.
static recursiveRemoveDir($dir)
Recursive delete of a folder.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
static xCopy($src, $dest)
Recursive copy of a folder.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC