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