TYPO3  7.6
ConfigurationUtilityTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 class ConfigurationUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
22 {
26  public function getCurrentConfigurationReturnsExtensionConfigurationAsValuedConfiguration()
27  {
29  $configurationUtility = $this->getMock(
30  \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class,
31  array('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
32  );
33  $configurationUtility
34  ->expects($this->once())
35  ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
36  ->will($this->returnValue(array()));
37  $extensionKey = $this->getUniqueId('some-extension');
38 
39  $currentConfiguration = array(
40  'key1' => 'value1',
41  'key2.' => array(
42  'subkey1' => 'value2'
43  )
44  );
45 
46  $expected = array(
47  'key1' => array(
48  'value' => 'value1',
49  ),
50  'key2.subkey1' => array(
51  'value' => 'value2',
52  ),
53  );
54 
55  $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey] = serialize($currentConfiguration);
56  $actual = $configurationUtility->getCurrentConfiguration($extensionKey);
57  $this->assertEquals($expected, $actual);
58  }
59 
63  public function getDefaultConfigurationFromExtConfTemplateAsValuedArrayReturnsExpectedExampleArray()
64  {
66  $configurationUtility = $this->getAccessibleMock(
67  \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class,
68  array('getDefaultConfigurationRawString', 'getExtensionPathInformation')
69  );
70  $configurationUtility
71  ->expects($this->once())
72  ->method('getDefaultConfigurationRawString')
73  ->will($this->returnValue('foo'));
74 
75  $configurationUtility
76  ->expects($this->once())
77  ->method('getExtensionPathInformation')
78  ->will($this->returnValue(null));
79 
80  $tsStyleConfig = $this->getMock(\TYPO3\CMS\Core\TypoScript\ConfigurationForm::class);
81 
82  $objectManagerMock = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
83  $configurationUtility->_set('objectManager', $objectManagerMock);
84  $objectManagerMock
85  ->expects($this->once())
86  ->method('get')
87  ->with(\TYPO3\CMS\Core\TypoScript\ConfigurationForm::class)
88  ->will($this->returnValue($tsStyleConfig));
89 
90  $constants = array(
91  'checkConfigurationFE' => array(
92  'cat' => 'basic',
93  'subcat_name' => 'enable',
94  'subcat' => 'a/enable/z',
95  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
96  'label' => 'Frontend configuration check',
97  'name' => 'checkConfigurationFE',
98  'value' => '0',
99  'default_value' => '0'
100  ),
101  'BE.forceSalted' => array(
102  'cat' => 'advancedbackend',
103  'subcat' => 'x/z',
104  'type' => 'boolean',
105  'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
106  'name' => 'BE.forceSalted',
107  'value' => '0',
108  'default_value' => '0'
109  )
110  );
111  $tsStyleConfig
112  ->expects($this->once())
113  ->method('ext_initTSstyleConfig')
114  ->will($this->returnValue($constants));
115 
116  $setupTsConstantEditor = array(
117  'advancedbackend.' => array(
118  '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!',
119  1 => 'BE.forceSalted'
120  )
121  );
122  $tsStyleConfig->setup['constants']['TSConstantEditor.'] = $setupTsConstantEditor;
123 
124  $expected = array(
125  'checkConfigurationFE' => array(
126  'cat' => 'basic',
127  'subcat_name' => 'enable',
128  'subcat' => 'a/enable/z',
129  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
130  'label' => 'Frontend configuration check',
131  'name' => 'checkConfigurationFE',
132  'value' => '0',
133  'default_value' => '0',
134  'subcat_label' => 'Enable features',
135  ),
136  'BE.forceSalted' => array(
137  'cat' => 'advancedbackend',
138  'subcat' => 'x/z',
139  'type' => 'boolean',
140  'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
141  'name' => 'BE.forceSalted',
142  'value' => '0',
143  'default_value' => '0',
144  'highlight' => 1,
145  ),
146  '__meta__' => array(
147  'advancedbackend' => array(
148  '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!'
149  )
150  )
151  );
152 
153  $result = $configurationUtility->getDefaultConfigurationFromExtConfTemplateAsValuedArray($this->getUniqueId('some_extension'));
154  $this->assertEquals($expected, $result);
155  }
156 
163  {
164  return array(
165  'plain array' => array(
166  array(
167  'first' => array(
168  'value' => 'value1'
169  ),
170  'second' => array(
171  'value' => 'value2'
172  )
173  ),
174  array(
175  'first' => 'value1',
176  'second' => 'value2'
177  )
178  ),
179  'nested value with 2 levels' => array(
180  array(
181  'first.firstSub' => array(
182  'value' => 'value1'
183  ),
184  'second.secondSub' => array(
185  'value' => 'value2'
186  )
187  ),
188  array(
189  'first.' => array(
190  'firstSub' => 'value1'
191  ),
192  'second.' => array(
193  'secondSub' => 'value2'
194  )
195  )
196  ),
197  'nested value with 3 levels' => array(
198  array(
199  'first.firstSub.firstSubSub' => array(
200  'value' => 'value1'
201  ),
202  'second.secondSub.secondSubSub' => array(
203  'value' => 'value2'
204  )
205  ),
206  array(
207  'first.' => array(
208  'firstSub.' => array(
209  'firstSubSub' => 'value1'
210  )
211  ),
212  'second.' => array(
213  'secondSub.' => array(
214  'secondSubSub' => 'value2'
215  )
216  )
217  )
218  ),
219  'mixed nested value with 2 levels' => array(
220  array(
221  'first' => array(
222  'value' => 'firstValue'
223  ),
224  'first.firstSub' => array(
225  'value' => 'value1'
226  ),
227  'second.secondSub' => array(
228  'value' => 'value2'
229  )
230  ),
231  array(
232  'first' => 'firstValue',
233  'first.' => array(
234  'firstSub' => 'value1'
235  ),
236  'second.' => array(
237  'secondSub' => 'value2'
238  )
239  )
240  )
241  );
242  }
243 
252  public function convertValuedToNestedConfiguration(array $configuration, array $expected)
253  {
255  $subject = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class, array('dummy'), array(), '', false);
256  $this->assertEquals($expected, $subject->convertValuedToNestedConfiguration($configuration));
257  }
258 
265  {
266  return array(
267  'plain array' => array(
268  array(
269  'first' => 'value1',
270  'second' => 'value2'
271  ),
272  array(
273  'first' => array('value' => 'value1'),
274  'second' => array('value' => 'value2'),
275  )
276  ),
277  'two levels' => array(
278  array(
279  'first.' => array('firstSub' => 'value1'),
280  'second.' => array('firstSub' => 'value2'),
281  ),
282  array(
283  'first.firstSub' => array('value' => 'value1'),
284  'second.firstSub' => array('value' => 'value2'),
285  )
286  ),
287  'three levels' => array(
288  array(
289  'first.' => array('firstSub.' => array('firstSubSub' => 'value1')),
290  'second.' => array('firstSub.' => array('firstSubSub' => 'value2'))
291  ),
292  array(
293  'first.firstSub.firstSubSub' => array('value' => 'value1'),
294  'second.firstSub.firstSubSub' => array('value' => 'value2'),
295  )
296  ),
297  'mixed' => array(
298  array(
299  'first.' => array('firstSub' => 'value1'),
300  'second.' => array('firstSub.' => array('firstSubSub' => 'value2')),
301  'third' => 'value3'
302  ),
303  array(
304  'first.firstSub' => array('value' => 'value1'),
305  'second.firstSub.firstSubSub' => array('value' => 'value2'),
306  'third' => array('value' => 'value3')
307  )
308  )
309  );
310  }
311 
320  public function convertNestedToValuedConfiguration(array $configuration, array $expected)
321  {
323  $subject = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class, array('dummy'), array(), '', false);
324  $this->assertEquals($expected, $subject->convertNestedToValuedConfiguration($configuration));
325  }
326 }