ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilSkinFactoryTest.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  protected ilSkin $skin;
26  protected ilSkinStyle $style1;
27  protected ilSkinStyle $style2;
29 
30  protected function setUp(): void
31  {
32  parent::setUp();
33 
34  if (!defined('PATH_TO_SCSS')) {
35  if (file_exists('ilias.ini.php')) {
36  $ini = parse_ini_file('ilias.ini.php', true);
37  define('PATH_TO_SCSS', $ini['tools']['lessc'] ?? '');
38  } else {
39  define('PATH_TO_SCSS', '');
40  }
41  }
42 
43  $this->skin = new ilSkin('skin1', 'skin 1');
44 
45  $this->style1 = new ilSkinStyle('style1', 'Style 1');
46  $this->style1->setCssFile('style1');
47  $this->style1->setImageDirectory('style1image');
48  $this->style1->setSoundDirectory('style1sound');
49  $this->style1->setFontDirectory('style1font');
50 
51  $this->style2 = new ilSkinStyle('style2', 'Style 2');
52  $this->style2->setCssFile('style2');
53  $this->style2->setImageDirectory('style2image');
54  $this->style2->setSoundDirectory('style2sound');
55  $this->style2->setFontDirectory('style2font');
56 
57  $this->factory = new ilSkinFactory($this->lng, $this->system_style_config);
58 
59  global $DIC;
60 
61  $DIC = new ilSystemStyleDICMock();
62  $DIC['tpl'] = $this->getMockBuilder(ilGlobalTemplateInterface::class)->getMock();
63  }
64 
65  public function testSkinFromXML(): void
66  {
67  $factory = new ilSkinFactory($this->lng);
68  $skin = $factory->skinFromXML($this->system_style_config->getCustomizingSkinPath() . 'skin1/template.xml');
69  $this->assertEquals(
70  $skin->asXML(),
71  file_get_contents($this->system_style_config->getCustomizingSkinPath() . 'skin1/template.xml')
72  );
73  }
74 
75  public function testSkinStyleContainerFromId(): void
76  {
77  $container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);
78  $this->assertEquals($container->getSkin()->getId(), $this->skin->getId());
79  $this->assertEquals($container->getSkin()->getName(), $this->skin->getName());
80 
81  $this->assertEquals($container->getSkin()->getStyle($this->style1->getId()), $this->style1);
82  $this->assertEquals($container->getSkin()->getStyle($this->style2->getId()), $this->style2);
83  }
84 
85  public function testCopySkin(): void
86  {
87  $container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);
88  $skin = $container->getSkin();
89 
90  $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'Copy'));
91 
92  $container_copy = $this->factory->copyFromSkinStyleContainer($container, $this->file_system, $this->message_stack);
93  $skin_copy = $container_copy->getSkin();
94 
95  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'Copy'));
96  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
97  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/style1image'));
98  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/style1sound'));
99  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/style1font'));
100  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/style1.css'));
101  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/style1.scss'));
102  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/010-settings/variables1.scss'));
103  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1/010-settings/variables2.scss'));
104 
105  $this->assertEquals($skin->getName() . ' Copy', $skin_copy->getName());
106  $this->assertEquals('0.1', $skin_copy->getVersion());
107  }
108 
109  public function testCopySkinWithInjectedName(): void
110  {
111  $container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);
112  $skin = $container->getSkin();
113  $container_copy = $this->factory->copyFromSkinStyleContainer($container, $this->file_system, $this->message_stack, 'inject');
114  $skin_copy = $container_copy->getSkin();
115 
116  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'inject'));
117  $this->assertEquals($skin->getName() . ' inject', $skin_copy->getName());
118  $this->assertEquals('0.1', $skin_copy->getVersion());
119  }
120 
121  public function testImportSkin(): void
122  {
123  $this->markTestSkipped('This test is skipped, because it is not possible to create a zip file, which can be unzipped at the moment in Test-Context. The test is violating thr policy to access only directories which are known to the LegacyPathHelper.');
124 
125 
126  if (!defined('PATH_TO_ZIP')) {
127  if (file_exists('ilias.ini.php')) {
128  $ini = parse_ini_file('ilias.ini.php', true);
129  define('PATH_TO_ZIP', $ini['tools']['zip']);
130  } elseif (is_executable('/usr/bin/zip')) {
131  define('PATH_TO_ZIP', '/usr/bin/zip');
132  } else {
133  define('PATH_TO_ZIP', '');
134  }
135  }
136 
137  if (!defined('PATH_TO_UNZIP')) {
138  if (file_exists('ilias.ini.php')) {
139  $ini = parse_ini_file('ilias.ini.php', true);
140  define('PATH_TO_UNZIP', $ini['tools']['unzip']);
141  } elseif (is_executable('/usr/bin/unzip')) {
142  define('PATH_TO_UNZIP', '/usr/bin/unzip');
143  } else {
144  define('PATH_TO_UNZIP', '');
145  }
146  }
147 
148  //Only perform this test, if an unzip path has been found.
149  if (PATH_TO_UNZIP != '' && PATH_TO_ZIP != "") {
150  $container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);
151  $skin = $container->getSkin();
152 
153  $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'Copy'));
154 
155  $container_import = $this->factory->skinStyleContainerFromZip(
157  $this->skin->getId() . '.zip',
159  );
160  $skin_copy = $container_import->getSkin();
161 
162  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'Copy'));
163  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
164  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1image'));
165  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1sound'));
166  $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1font'));
167  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css.css'));
168  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css.less'));
169  $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css-variables.less'));
170  } else {
171  $this->markTestIncomplete('No unzip has been detected on the system');
172  }
173  }
174 }
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
asXML()
Stores the skin and all it&#39;s styles as xml.
global $DIC
Definition: feed.php:28
ilSkinFactory $factory
ilSystemStyleMessageStack $message_stack
createTempZip()
Creates a temp zip file.
ilSkinStyleContainer $container
$ini
Definition: raiseError.php:4
ilSkin holds an manages the basic data of a skin as provide by the template of the skin...