ILIAS  release_8 Revision v8.24
ilSkinStyleLessFileTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once('libs/composer/vendor/autoload.php');
22
24{
25 public function testConstructAndRead(): void
26 {
27 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
28 $this->assertCount(14, $file->getItems());
29 }
30
31 public function testReadCorrectTypes(): void
32 {
33 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
34
35 $this->assertCount(2, $file->getCategories());
36 $this->assertCount(6, $file->getVariablesIds());
37 $this->assertCount(6, $file->getCommentsIds());
38 }
39
40 public function testGetVariableByName(): void
41 {
42 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
43
44 $expected_variable11 = new ilSystemStyleLessVariable(
45 'variable11',
46 'value11',
47 'comment variable 11',
48 'Category 1',
49 []
50 );
51 $expected_variable12 = new ilSystemStyleLessVariable(
52 'variable12',
53 'value12',
54 'comment variable 12',
55 'Category 1',
56 []
57 );
58 $expected_variable13 = new ilSystemStyleLessVariable(
59 'variable13',
60 '@variable11',
61 'comment variable 13',
62 'Category 1',
63 ['variable11']
64 );
65
66 $expected_variable21 = new ilSystemStyleLessVariable(
67 'variable21',
68 '@variable11',
69 'comment variable 21',
70 'Category 2',
71 ['variable11']
72 );
73 $expected_variable22 = new ilSystemStyleLessVariable(
74 'variable22',
75 'value21',
76 'comment variable 22',
77 'Category 2',
78 []
79 );
80 $expected_variable23 = new ilSystemStyleLessVariable(
81 'variable23',
82 '@variable21',
83 'comment variable 23',
84 'Category 2',
85 ['variable21']
86 );
87
88 $this->assertEquals($expected_variable11, $file->getVariableByName('variable11'));
89 $this->assertEquals($expected_variable12, $file->getVariableByName('variable12'));
90 $this->assertEquals($expected_variable13, $file->getVariableByName('variable13'));
91
92 $this->assertEquals($expected_variable21, $file->getVariableByName('variable21'));
93 $this->assertEquals($expected_variable22, $file->getVariableByName('variable22'));
94 $this->assertEquals($expected_variable23, $file->getVariableByName('variable23'));
95 }
96
97 public function testGetCategory(): void
98 {
99 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
100
101 $expected_category1 = new ilSystemStyleLessCategory('Category 1', 'Comment Category 1');
102 $expected_category2 = new ilSystemStyleLessCategory('Category 2', 'Comment Category 2');
103 $expected_categories = [$expected_category1, $expected_category2];
104
105 $this->assertEquals($expected_categories, $file->getCategories());
106 }
107
108 public function testGetItems(): void
109 {
110 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
111
112 $expected_category1 = new ilSystemStyleLessCategory('Category 1', 'Comment Category 1');
113 $expected_comment2 = new ilSystemStyleLessComment('// Random Section 1');
114 $expected_comment3 = new ilSystemStyleLessComment('');
115 $expected_variable11 = new ilSystemStyleLessVariable(
116 'variable11',
117 'value11',
118 'comment variable 11',
119 'Category 1',
120 []
121 );
122 $expected_variable12 = new ilSystemStyleLessVariable(
123 'variable12',
124 'value12',
125 'comment variable 12',
126 'Category 1',
127 []
128 );
129 $expected_variable13 = new ilSystemStyleLessVariable(
130 'variable13',
131 '@variable11',
132 'comment variable 13',
133 'Category 1',
134 ['variable11']
135 );
136 $expected_comment4 = new ilSystemStyleLessComment('');
137 $expected_category2 = new ilSystemStyleLessCategory('Category 2', 'Comment Category 2');
138 $expected_comment6 = new ilSystemStyleLessComment('');
140 $expected_comment8 = new ilSystemStyleLessComment('');
141 $expected_variable21 = new ilSystemStyleLessVariable(
142 'variable21',
143 '@variable11',
144 'comment variable 21',
145 'Category 2',
146 ['variable11']
147 );
148 $expected_variable22 = new ilSystemStyleLessVariable(
149 'variable22',
150 'value21',
151 'comment variable 22',
152 'Category 2',
153 []
154 );
155 $expected_variable23 = new ilSystemStyleLessVariable(
156 'variable23',
157 '@variable21',
158 'comment variable 23',
159 'Category 2',
160 ['variable21']
161 );
162
163 $expected_items = [$expected_category1,
164 $expected_comment2,
165 $expected_comment3,
166 $expected_variable11,
167 $expected_variable12,
168 $expected_variable13,
169 $expected_comment4,
170 $expected_category2,
171 $expected_comment6,
172 $expected_comment7,
173 $expected_comment8,
174 $expected_variable21,
175 $expected_variable22,
176 $expected_variable23
177 ];
178
179 $this->assertEquals($expected_items, $file->getItems());
180 }
181
182 public function testGetContent(): void
183 {
184 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
185 $expected_content = file_get_contents($this->container->getLessVariablesFilePath($this->style->getId()));
186 $this->assertEquals($expected_content, $file->getContent());
187 }
188
189 public function testReadWriteDouble(): void
190 {
191 $expected_content = file_get_contents($this->container->getLessVariablesFilePath($this->style->getId()));
192
193 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
194 $file->write();
195 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
196 $file->write();
197 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
198
199 $this->assertEquals($expected_content, $file->getContent());
200 }
201
202 public function testReadWriteDoubleFullLess(): void
203 {
204 $expected_content = file_get_contents($this->container->getSkinDirectory() . 'full.less');
205
206 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'full.less');
207 $file->write();
208 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'full.less');
209 $file->write();
210 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'full.less');
211
212 $this->assertEquals($expected_content, $file->getContent());
213 }
214
215 public function testChangeVariable(): void
216 {
217 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
218 $variable = $file->getVariableByName('variable11');
219 $variable->setValue('newvalue11');
220
221 $expected_category1 = new ilSystemStyleLessCategory('Category 1', 'Comment Category 1');
222 $expected_comment2 = new ilSystemStyleLessComment('// Random Section 1');
223 $expected_comment3 = new ilSystemStyleLessComment('');
224 $expected_variable11 = new ilSystemStyleLessVariable(
225 'variable11',
226 'newvalue11',
227 'comment variable 11',
228 'Category 1',
229 []
230 );
231 $expected_variable12 = new ilSystemStyleLessVariable(
232 'variable12',
233 'value12',
234 'comment variable 12',
235 'Category 1',
236 []
237 );
238 $expected_variable13 = new ilSystemStyleLessVariable(
239 'variable13',
240 '@variable11',
241 'comment variable 13',
242 'Category 1',
243 ['variable11']
244 );
245 $expected_comment4 = new ilSystemStyleLessComment('');
246 $expected_category2 = new ilSystemStyleLessCategory('Category 2', 'Comment Category 2');
247 $expected_comment6 = new ilSystemStyleLessComment('');
249 $expected_comment8 = new ilSystemStyleLessComment('');
250 $expected_variable21 = new ilSystemStyleLessVariable(
251 'variable21',
252 '@variable11',
253 'comment variable 21',
254 'Category 2',
255 ['variable11']
256 );
257 $expected_variable22 = new ilSystemStyleLessVariable(
258 'variable22',
259 'value21',
260 'comment variable 22',
261 'Category 2',
262 []
263 );
264 $expected_variable23 = new ilSystemStyleLessVariable(
265 'variable23',
266 '@variable21',
267 'comment variable 23',
268 'Category 2',
269 ['variable21']
270 );
271
272 $expected_items = [$expected_category1,
273 $expected_comment2,
274 $expected_comment3,
275 $expected_variable11,
276 $expected_variable12,
277 $expected_variable13,
278 $expected_comment4,
279 $expected_category2,
280 $expected_comment6,
281 $expected_comment7,
282 $expected_comment8,
283 $expected_variable21,
284 $expected_variable22,
285 $expected_variable23
286 ];
287
288 $this->assertEquals($expected_items, $file->getItems());
289 }
290
291 public function testAddAndWriteItems(): void
292 {
293 $empty_less = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'empty.less');
294
295 $expected_category1 = new ilSystemStyleLessCategory('Category 1', 'Comment Category 1');
296 $expected_comment2 = new ilSystemStyleLessComment('// Random Section 1');
297 $expected_comment3 = new ilSystemStyleLessComment('');
298 $expected_variable11 = new ilSystemStyleLessVariable(
299 'variable11',
300 'value11',
301 'comment variable 11',
302 'Category 1',
303 []
304 );
305 $expected_variable12 = new ilSystemStyleLessVariable(
306 'variable12',
307 'value12',
308 'comment variable 12',
309 'Category 1',
310 []
311 );
312 $expected_variable13 = new ilSystemStyleLessVariable(
313 'variable13',
314 '@variable11',
315 'comment variable 13',
316 'Category 1',
317 ['variable11']
318 );
319 $expected_comment4 = new ilSystemStyleLessComment('');
320 $expected_category2 = new ilSystemStyleLessCategory('Category 2', 'Comment Category 2');
321 $expected_comment6 = new ilSystemStyleLessComment('');
323 $expected_comment8 = new ilSystemStyleLessComment('');
324 $expected_variable21 = new ilSystemStyleLessVariable(
325 'variable21',
326 '@variable11',
327 'comment variable 21',
328 'Category 2',
329 ['variable11']
330 );
331 $expected_variable22 = new ilSystemStyleLessVariable(
332 'variable22',
333 'value21',
334 'comment variable 22',
335 'Category 2',
336 []
337 );
338 $expected_variable23 = new ilSystemStyleLessVariable(
339 'variable23',
340 '@variable21',
341 'comment variable 23',
342 'Category 2',
343 ['variable21']
344 );
345
346 $expected_items = [$expected_category1,
347 $expected_comment2,
348 $expected_comment3,
349 $expected_variable11,
350 $expected_variable12,
351 $expected_variable13,
352 $expected_comment4,
353 $expected_category2,
354 $expected_comment6,
355 $expected_comment7,
356 $expected_comment8,
357 $expected_variable21,
358 $expected_variable22,
359 $expected_variable23
360 ];
361
362 foreach ($expected_items as $item) {
363 $empty_less->addItem($item);
364 }
365 $empty_less->write();
366
367 $new_less = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'empty.less');
368 $this->assertEquals($expected_items, $new_less->getItems());
369 }
370
371 public function testGetVariableReferences(): void
372 {
373 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
374
375 $this->assertEquals(['variable13', 'variable21'], $file->getReferencesToVariable('variable11'));
376 $this->assertEquals([], $file->getReferencesToVariable('variable12'));
377 $this->assertEquals([], $file->getReferencesToVariable('variable13'));
378
379 $this->assertEquals(['variable23'], $file->getReferencesToVariable('variable21'));
380 $this->assertEquals([], $file->getReferencesToVariable('variable22'));
381 $this->assertEquals([], $file->getReferencesToVariable('variable23'));
382 }
383
384 public function testGetRefAndCommentAsString(): void
385 {
386 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
387
388 $this->assertEquals(
389 'comment variable 11</br>Usage: variable13; variable21; ',
390 $file->getRefAndCommentAsString('variable11', 'Usage:')
391 );
392 $this->assertEquals('comment variable 12', $file->getRefAndCommentAsString('variable12', 'Usage:'));
393 $this->assertEquals('comment variable 13', $file->getRefAndCommentAsString('variable13', 'Usage:'));
394
395 $this->assertEquals('comment variable 21</br>Usage: variable23; ', $file->getRefAndCommentAsString('variable21', 'Usage:'));
396 $this->assertEquals('comment variable 22', $file->getRefAndCommentAsString('variable22', 'Usage:'));
397 $this->assertEquals('comment variable 23', $file->getRefAndCommentAsString('variable23', 'Usage:'));
398 }
399
400 public function testGetVariableReferencesAsString(): void
401 {
402 $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
403
404 $this->assertEquals('variable13; variable21; ', $file->getReferencesToVariableAsString('variable11'));
405 $this->assertEquals('', $file->getReferencesToVariableAsString('variable12'));
406 $this->assertEquals('', $file->getReferencesToVariableAsString('variable13'));
407
408 $this->assertEquals('variable23; ', $file->getReferencesToVariableAsString('variable21'));
409 $this->assertEquals('', $file->getReferencesToVariableAsString('variable22'));
410 $this->assertEquals('', $file->getReferencesToVariableAsString('variable23'));
411 }
412
413 public function testReadCorrectTypesEdgeCases(): void
414 {
415 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'edge-cases.less');
416
417 $this->assertCount(3, $file->getCategories());
418 $this->assertCount(7, $file->getVariablesIds());
419 $this->assertCount(4, $file->getCommentsIds());
420 }
421
422 public function testGetItemsEdgeCases(): void
423 {
424 $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'edge-cases.less');
425
426 $expected_comment1 = new ilSystemStyleLessComment('// No Category to start');
427 $expected_comment2 = new ilSystemStyleLessComment('');
428
429 $expected_variable11 = new ilSystemStyleLessVariable(
430 'variableNoCategory1',
431 'value11',
432 'comment variable 11',
433 '',
434 []
435 );
436 $expected_variable12 = new ilSystemStyleLessVariable('variableNoCategory1NoComment', 'value12', '', '', []);
437
438 $expected_category1 = new ilSystemStyleLessCategory('Category 1 no valid section', '');
439
440 $expected_variable21 = new ilSystemStyleLessVariable(
441 'variableNoValidSection1',
442 'value21',
443 '',
444 'Category 1 no valid section',
445 []
446 );
447 $expected_variable22 = new ilSystemStyleLessVariable(
448 'variableNoValidSection2',
449 'value22',
450 'comment',
451 'Category 1 no valid section',
452 []
453 );
454
455 $expected_comment3 = new ilSystemStyleLessComment('');
456
457 $expected_category2 = new ilSystemStyleLessCategory('Category 2', 'Comment Category 2');
458
459 $expected_variable31 = new ilSystemStyleLessVariable(
460 'regular',
461 'value',
462 'Hard references id',
463 'Category 2',
464 []
465 );
466 $expected_variable32 = new ilSystemStyleLessVariable(
467 'variable21',
468 'floor((@regular * 1.6)) * lighten(@regular, 20%)',
469 'Hard references',
470 'Category 2',
471 ['regular']
472 );
473
474 $expected_comment4 = new ilSystemStyleLessComment('');
475
476 $expected_category3 = new ilSystemStyleLessCategory('Category 3', 'No Section Between');
477 $expected_variable41 = new ilSystemStyleLessVariable('variable3', 'value3', '', 'Category 3', []);
478
479 $expected_items = [$expected_comment1,
480 $expected_comment2,
481 $expected_variable11,
482 $expected_variable12,
483 $expected_category1,
484 $expected_variable21,
485 $expected_variable22,
486 $expected_comment3,
487 $expected_category2,
488 $expected_variable31,
489 $expected_variable32,
490 $expected_comment4,
491 $expected_category3,
492 $expected_variable41
493 ];
494
495 $this->assertEquals($expected_items, $file->getItems());
496 }
497}
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.