[TASk] Remove dummy files from ext:saltedpasswords
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Utility / ConfigurationUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Configuration utility test
29 *
30 */
31 class ConfigurationUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
32
33 /**
34 * @test
35 */
36 public function getCurrentConfigurationReturnsExtensionConfigurationAsValuedConfiguration() {
37 /** @var $configurationUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
38 $configurationUtility = $this->getMock(
39 'TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility',
40 array('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
41 );
42 $configurationUtility
43 ->expects($this->once())
44 ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
45 ->will($this->returnValue(array()));
46 $extensionKey = uniqid('some-extension');
47
48 $currentConfiguration = array(
49 'key1' => 'value1',
50 'key2.' => array(
51 'subkey1' => 'value2'
52 )
53 );
54
55 $expected = array(
56 'key1' => array(
57 'value' => 'value1',
58 ),
59 'key2.subkey1' => array(
60 'value' => 'value2',
61 ),
62 );
63
64 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey]= array();
65 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey] = serialize($currentConfiguration);
66 $actual = $configurationUtility->getCurrentConfiguration($extensionKey);
67 $this->assertEquals($expected, $actual);
68 }
69
70 /**
71 * @test
72 */
73 public function getDefaultConfigurationFromExtConfTemplateAsValuedArrayReturnsExpectedExampleArray() {
74 /** @var $configurationUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
75 $configurationUtility = $this->getAccessibleMock(
76 'TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility',
77 array('getDefaultConfigurationRawString')
78 );
79 $configurationUtility
80 ->expects($this->once())
81 ->method('getDefaultConfigurationRawString')
82 ->will($this->returnValue('foo'));
83
84 $tsStyleConfig = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\ConfigurationForm');
85
86 $objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
87 $configurationUtility->_set('objectManager', $objectManagerMock);
88 $objectManagerMock
89 ->expects($this->once())
90 ->method('get')
91 ->with('TYPO3\\CMS\\Core\\TypoScript\\ConfigurationForm')
92 ->will($this->returnValue($tsStyleConfig));
93
94 $constants = array(
95 'checkConfigurationFE' => array(
96 'cat' => 'basic',
97 'subcat_name' => 'enable',
98 'subcat' => 'a/enable/z',
99 'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
100 'label' => 'Frontend configuration check',
101 'name' => 'checkConfigurationFE',
102 'value' => '0',
103 'default_value' => '0'
104 ),
105 'BE.forceSalted' => array(
106 'cat' => 'advancedbackend',
107 'subcat' => 'x/z',
108 'type' => 'boolean',
109 'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
110 'name' => 'BE.forceSalted',
111 'value' => '0',
112 'default_value' => '0'
113 )
114 );
115 $tsStyleConfig
116 ->expects($this->once())
117 ->method('ext_initTSstyleConfig')
118 ->will($this->returnValue($constants));
119
120 $setupTsConstantEditor = array(
121 'advancedbackend.' => array(
122 'description' => '<span style="background:red; padding:1px 2px; color:#fff; font-weight:bold;">1</span> Install tool has hardcoded md5 hashing, enabling this setting will prevent use of a install-tool-created BE user.<br />Currently same is for changin password with user setup module unless you use pending patch!',
123 1 => 'BE.forceSalted'
124 )
125 );
126 $tsStyleConfig->setup['constants']['TSConstantEditor.'] = $setupTsConstantEditor;
127
128 $expected = array(
129 'checkConfigurationFE' => array(
130 'cat' => 'basic',
131 'subcat_name' => 'enable',
132 'subcat' => 'a/enable/z',
133 'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
134 'label' => 'Frontend configuration check',
135 'name' => 'checkConfigurationFE',
136 'value' => '0',
137 'default_value' => '0',
138 'subcat_label' => 'Enable features',
139 ),
140 'BE.forceSalted' => array(
141 'cat' => 'advancedbackend',
142 'subcat' => 'x/z',
143 'type' => 'boolean',
144 'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
145 'name' => 'BE.forceSalted',
146 'value' => '0',
147 'default_value' => '0',
148 'highlight' => 1,
149 ),
150 '__meta__' => array(
151 'advancedbackend' => array(
152 'highlightText' => '<span style="background:red; padding:1px 2px; color:#fff; font-weight:bold;">1</span> Install tool has hardcoded md5 hashing, enabling this setting will prevent use of a install-tool-created BE user.<br />Currently same is for changin password with user setup module unless you use pending patch!'
153 )
154 )
155 );
156
157 $result = $configurationUtility->getDefaultConfigurationFromExtConfTemplateAsValuedArray(uniqid('some_extension'));
158 $this->assertEquals($expected, $result);
159 }
160
161 /**
162 * Data provider for convertValuedToNestedConfiguration
163 *
164 * @return array
165 */
166 public function convertValuedToNestedConfigurationDataProvider() {
167 return array(
168 'plain array' => array(
169 array(
170 'first' => array(
171 'value' => 'value1'
172 ),
173 'second' => array(
174 'value' => 'value2'
175 )
176 ),
177 array(
178 'first' => 'value1',
179 'second' => 'value2'
180 )
181 ),
182 'nested value with 2 levels' => array(
183 array(
184 'first.firstSub' => array(
185 'value' => 'value1'
186 ),
187 'second.secondSub' => array(
188 'value' => 'value2'
189 )
190 ),
191 array(
192 'first.' => array(
193 'firstSub' => 'value1'
194 ),
195 'second.' => array(
196 'secondSub' => 'value2'
197 )
198 )
199 ),
200 'nested value with 3 levels' => array(
201 array(
202 'first.firstSub.firstSubSub' => array(
203 'value' => 'value1'
204 ),
205 'second.secondSub.secondSubSub' => array(
206 'value' => 'value2'
207 )
208 ),
209 array(
210 'first.' => array(
211 'firstSub.' => array(
212 'firstSubSub' => 'value1'
213 )
214 ),
215 'second.' => array(
216 'secondSub.' => array(
217 'secondSubSub' => 'value2'
218 )
219 )
220 )
221 ),
222 'mixed nested value with 2 levels' => array(
223 array(
224 'first' => array(
225 'value' => 'firstValue'
226 ),
227 'first.firstSub' => array(
228 'value' => 'value1'
229 ),
230 'second.secondSub' => array(
231 'value' => 'value2'
232 )
233 ),
234 array(
235 'first' => 'firstValue',
236 'first.' => array(
237 'firstSub' => 'value1'
238 ),
239 'second.' => array(
240 'secondSub' => 'value2'
241 )
242 )
243 )
244 );
245 }
246
247 /**
248 * @test
249 * @dataProvider convertValuedToNestedConfigurationDataProvider
250 *
251 * @param array $configuration
252 * @param array $expected
253 * @return void
254 */
255 public function convertValuedToNestedConfiguration(array $configuration, array $expected) {
256 /** @var $fixture \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
257 $fixture = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility');
258 $this->assertEquals($expected, $fixture->convertValuedToNestedConfiguration($configuration));
259 }
260
261 /**
262 * Data provider for convertNestedToValuedConfiguration
263 *
264 * @return array
265 */
266 public function convertNestedToValuedConfigurationDataProvider() {
267 return array(
268 'plain array' => array(
269 array(
270 'first' => 'value1',
271 'second' => 'value2'
272 ),
273 array(
274 'first' => array('value' => 'value1'),
275 'second' => array('value' => 'value2'),
276 )
277 ),
278 'two levels' => array(
279 array(
280 'first.' => array('firstSub' => 'value1'),
281 'second.' => array('firstSub' => 'value2'),
282 ),
283 array(
284 'first.firstSub' => array('value' => 'value1'),
285 'second.firstSub' => array('value' => 'value2'),
286 )
287 ),
288 'three levels' => array(
289 array(
290 'first.' => array('firstSub.' => array('firstSubSub' => 'value1')),
291 'second.' => array('firstSub.' => array('firstSubSub' => 'value2'))
292 ),
293 array(
294 'first.firstSub.firstSubSub' => array('value' => 'value1'),
295 'second.firstSub.firstSubSub' => array('value' => 'value2'),
296 )
297 ),
298 'mixed' => array(
299 array(
300 'first.' => array('firstSub' => 'value1'),
301 'second.' => array('firstSub.' => array('firstSubSub' => 'value2')),
302 'third' => 'value3'
303 ),
304 array(
305 'first.firstSub' => array('value' => 'value1'),
306 'second.firstSub.firstSubSub' => array('value' => 'value2'),
307 'third' => array('value' => 'value3')
308 )
309 )
310 );
311 }
312
313 /**
314 * @test
315 * @dataProvider convertNestedToValuedConfigurationDataProvider
316 *
317 * @param array $configuration
318 * @param array $expected
319 * @return void
320 */
321 public function convertNestedToValuedConfiguration(array $configuration, array $expected) {
322 /** @var $fixture \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
323 $fixture = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility');
324 $this->assertEquals($expected, $fixture->convertNestedToValuedConfiguration($configuration));
325 }
326 }
327 ?>