ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilSystemStyleStyleScssTest.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 ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
28  $this->assertCount(32, $file->getItems());
29  }
30 
31  public function testReadCorrectTypes(): void
32  {
33  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
34 
35  $this->assertCount(5, $file->getCategories());
36  $this->assertCount(12, $file->getVariables());
37  $this->assertCount(32, $file->getItems());
38  }
39 
40  public function testGetVariableByName(): void
41  {
42  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
43 
44  $expected_variable111 = new ilSystemStyleScssVariable(
45  'variable111',
46  'value111',
47  'comment variable 111',
48  'Category 11',
49  []
50  );
51  $expected_variable112 = new ilSystemStyleScssVariable(
52  'variable112',
53  'value112',
54  'comment variable 112',
55  'Category 11',
56  []
57  );
58  $expected_variable113 = new ilSystemStyleScssVariable(
59  'variable113',
60  '$variable111',
61  'comment variable 113',
62  'Category 11',
63  ['variable111']
64  );
65 
66  $expected_variable121 = new ilSystemStyleScssVariable(
67  'variable121',
68  '$variable111',
69  'comment variable 121',
70  'Category 12',
71  ['variable111']
72  );
73  $expected_variable122 = new ilSystemStyleScssVariable(
74  'variable122',
75  'value121',
76  'comment variable 122',
77  'Category 12',
78  []
79  );
80  $expected_variable123 = new ilSystemStyleScssVariable(
81  'variable123',
82  '$variable121',
83  'comment variable 123',
84  'Category 12',
85  ['variable121']
86  );
87  $expected_variable211 = new ilSystemStyleScssVariable(
88  'variable211',
89  'value211',
90  'comment variable 211',
91  'Category 21',
92  []
93  );
94  $expected_variable212 = new ilSystemStyleScssVariable(
95  'variable212',
96  'value212',
97  'comment variable 212',
98  'Category 21',
99  []
100  );
101  $expected_variable213 = new ilSystemStyleScssVariable(
102  'variable213',
103  '$variable211',
104  'comment variable 213',
105  'Category 21',
106  ['variable211']
107  );
108 
109  $expected_variable221 = new ilSystemStyleScssVariable(
110  'variable221',
111  '$variable211',
112  'comment variable 221',
113  'Category 22',
114  ['variable211']
115  );
116  $expected_variable222 = new ilSystemStyleScssVariable(
117  'variable222',
118  'value221',
119  'comment variable 222',
120  'Category 22',
121  []
122  );
123  $expected_variable223 = new ilSystemStyleScssVariable(
124  'variable223',
125  '$variable221',
126  'comment variable 223',
127  'Category 22',
128  ['variable221']
129  );
130  $this->assertEquals($expected_variable111, $file->getVariableByName('variable111'));
131  $this->assertEquals($expected_variable112, $file->getVariableByName('variable112'));
132  $this->assertEquals($expected_variable113, $file->getVariableByName('variable113'));
133 
134  $this->assertEquals($expected_variable121, $file->getVariableByName('variable121'));
135  $this->assertEquals($expected_variable122, $file->getVariableByName('variable122'));
136  $this->assertEquals($expected_variable123, $file->getVariableByName('variable123'));
137 
138  $this->assertEquals($expected_variable211, $file->getVariableByName('variable211'));
139  $this->assertEquals($expected_variable212, $file->getVariableByName('variable212'));
140  $this->assertEquals($expected_variable213, $file->getVariableByName('variable213'));
141 
142  $this->assertEquals($expected_variable221, $file->getVariableByName('variable221'));
143  $this->assertEquals($expected_variable222, $file->getVariableByName('variable222'));
144  $this->assertEquals($expected_variable223, $file->getVariableByName('variable223'));
145  }
146 
147  public function testGetCategory(): void
148  {
149  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
150  $expected_categories = [];
151 
152  $expected_categories['Category 11'] = new ilSystemStyleScssCategory('Category 11', 'Comment Category 11');
153  $expected_categories['Category 12'] = new ilSystemStyleScssCategory('Category 12', 'Comment Category 12');
154  $expected_categories['Category 21'] = new ilSystemStyleScssCategory('Category 21', 'Comment Category 21');
155  $expected_categories['Category 22'] = new ilSystemStyleScssCategory('Category 22', 'Comment Category 22');
156  $expected_categories['Settings'] = new ilSystemStyleScssCategory('Settings', 'Settings Comment');
157 
158  $this->assertEquals($expected_categories, $file->getCategories());
159  }
160 
161  public function testGetItems(): void
162  {
163  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
164 
165  $expected_settings = new ilSystemStyleScssCategory('Settings', 'Settings Comment');
166  $expected_settings_comment1 = new ilSystemStyleScssComment('');
167  $expected_settings_comment2 = new ilSystemStyleScssComment('@forward "./variables1";');
168  $expected_settings_comment3 = new ilSystemStyleScssComment('@forward "./variables2";');
169  $expected_category21 = new ilSystemStyleScssCategory('Category 21', 'Comment Category 21');
170  $expected_comment22 = new ilSystemStyleScssComment('// Random Section 21');
171  $expected_comment23 = new ilSystemStyleScssComment('');
172  $expected_variable211 = new ilSystemStyleScssVariable(
173  'variable211',
174  'value211',
175  'comment variable 211',
176  'Category 21',
177  []
178  );
179  $expected_variable212 = new ilSystemStyleScssVariable(
180  'variable212',
181  'value212',
182  'comment variable 212',
183  'Category 21',
184  []
185  );
186  $expected_variable213 = new ilSystemStyleScssVariable(
187  'variable213',
188  '$variable211',
189  'comment variable 213',
190  'Category 21',
191  ['variable211']
192  );
193  $expected_comment24 = new ilSystemStyleScssComment('');
194  $expected_category22 = new ilSystemStyleScssCategory('Category 22', 'Comment Category 22');
195  $expected_comment26 = new ilSystemStyleScssComment('');
197  $expected_comment28 = new ilSystemStyleScssComment('');
198  $expected_variable221 = new ilSystemStyleScssVariable(
199  'variable221',
200  '$variable211',
201  'comment variable 221',
202  'Category 22',
203  ['variable211']
204  );
205  $expected_variable222 = new ilSystemStyleScssVariable(
206  'variable222',
207  'value221',
208  'comment variable 222',
209  'Category 22',
210  []
211  );
212  $expected_variable223 = new ilSystemStyleScssVariable(
213  'variable223',
214  '$variable221',
215  'comment variable 223',
216  'Category 22',
217  ['variable221']
218  );
219 
220  $expected_category11 = new ilSystemStyleScssCategory('Category 11', 'Comment Category 11');
221  $expected_comment12 = new ilSystemStyleScssComment('// Random Section 11');
222  $expected_comment13 = new ilSystemStyleScssComment('');
223  $expected_variable111 = new ilSystemStyleScssVariable(
224  'variable111',
225  'value111',
226  'comment variable 111',
227  'Category 11',
228  []
229  );
230  $expected_variable112 = new ilSystemStyleScssVariable(
231  'variable112',
232  'value112',
233  'comment variable 112',
234  'Category 11',
235  []
236  );
237  $expected_variable113 = new ilSystemStyleScssVariable(
238  'variable113',
239  '$variable111',
240  'comment variable 113',
241  'Category 11',
242  ['variable111']
243  );
244  $expected_comment14 = new ilSystemStyleScssComment('');
245  $expected_category12 = new ilSystemStyleScssCategory('Category 12', 'Comment Category 12');
246  $expected_comment16 = new ilSystemStyleScssComment('');
248  $expected_comment18 = new ilSystemStyleScssComment('');
249  $expected_variable121 = new ilSystemStyleScssVariable(
250  'variable121',
251  '$variable111',
252  'comment variable 121',
253  'Category 12',
254  ['variable111']
255  );
256  $expected_variable122 = new ilSystemStyleScssVariable(
257  'variable122',
258  'value121',
259  'comment variable 122',
260  'Category 12',
261  []
262  );
263  $expected_variable123 = new ilSystemStyleScssVariable(
264  'variable123',
265  '$variable121',
266  'comment variable 123',
267  'Category 12',
268  ['variable121']
269  );
270 
271  $expected_items = [
272  $expected_settings,
273  $expected_settings_comment1,
274  $expected_settings_comment2,
275  $expected_settings_comment3,
276  $expected_category11,
277  $expected_comment12,
278  $expected_comment13,
279  $expected_variable111,
280  $expected_variable112,
281  $expected_variable113,
282  $expected_comment14,
283  $expected_category12,
284  $expected_comment16,
285  $expected_comment17,
286  $expected_comment18,
287  $expected_variable121,
288  $expected_variable122,
289  $expected_variable123,
290  $expected_category21,
291  $expected_comment22,
292  $expected_comment23,
293  $expected_variable211,
294  $expected_variable212,
295  $expected_variable213,
296  $expected_comment24,
297  $expected_category22,
298  $expected_comment26,
299  $expected_comment27,
300  $expected_comment28,
301  $expected_variable221,
302  $expected_variable222,
303  $expected_variable223
304  ];
305 
306  $this->assertEquals($expected_items, $file->getItems());
307  }
308 
309  public function testGetContent(): void
310  {
311  $settings = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
312  $expected_content = $this->getAllContentOfFolder($this->container->getScssSettingsPath($this->style->getId()));
313  $this->assertEquals($expected_content, $settings->getContent());
314  }
315 
316  public function testGetVariablesForDelosOverride(): void
317  {
318  $settings = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
319  $expected_content = '$variable111: globals.$variable111,
320 $variable112: globals.$variable112,
321 $variable113: globals.$variable113,
322 $variable121: globals.$variable121,
323 $variable122: globals.$variable122,
324 $variable123: globals.$variable123,
325 $variable211: globals.$variable211,
326 $variable212: globals.$variable212,
327 $variable213: globals.$variable213,
328 $variable221: globals.$variable221,
329 $variable222: globals.$variable222,
330 $variable223: globals.$variable223,
331 ';
332  $this->assertEquals($expected_content, $settings->getVariablesForDelosOverride());
333  }
334 
335  public function testReadWriteDouble(): void
336  {
337  $expected_content = $this->getAllContentOfFolder($this->container->getScssSettingsPath($this->style->getId()));
338 
339  $settings = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
340  $settings->write();
341  $settings = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
342  $settings->write();
343  $settings = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
344 
345  $this->assertEquals($expected_content, $settings->getContent());
346  }
347 
348  public function testReadWriteDoubleRealFolderSCSS(): void
349  {
350  $expected_content = $this->getAllContentOfFolder($this->container->getSkinDirectory() . 'scss-test/real-folder');
351 
352  $settings = new ilSystemStyleScssSettings($this->container->getSkinDirectory() . 'scss-test/real-folder');
353  $settings->write();
354  $settings = new ilSystemStyleScssSettings($this->container->getSkinDirectory() . 'scss-test/real-folder');
355  $settings->write();
356  $settings = new ilSystemStyleScssSettings($this->container->getSkinDirectory() . 'scss-test/real-folder');
357 
358  // !defaults will get removed in this process
359  $expected_content = str_replace(" !default", "", $expected_content);
360  $this->assertEquals($expected_content, $settings->getContent());
361  }
362 
363  public function testChangeVariable(): void
364  {
365  $settings = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
366  $variable = $settings->getVariableByName('variable111');
367  $variable->setValue('newvalue111');
368 
369  $expected_settings = new ilSystemStyleScssCategory('Settings', 'Settings Comment');
370  $expected_settings_comment1 = new ilSystemStyleScssComment('');
371  $expected_settings_comment2 = new ilSystemStyleScssComment('@forward "./variables1";');
372  $expected_settings_comment3 = new ilSystemStyleScssComment('@forward "./variables2";');
373  $expected_category11 = new ilSystemStyleScssCategory('Category 11', 'Comment Category 11');
374  $expected_comment12 = new ilSystemStyleScssComment('// Random Section 11');
375  $expected_comment13 = new ilSystemStyleScssComment('');
376  $expected_variable111 = new ilSystemStyleScssVariable(
377  'variable111',
378  'newvalue111',
379  'comment variable 111',
380  'Category 11',
381  []
382  );
383  $expected_variable112 = new ilSystemStyleScssVariable(
384  'variable112',
385  'value112',
386  'comment variable 112',
387  'Category 11',
388  []
389  );
390  $expected_variable113 = new ilSystemStyleScssVariable(
391  'variable113',
392  '$variable111',
393  'comment variable 113',
394  'Category 11',
395  ['variable111']
396  );
397  $expected_comment14 = new ilSystemStyleScssComment('');
398  $expected_category12 = new ilSystemStyleScssCategory('Category 12', 'Comment Category 12');
399  $expected_comment16 = new ilSystemStyleScssComment('');
401  $expected_comment18 = new ilSystemStyleScssComment('');
402  $expected_variable121 = new ilSystemStyleScssVariable(
403  'variable121',
404  '$variable111',
405  'comment variable 121',
406  'Category 12',
407  ['variable111']
408  );
409  $expected_variable122 = new ilSystemStyleScssVariable(
410  'variable122',
411  'value121',
412  'comment variable 122',
413  'Category 12',
414  []
415  );
416  $expected_variable123 = new ilSystemStyleScssVariable(
417  'variable123',
418  '$variable121',
419  'comment variable 123',
420  'Category 12',
421  ['variable121']
422  );
423 
424  $expected_category21 = new ilSystemStyleScssCategory('Category 21', 'Comment Category 21');
425  $expected_comment22 = new ilSystemStyleScssComment('// Random Section 21');
426  $expected_comment23 = new ilSystemStyleScssComment('');
427  $expected_variable211 = new ilSystemStyleScssVariable(
428  'variable211',
429  'value211',
430  'comment variable 211',
431  'Category 21',
432  []
433  );
434  $expected_variable212 = new ilSystemStyleScssVariable(
435  'variable212',
436  'value212',
437  'comment variable 212',
438  'Category 21',
439  []
440  );
441  $expected_variable213 = new ilSystemStyleScssVariable(
442  'variable213',
443  '$variable211',
444  'comment variable 213',
445  'Category 21',
446  ['variable211']
447  );
448  $expected_comment24 = new ilSystemStyleScssComment('');
449  $expected_category22 = new ilSystemStyleScssCategory('Category 22', 'Comment Category 22');
450  $expected_comment26 = new ilSystemStyleScssComment('');
452  $expected_comment28 = new ilSystemStyleScssComment('');
453  $expected_variable221 = new ilSystemStyleScssVariable(
454  'variable221',
455  '$variable211',
456  'comment variable 221',
457  'Category 22',
458  ['variable211']
459  );
460  $expected_variable222 = new ilSystemStyleScssVariable(
461  'variable222',
462  'value221',
463  'comment variable 222',
464  'Category 22',
465  []
466  );
467  $expected_variable223 = new ilSystemStyleScssVariable(
468  'variable223',
469  '$variable221',
470  'comment variable 223',
471  'Category 22',
472  ['variable221']
473  );
474 
475 
476  $expected_items = [
477  $expected_settings,
478  $expected_settings_comment1,
479  $expected_settings_comment2,
480  $expected_settings_comment3,
481  $expected_category11,
482  $expected_comment12,
483  $expected_comment13,
484  $expected_variable111,
485  $expected_variable112,
486  $expected_variable113,
487  $expected_comment14,
488  $expected_category12,
489  $expected_comment16,
490  $expected_comment17,
491  $expected_comment18,
492  $expected_variable121,
493  $expected_variable122,
494  $expected_variable123,
495  $expected_category21,
496  $expected_comment22,
497  $expected_comment23,
498  $expected_variable211,
499  $expected_variable212,
500  $expected_variable213,
501  $expected_comment24,
502  $expected_category22,
503  $expected_comment26,
504  $expected_comment27,
505  $expected_comment28,
506  $expected_variable221,
507  $expected_variable222,
508  $expected_variable223
509  ];
510 
511  $this->assertEquals($expected_items, $settings->getItems());
512  }
513 
514 
515  public function testGetVariableReferences(): void
516  {
517  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
518 
519  $this->assertEquals(['variable113', 'variable121'], $file->getReferencesToVariable('variable111'));
520  $this->assertEquals([], $file->getReferencesToVariable('variable112'));
521  $this->assertEquals([], $file->getReferencesToVariable('variable113'));
522 
523  $this->assertEquals(['variable123'], $file->getReferencesToVariable('variable121'));
524  $this->assertEquals([], $file->getReferencesToVariable('variable122'));
525  $this->assertEquals([], $file->getReferencesToVariable('variable123'));
526  }
527 
528  public function testGetRefAndCommentAsString(): void
529  {
530  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
531 
532  $this->assertEquals(
533  'comment variable 111</br>Usage: variable113; variable121; ',
534  $file->getRefAndCommentAsString('variable111', 'Usage:')
535  );
536  $this->assertEquals('comment variable 112', $file->getRefAndCommentAsString('variable112', 'Usage:'));
537  $this->assertEquals('comment variable 113', $file->getRefAndCommentAsString('variable113', 'Usage:'));
538 
539  $this->assertEquals('comment variable 121</br>Usage: variable123; ', $file->getRefAndCommentAsString('variable121', 'Usage:'));
540  $this->assertEquals('comment variable 122', $file->getRefAndCommentAsString('variable122', 'Usage:'));
541  $this->assertEquals('comment variable 123', $file->getRefAndCommentAsString('variable123', 'Usage:'));
542  }
543 
544  public function testGetVariableReferencesAsString(): void
545  {
546  $file = new ilSystemStyleScssSettings($this->container->getScssSettingsPath($this->style->getId()));
547 
548  $this->assertEquals('variable113; variable121; ', $file->getReferencesToVariableAsString('variable111'));
549  $this->assertEquals('', $file->getReferencesToVariableAsString('variable112'));
550  $this->assertEquals('', $file->getReferencesToVariableAsString('variable113'));
551 
552  $this->assertEquals('variable123; ', $file->getReferencesToVariableAsString('variable121'));
553  $this->assertEquals('', $file->getReferencesToVariableAsString('variable122'));
554  $this->assertEquals('', $file->getReferencesToVariableAsString('variable123'));
555  }
556 
557  public function testReadCorrectTypesEdgeCases(): void
558  {
559  $file = new ilSystemStyleScssSettings($this->container->getSkinDirectory() . 'scss-test/edge-cases');
560 
561  $this->assertCount(3, $file->getCategories());
562  $this->assertCount(9, $file->getVariables());
563  $this->assertCount(16, $file->getItems());
564  }
565 
566  public function testGetItemsEdgeCases(): void
567  {
568  $file = new ilSystemStyleScssSettings($this->container->getSkinDirectory() . 'scss-test/edge-cases');
569 
570  $expected_comment1 = new ilSystemStyleScssComment('// No Category to start');
571  $expected_comment2 = new ilSystemStyleScssComment('');
572 
573  $expected_variable11 = new ilSystemStyleScssVariable(
574  'variableNoCategory1',
575  'value11',
576  'comment variable 11',
577  '',
578  []
579  );
580  $expected_variable12 = new ilSystemStyleScssVariable('variableNoCategory1NoComment', 'value12', '', '', []);
581 
582  $expected_category1 = new ilSystemStyleScssCategory('Category 1 no valid section', '');
583 
584  $expected_variable21 = new ilSystemStyleScssVariable(
585  'variableNoValidSection1',
586  'value21',
587  '',
588  'Category 1 no valid section',
589  []
590  );
591  $expected_variable22 = new ilSystemStyleScssVariable(
592  'variableNoValidSection2',
593  'value22',
594  'comment',
595  'Category 1 no valid section',
596  []
597  );
598 
599  $expected_comment3 = new ilSystemStyleScssComment('');
600 
601  $expected_category2 = new ilSystemStyleScssCategory('Category 2', 'Comment Category 2');
602 
603  $expected_variable31 = new ilSystemStyleScssVariable(
604  'regular',
605  'value',
606  'Hard references id',
607  'Category 2',
608  []
609  );
610  $expected_variable32 = new ilSystemStyleScssVariable(
611  'variable21',
612  'floor(($regular * 1.6)) * lighten($regular, 20%)',
613  'Hard references',
614  'Category 2',
615  ['regular']
616  );
617  $expected_variable33 = new ilSystemStyleScssVariable(
618  'variable22',
619  'color.scale($il-success-color, $lightness: 86%)',
620  'Hard references II, see #39792',
621  'Category 2',
622  ['il-success-color', 'lightness']
623  );
624  $expected_comment4 = new ilSystemStyleScssComment('');
625 
626  $expected_category3 = new ilSystemStyleScssCategory('Category 3', 'No Section Between');
627  $expected_variable41 = new ilSystemStyleScssVariable('variable3', 'value3', '', 'Category 3', []);
628  $expected_variable42 = new ilSystemStyleScssVariable('variable4', 'value4', '!default identifier', 'Category 3', []);
629 
630  $expected_items = [$expected_comment1,
631  $expected_comment2,
632  $expected_variable11,
633  $expected_variable12,
634  $expected_category1,
635  $expected_variable21,
636  $expected_variable22,
637  $expected_comment3,
638  $expected_category2,
639  $expected_variable31,
640  $expected_variable32,
641  $expected_variable33,
642  $expected_comment4,
643  $expected_category3,
644  $expected_variable41,
645  $expected_variable42
646  ];
647 
648  $this->assertEquals($expected_items, $file->getItems());
649  }
650 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Capsules data of a Scss category in the variables to Scss file.
write(string $new_path="")
Write the complete files back to the file system (including comments and random content) ...
Capsules all data which is neither part of a variable or category structure in the Scss file...
getAllContentOfFolder(string $directory)