ILIAS  release_8 Revision v8.24
ilSkinFactoryTest.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 protected ilSkin $skin;
29
30 protected function setUp(): void
31 {
32 parent::setUp();
33
34 if (!defined('PATH_TO_LESSC')) {
35 if (file_exists('ilias.ini.php')) {
36 $ini = parse_ini_file('ilias.ini.php', true);
37 define('PATH_TO_LESSC', $ini['tools']['lessc'] ?? '');
38 } else {
39 define('PATH_TO_LESSC', '');
40 }
41 }
42
43 $this->skin = new ilSkin('skin1', 'skin 1');
44
45 $this->style1 = new ilSkinStyle('style1', 'Style 1');
46 $this->style1->setCssFile('style1css');
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('style2css');
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
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);
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() . '/style1image'));
98 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1sound'));
99 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1font'));
100 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css.css'));
101 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css.less'));
102 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css-variables.less'));
103
104 $this->assertEquals($skin->getName() . ' Copy', $skin_copy->getName());
105 $this->assertEquals('0.1', $skin_copy->getVersion());
106 }
107
108 public function testCopySkinWithInjectedName(): void
109 {
110 $container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);
112 $container_copy = $this->factory->copyFromSkinStyleContainer($container, $this->file_system, $this->message_stack, 'inject');
113 $skin_copy = $container_copy->getSkin();
114
115 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'inject'));
116 $this->assertEquals($skin->getName() . ' inject', $skin_copy->getName());
117 $this->assertEquals('0.1', $skin_copy->getVersion());
118 }
119
120 public function testImportSkin(): void
121 {
122 $this->markTestSkipped('Unzipping is not possible due to missing dependencies');
123 return;
124
125 if (!defined('PATH_TO_ZIP')) {
126 if (file_exists('ilias.ini.php')) {
127 $ini = parse_ini_file('ilias.ini.php', true);
128 define('PATH_TO_ZIP', $ini['tools']['zip']);
129 } elseif (is_executable('/usr/bin/zip')) {
130 define('PATH_TO_ZIP', '/usr/bin/zip');
131 } else {
132 define('PATH_TO_ZIP', '');
133 }
134 }
135
136 if (!defined('PATH_TO_UNZIP')) {
137 if (file_exists('ilias.ini.php')) {
138 $ini = parse_ini_file('ilias.ini.php', true);
139 define('PATH_TO_UNZIP', $ini['tools']['unzip']);
140 } elseif (is_executable('/usr/bin/unzip')) {
141 define('PATH_TO_UNZIP', '/usr/bin/unzip');
142 } else {
143 define('PATH_TO_UNZIP', '');
144 }
145 }
146
147 //Only perform this test, if an unzip path has been found.
148 if (PATH_TO_UNZIP != '' && PATH_TO_ZIP != "") {
149 $container = $this->factory->skinStyleContainerFromId($this->skin->getId(), $this->message_stack);
151
152 $this->assertFalse(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'Copy'));
153
154 $container_import = $this->factory->skinStyleContainerFromZip(
156 $this->skin->getId() . '.zip',
157 $this->message_stack
158 );
159 $skin_copy = $container_import->getSkin();
160
161 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin->getId() . 'Copy'));
162 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId()));
163 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1image'));
164 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1sound'));
165 $this->assertTrue(is_dir($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1font'));
166 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css.css'));
167 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css.less'));
168 $this->assertTrue(is_file($this->system_style_config->getCustomizingSkinPath() . $skin_copy->getId() . '/style1css-variables.less'));
169 } else {
170 $this->markTestIncomplete('No unzip has been detected on the system');
171 }
172 }
173}
ilSkinFactory $factory
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
createTempZip()
Creates a temp zip file.
ilSkin holds an manages the basic data of a skin as provide by the template of the skin.
asXML()
Stores the skin and all it's styles as xml.
ilSkinStyleContainer $container
global $DIC
Definition: feed.php:28
$ini
Definition: raiseError.php:4