TYPO3 CMS  TYPO3_7-6
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 
22 {
26  public function getCurrentConfigurationReturnsExtensionConfigurationAsValuedConfiguration()
27  {
29  $configurationUtility = $this->getMock(
30  \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class,
31  ['getDefaultConfigurationFromExtConfTemplateAsValuedArray']
32  );
33  $configurationUtility
34  ->expects($this->once())
35  ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
36  ->will($this->returnValue([]));
37  $extensionKey = $this->getUniqueId('some-extension');
38 
39  $currentConfiguration = [
40  'key1' => 'value1',
41  'key2.' => [
42  'subkey1' => 'value2'
43  ]
44  ];
45 
46  $expected = [
47  'key1' => [
48  'value' => 'value1',
49  ],
50  'key2.subkey1' => [
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  ['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 = [
91  'checkConfigurationFE' => [
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' => [
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 = [
117  'advancedbackend.' => [
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 = [
125  'checkConfigurationFE' => [
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' => [
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__' => [
147  'advancedbackend' => [
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 [
165  'plain array' => [
166  [
167  'first' => [
168  'value' => 'value1'
169  ],
170  'second' => [
171  'value' => 'value2'
172  ]
173  ],
174  [
175  'first' => 'value1',
176  'second' => 'value2'
177  ]
178  ],
179  'nested value with 2 levels' => [
180  [
181  'first.firstSub' => [
182  'value' => 'value1'
183  ],
184  'second.secondSub' => [
185  'value' => 'value2'
186  ]
187  ],
188  [
189  'first.' => [
190  'firstSub' => 'value1'
191  ],
192  'second.' => [
193  'secondSub' => 'value2'
194  ]
195  ]
196  ],
197  'nested value with 3 levels' => [
198  [
199  'first.firstSub.firstSubSub' => [
200  'value' => 'value1'
201  ],
202  'second.secondSub.secondSubSub' => [
203  'value' => 'value2'
204  ]
205  ],
206  [
207  'first.' => [
208  'firstSub.' => [
209  'firstSubSub' => 'value1'
210  ]
211  ],
212  'second.' => [
213  'secondSub.' => [
214  'secondSubSub' => 'value2'
215  ]
216  ]
217  ]
218  ],
219  'mixed nested value with 2 levels' => [
220  [
221  'first' => [
222  'value' => 'firstValue'
223  ],
224  'first.firstSub' => [
225  'value' => 'value1'
226  ],
227  'second.secondSub' => [
228  'value' => 'value2'
229  ]
230  ],
231  [
232  'first' => 'firstValue',
233  'first.' => [
234  'firstSub' => 'value1'
235  ],
236  'second.' => [
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, ['dummy'], [], '', false);
256  $this->assertEquals($expected, $subject->convertValuedToNestedConfiguration($configuration));
257  }
258 
265  {
266  return [
267  'plain array' => [
268  [
269  'first' => 'value1',
270  'second' => 'value2'
271  ],
272  [
273  'first' => ['value' => 'value1'],
274  'second' => ['value' => 'value2'],
275  ]
276  ],
277  'two levels' => [
278  [
279  'first.' => ['firstSub' => 'value1'],
280  'second.' => ['firstSub' => 'value2'],
281  ],
282  [
283  'first.firstSub' => ['value' => 'value1'],
284  'second.firstSub' => ['value' => 'value2'],
285  ]
286  ],
287  'three levels' => [
288  [
289  'first.' => ['firstSub.' => ['firstSubSub' => 'value1']],
290  'second.' => ['firstSub.' => ['firstSubSub' => 'value2']]
291  ],
292  [
293  'first.firstSub.firstSubSub' => ['value' => 'value1'],
294  'second.firstSub.firstSubSub' => ['value' => 'value2'],
295  ]
296  ],
297  'mixed' => [
298  [
299  'first.' => ['firstSub' => 'value1'],
300  'second.' => ['firstSub.' => ['firstSubSub' => 'value2']],
301  'third' => 'value3'
302  ],
303  [
304  'first.firstSub' => ['value' => 'value1'],
305  'second.firstSub.firstSubSub' => ['value' => 'value2'],
306  'third' => ['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, ['dummy'], [], '', false);
324  $this->assertEquals($expected, $subject->convertNestedToValuedConfiguration($configuration));
325  }
326 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']