ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
17
22
26 protected $container;
27
31 protected $style;
32
33 protected $save_dic = null;
34
35 protected function setUp()
36 {
37 global $DIC;
38
39 $this->save_dic = $DIC;
41
42 $this->system_style_config = new ilSystemStyleConfigMock();
43
44 mkdir($this->system_style_config->test_skin_temp_path);
45 ilSystemStyleSkinContainer::xCopy($this->system_style_config->test_skin_original_path, $this->system_style_config->test_skin_temp_path);
46
47 $this->container = ilSystemStyleSkinContainer::generateFromId("skin1", null, $this->system_style_config);
48 $this->style = $this->container->getSkin()->getStyle("style1");
49 }
50
51 protected function tearDown()
52 {
53 global $DIC;
55
56 ilSystemStyleSkinContainer::recursiveRemoveDir($this->system_style_config->test_skin_temp_path);
57 }
58
59 public function testConstructAndRead()
60 {
61 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
62 $this->assertEquals(14, count($file->getItems()));
63 }
64
65 public function testReadCorrectTypes()
66 {
67 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
68
69 $this->assertEquals(2, count($file->getCategories()));
70 $this->assertEquals(6, count($file->getVariablesIds()));
71 $this->assertEquals(6, count($file->getCommentsIds()));
72 }
73
74
75 public function testGetVariableByName()
76 {
77 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
78
79 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "value11", "comment variable 11", "Category 1", []);
80 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12", "Category 1", []);
81 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13", "Category 1", ["variable11"]);
82
83 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21", "Category 2", ["variable11"]);
84 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22", "Category 2", []);
85 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23", "Category 2", ["variable21"]);
86
87 $this->assertEquals($expected_variable11, $file->getVariableByName("variable11"));
88 $this->assertEquals($expected_variable12, $file->getVariableByName("variable12"));
89 $this->assertEquals($expected_variable13, $file->getVariableByName("variable13"));
90
91 $this->assertEquals($expected_variable21, $file->getVariableByName("variable21"));
92 $this->assertEquals($expected_variable22, $file->getVariableByName("variable22"));
93 $this->assertEquals($expected_variable23, $file->getVariableByName("variable23"));
94 }
95
96 public function testGetCategory()
97 {
98 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
99
100 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
101 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
102 $expected_categories = [$expected_category1,$expected_category2];
103
104 $this->assertEquals($expected_categories, $file->getCategories());
105 }
106
107 public function testGetItems()
108 {
109 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
110
111 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
112 $expected_comment2 = new ilSystemStyleLessComment("// Random Section 1");
113 $expected_comment3 = new ilSystemStyleLessComment("");
114 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "value11", "comment variable 11", "Category 1", []);
115 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12", "Category 1", []);
116 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13", "Category 1", ["variable11"]);
117 $expected_comment4 = new ilSystemStyleLessComment("");
118 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
119 $expected_comment6 = new ilSystemStyleLessComment("/**");
120 $expected_comment7 = new ilSystemStyleLessComment(" Random Section 2 **/");
121 $expected_comment8 = new ilSystemStyleLessComment("");
122 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21", "Category 2", ["variable11"]);
123 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22", "Category 2", []);
124 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23", "Category 2", ["variable21"]);
125
126 $expected_items = [$expected_category1,
127 $expected_comment2,$expected_comment3,
128 $expected_variable11,$expected_variable12,$expected_variable13,
129 $expected_comment4,
130 $expected_category2,
131 $expected_comment6,$expected_comment7,$expected_comment8,
132 $expected_variable21,$expected_variable22,$expected_variable23];
133
134 $this->assertEquals($expected_items, $file->getItems());
135 }
136
137 public function testGetContent()
138 {
139 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
140 $expected_content = file_get_contents($this->container->getLessVariablesFilePath($this->style->getId()));
141 $this->assertEquals($expected_content, $file->getContent());
142 }
143
144 public function testReadWriteDouble()
145 {
146 $expected_content = file_get_contents($this->container->getLessVariablesFilePath($this->style->getId()));
147
148 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
149 $file->write();
150 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
151 $file->write();
152 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
153
154 $this->assertEquals($expected_content, $file->getContent());
155 }
156
158 {
159 $expected_content = file_get_contents($this->container->getSkinDirectory() . "full.less");
160
161 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "full.less");
162 $file->write();
163 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "full.less");
164 $file->write();
165 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "full.less");
166
167 $this->assertEquals($expected_content, $file->getContent());
168 }
169
170 public function testChangeVariable()
171 {
172 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
173 $variable = $file->getVariableByName("variable11");
174 $variable->setValue("newvalue11");
175
176 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
177 $expected_comment2 = new ilSystemStyleLessComment("// Random Section 1");
178 $expected_comment3 = new ilSystemStyleLessComment("");
179 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "newvalue11", "comment variable 11", "Category 1", []);
180 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12", "Category 1", []);
181 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13", "Category 1", ["variable11"]);
182 $expected_comment4 = new ilSystemStyleLessComment("");
183 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
184 $expected_comment6 = new ilSystemStyleLessComment("/**");
185 $expected_comment7 = new ilSystemStyleLessComment(" Random Section 2 **/");
186 $expected_comment8 = new ilSystemStyleLessComment("");
187 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21", "Category 2", ["variable11"]);
188 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22", "Category 2", []);
189 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23", "Category 2", ["variable21"]);
190
191 $expected_items = [$expected_category1,
192 $expected_comment2,$expected_comment3,
193 $expected_variable11,$expected_variable12,$expected_variable13,
194 $expected_comment4,
195 $expected_category2,
196 $expected_comment6,$expected_comment7,$expected_comment8,
197 $expected_variable21,$expected_variable22,$expected_variable23];
198
199 $this->assertEquals($expected_items, $file->getItems());
200 }
201
202 public function testAddAndWriteItems()
203 {
204 $empty_less = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "empty.less");
205
206 $expected_category1 = new ilSystemStyleLessCategory("Category 1", "Comment Category 1");
207 $expected_comment2 = new ilSystemStyleLessComment("// Random Section 1");
208 $expected_comment3 = new ilSystemStyleLessComment("");
209 $expected_variable11 = new ilSystemStyleLessVariable("variable11", "value11", "comment variable 11", "Category 1", []);
210 $expected_variable12 = new ilSystemStyleLessVariable("variable12", "value12", "comment variable 12", "Category 1", []);
211 $expected_variable13 = new ilSystemStyleLessVariable("variable13", "@variable11", "comment variable 13", "Category 1", ["variable11"]);
212 $expected_comment4 = new ilSystemStyleLessComment("");
213 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
214 $expected_comment6 = new ilSystemStyleLessComment("/**");
215 $expected_comment7 = new ilSystemStyleLessComment(" Random Section 2 **/");
216 $expected_comment8 = new ilSystemStyleLessComment("");
217 $expected_variable21 = new ilSystemStyleLessVariable("variable21", "@variable11", "comment variable 21", "Category 2", ["variable11"]);
218 $expected_variable22 = new ilSystemStyleLessVariable("variable22", "value21", "comment variable 22", "Category 2", []);
219 $expected_variable23 = new ilSystemStyleLessVariable("variable23", "@variable21", "comment variable 23", "Category 2", ["variable21"]);
220
221 $expected_items = [$expected_category1,
222 $expected_comment2,$expected_comment3,
223 $expected_variable11,$expected_variable12,$expected_variable13,
224 $expected_comment4,
225 $expected_category2,
226 $expected_comment6,$expected_comment7,$expected_comment8,
227 $expected_variable21,$expected_variable22,$expected_variable23];
228
229 foreach ($expected_items as $item) {
230 $empty_less->addItem($item);
231 }
232 $empty_less->write();
233
234 $new_less = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "empty.less");
235 $this->assertEquals($expected_items, $new_less->getItems());
236 }
237
239 {
240 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
241
242 $this->assertEquals(["variable13","variable21"], $file->getReferencesToVariable("variable11"));
243 $this->assertEquals([], $file->getReferencesToVariable("variable12"));
244 $this->assertEquals([], $file->getReferencesToVariable("variable13"));
245
246 $this->assertEquals(["variable23"], $file->getReferencesToVariable("variable21"));
247 $this->assertEquals([], $file->getReferencesToVariable("variable22"));
248 $this->assertEquals([], $file->getReferencesToVariable("variable23"));
249 }
250
252 {
253 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
254
255 $this->assertEquals("variable13; variable21; ", $file->getReferencesToVariableAsString("variable11"));
256 $this->assertEquals("", $file->getReferencesToVariableAsString("variable12"));
257 $this->assertEquals("", $file->getReferencesToVariableAsString("variable13"));
258
259 $this->assertEquals("variable23; ", $file->getReferencesToVariableAsString("variable21"));
260 $this->assertEquals("", $file->getReferencesToVariableAsString("variable22"));
261 $this->assertEquals("", $file->getReferencesToVariableAsString("variable23"));
262 }
263
265 {
266 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "edge-cases.less");
267
268 $this->assertEquals(3, count($file->getCategories()));
269 $this->assertEquals(7, count($file->getVariablesIds()));
270 $this->assertEquals(4, count($file->getCommentsIds()));
271 }
272
273 public function testGetItemsEdgeCases()
274 {
275 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . "edge-cases.less");
276
277 $expected_comment1 = new ilSystemStyleLessComment("// No Category to start");
278 $expected_comment2 = new ilSystemStyleLessComment("");
279
280 $expected_variable11 = new ilSystemStyleLessVariable("variableNoCategory1", "value11", "comment variable 11", "", []);
281 $expected_variable12 = new ilSystemStyleLessVariable("variableNoCategory1NoComment", "value12", "", "", []);
282
283 $expected_category1 = new ilSystemStyleLessCategory("Category 1 no valid section", "");
284
285 $expected_variable21 = new ilSystemStyleLessVariable("variableNoValidSection1", "value21", "", "Category 1 no valid section", []);
286 $expected_variable22 = new ilSystemStyleLessVariable("variableNoValidSection2", "value22", "comment", "Category 1 no valid section", []);
287
288 $expected_comment3 = new ilSystemStyleLessComment("");
289
290 $expected_category2 = new ilSystemStyleLessCategory("Category 2", "Comment Category 2");
291
292 $expected_variable31 = new ilSystemStyleLessVariable("regular", "value", "Hard references id", "Category 2", []);
293 $expected_variable32 = new ilSystemStyleLessVariable("variable21", "floor((@regular * 1.6)) * lighten(@regular, 20%)", "Hard references", "Category 2", ["regular"]);
294
295 $expected_comment4 = new ilSystemStyleLessComment("");
296
297 $expected_category3 = new ilSystemStyleLessCategory("Category 3", "No Section Between");
298 $expected_variable41 = new ilSystemStyleLessVariable("variable3", "value3", "", "Category 3", []);
299
300 $expected_items = [$expected_comment1,$expected_comment2,
301 $expected_variable11,$expected_variable12,
302 $expected_category1,$expected_variable21,$expected_variable22,
303 $expected_comment3,
304 $expected_category2,$expected_variable31,$expected_variable32,
305 $expected_comment4,
306 $expected_category3,$expected_variable41];
307
308 $this->assertEquals($expected_items, $file->getItems());
309 }
310}
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.
global $DIC
Definition: saml.php:7