TYPO3 CMS  TYPO3_8-7
ConfigurationUtilityTest.php
Go to the documentation of this file.
1 <?php
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 
20 class ConfigurationUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  public function getCurrentConfigurationReturnsExtensionConfigurationAsValuedConfiguration()
26  {
28  $configurationUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class)
29  ->setMethods(['getDefaultConfigurationFromExtConfTemplateAsValuedArray'])
30  ->getMock();
31  $configurationUtility
32  ->expects($this->once())
33  ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
34  ->will($this->returnValue([]));
35  $extensionKey = $this->getUniqueId('some-extension');
36 
37  $currentConfiguration = [
38  'key1' => 'value1',
39  'key2.' => [
40  'subkey1' => 'value2'
41  ]
42  ];
43 
44  $expected = [
45  'key1' => [
46  'value' => 'value1',
47  ],
48  'key2.subkey1' => [
49  'value' => 'value2',
50  ],
51  ];
52 
53  $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey] = serialize($currentConfiguration);
54  $actual = $configurationUtility->getCurrentConfiguration($extensionKey);
55  $this->assertEquals($expected, $actual);
56  }
57 
61  public function getDefaultConfigurationFromExtConfTemplateAsValuedArrayReturnsExpectedExampleArray()
62  {
64  $configurationUtility = $this->getAccessibleMock(
65  \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class,
66  ['getDefaultConfigurationRawString']
67  );
68  $configurationUtility
69  ->expects($this->once())
70  ->method('getDefaultConfigurationRawString')
71  ->will($this->returnValue('foo'));
72 
73  $tsStyleConfig = $this->getMockBuilder(\TYPO3\CMS\Core\TypoScript\ConfigurationForm::class)->getMock();
74 
75  $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class)->getMock();
76  $configurationUtility->_set('objectManager', $objectManagerMock);
77  $objectManagerMock
78  ->expects($this->once())
79  ->method('get')
80  ->with(\TYPO3\CMS\Core\TypoScript\ConfigurationForm::class)
81  ->will($this->returnValue($tsStyleConfig));
82 
83  $constants = [
84  'checkConfigurationFE' => [
85  'cat' => 'basic',
86  'subcat_name' => 'enable',
87  'subcat' => 'a/enable/z',
88  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
89  'label' => 'Frontend configuration check',
90  'name' => 'checkConfigurationFE',
91  'value' => '0',
92  'default_value' => '0'
93  ],
94  'BE.forceSalted' => [
95  'cat' => 'advancedbackend',
96  'subcat' => 'x/z',
97  'type' => 'boolean',
98  'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
99  'name' => 'BE.forceSalted',
100  'value' => '0',
101  'default_value' => '0'
102  ]
103  ];
104  $tsStyleConfig
105  ->expects($this->once())
106  ->method('ext_initTSstyleConfig')
107  ->will($this->returnValue($constants));
108 
109  $setupTsConstantEditor = [
110  'advancedbackend.' => [
111  '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!',
112  1 => 'BE.forceSalted'
113  ]
114  ];
115  $tsStyleConfig->setup['constants']['TSConstantEditor.'] = $setupTsConstantEditor;
116 
117  $expected = [
118  'checkConfigurationFE' => [
119  'cat' => 'basic',
120  'subcat_name' => 'enable',
121  'subcat' => 'a/enable/z',
122  'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
123  'label' => 'Frontend configuration check',
124  'name' => 'checkConfigurationFE',
125  'value' => '0',
126  'default_value' => '0',
127  'subcat_label' => 'Enable features',
128  ],
129  'BE.forceSalted' => [
130  'cat' => 'advancedbackend',
131  'subcat' => 'x/z',
132  'type' => 'boolean',
133  'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
134  'name' => 'BE.forceSalted',
135  'value' => '0',
136  'default_value' => '0',
137  'highlight' => 1,
138  ],
139  '__meta__' => [
140  'advancedbackend' => [
141  '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!'
142  ]
143  ]
144  ];
145 
146  $result = $configurationUtility->getDefaultConfigurationFromExtConfTemplateAsValuedArray($this->getUniqueId('some_extension'));
147  $this->assertEquals($expected, $result);
148  }
149 
156  {
157  return [
158  'plain array' => [
159  [
160  'first' => [
161  'value' => 'value1'
162  ],
163  'second' => [
164  'value' => 'value2'
165  ]
166  ],
167  [
168  'first' => 'value1',
169  'second' => 'value2'
170  ]
171  ],
172  'nested value with 2 levels' => [
173  [
174  'first.firstSub' => [
175  'value' => 'value1'
176  ],
177  'second.secondSub' => [
178  'value' => 'value2'
179  ]
180  ],
181  [
182  'first.' => [
183  'firstSub' => 'value1'
184  ],
185  'second.' => [
186  'secondSub' => 'value2'
187  ]
188  ]
189  ],
190  'nested value with 3 levels' => [
191  [
192  'first.firstSub.firstSubSub' => [
193  'value' => 'value1'
194  ],
195  'second.secondSub.secondSubSub' => [
196  'value' => 'value2'
197  ]
198  ],
199  [
200  'first.' => [
201  'firstSub.' => [
202  'firstSubSub' => 'value1'
203  ]
204  ],
205  'second.' => [
206  'secondSub.' => [
207  'secondSubSub' => 'value2'
208  ]
209  ]
210  ]
211  ],
212  'mixed nested value with 2 levels' => [
213  [
214  'first' => [
215  'value' => 'firstValue'
216  ],
217  'first.firstSub' => [
218  'value' => 'value1'
219  ],
220  'second.secondSub' => [
221  'value' => 'value2'
222  ]
223  ],
224  [
225  'first' => 'firstValue',
226  'first.' => [
227  'firstSub' => 'value1'
228  ],
229  'second.' => [
230  'secondSub' => 'value2'
231  ]
232  ]
233  ]
234  ];
235  }
236 
244  public function convertValuedToNestedConfiguration(array $configuration, array $expected)
245  {
247  $subject = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class, ['dummy'], [], '', false);
248  $this->assertEquals($expected, $subject->convertValuedToNestedConfiguration($configuration));
249  }
250 
257  {
258  return [
259  'plain array' => [
260  [
261  'first' => 'value1',
262  'second' => 'value2'
263  ],
264  [
265  'first' => ['value' => 'value1'],
266  'second' => ['value' => 'value2'],
267  ]
268  ],
269  'two levels' => [
270  [
271  'first.' => ['firstSub' => 'value1'],
272  'second.' => ['firstSub' => 'value2'],
273  ],
274  [
275  'first.firstSub' => ['value' => 'value1'],
276  'second.firstSub' => ['value' => 'value2'],
277  ]
278  ],
279  'three levels' => [
280  [
281  'first.' => ['firstSub.' => ['firstSubSub' => 'value1']],
282  'second.' => ['firstSub.' => ['firstSubSub' => 'value2']]
283  ],
284  [
285  'first.firstSub.firstSubSub' => ['value' => 'value1'],
286  'second.firstSub.firstSubSub' => ['value' => 'value2'],
287  ]
288  ],
289  'mixed' => [
290  [
291  'first.' => ['firstSub' => 'value1'],
292  'second.' => ['firstSub.' => ['firstSubSub' => 'value2']],
293  'third' => 'value3'
294  ],
295  [
296  'first.firstSub' => ['value' => 'value1'],
297  'second.firstSub.firstSubSub' => ['value' => 'value2'],
298  'third' => ['value' => 'value3']
299  ]
300  ]
301  ];
302  }
303 
311  public function convertNestedToValuedConfiguration(array $configuration, array $expected)
312  {
314  $subject = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class, ['dummy'], [], '', false);
315  $this->assertEquals($expected, $subject->convertNestedToValuedConfiguration($configuration));
316  }
317 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']