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