ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSystemStyleStyleLessFileTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_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 testGetVariableReferencesAsString(): void
385  {
386  $file = new ilSystemStyleLessFile($this->container->getLessVariablesFilePath($this->style->getId()));
387 
388  $this->assertEquals('variable13; variable21; ', $file->getReferencesToVariableAsString('variable11'));
389  $this->assertEquals('', $file->getReferencesToVariableAsString('variable12'));
390  $this->assertEquals('', $file->getReferencesToVariableAsString('variable13'));
391 
392  $this->assertEquals('variable23; ', $file->getReferencesToVariableAsString('variable21'));
393  $this->assertEquals('', $file->getReferencesToVariableAsString('variable22'));
394  $this->assertEquals('', $file->getReferencesToVariableAsString('variable23'));
395  }
396 
397  public function testReadCorrectTypesEdgeCases(): void
398  {
399  $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'edge-cases.less');
400 
401  $this->assertCount(3, $file->getCategories());
402  $this->assertCount(7, $file->getVariablesIds());
403  $this->assertCount(4, $file->getCommentsIds());
404  }
405 
406  public function testGetItemsEdgeCases(): void
407  {
408  $file = new ilSystemStyleLessFile($this->container->getSkinDirectory() . 'edge-cases.less');
409 
410  $expected_comment1 = new ilSystemStyleLessComment('// No Category to start');
411  $expected_comment2 = new ilSystemStyleLessComment('');
412 
413  $expected_variable11 = new ilSystemStyleLessVariable(
414  'variableNoCategory1',
415  'value11',
416  'comment variable 11',
417  '',
418  []
419  );
420  $expected_variable12 = new ilSystemStyleLessVariable('variableNoCategory1NoComment', 'value12', '', '', []);
421 
422  $expected_category1 = new ilSystemStyleLessCategory('Category 1 no valid section', '');
423 
424  $expected_variable21 = new ilSystemStyleLessVariable(
425  'variableNoValidSection1',
426  'value21',
427  '',
428  'Category 1 no valid section',
429  []
430  );
431  $expected_variable22 = new ilSystemStyleLessVariable(
432  'variableNoValidSection2',
433  'value22',
434  'comment',
435  'Category 1 no valid section',
436  []
437  );
438 
439  $expected_comment3 = new ilSystemStyleLessComment('');
440 
441  $expected_category2 = new ilSystemStyleLessCategory('Category 2', 'Comment Category 2');
442 
443  $expected_variable31 = new ilSystemStyleLessVariable(
444  'regular',
445  'value',
446  'Hard references id',
447  'Category 2',
448  []
449  );
450  $expected_variable32 = new ilSystemStyleLessVariable(
451  'variable21',
452  'floor((@regular * 1.6)) * lighten(@regular, 20%)',
453  'Hard references',
454  'Category 2',
455  ['regular']
456  );
457 
458  $expected_comment4 = new ilSystemStyleLessComment('');
459 
460  $expected_category3 = new ilSystemStyleLessCategory('Category 3', 'No Section Between');
461  $expected_variable41 = new ilSystemStyleLessVariable('variable3', 'value3', '', 'Category 3', []);
462 
463  $expected_items = [$expected_comment1,
464  $expected_comment2,
465  $expected_variable11,
466  $expected_variable12,
467  $expected_category1,
468  $expected_variable21,
469  $expected_variable22,
470  $expected_comment3,
471  $expected_category2,
472  $expected_variable31,
473  $expected_variable32,
474  $expected_comment4,
475  $expected_category3,
476  $expected_variable41
477  ];
478 
479  $this->assertEquals($expected_items, $file->getItems());
480  }
481 }
write()
Write the complete file back to the file system (including comments and random content) ...
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...