2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility
;
4 /***************************************************************
7 * (c) 2012-2013 Oliver Hader <oliver.hader@typo3.org>
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.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
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.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
28 * Configuration utility test
31 class ConfigurationUtilityTest
extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
{
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')
43 ->expects($this->once())
44 ->method('getDefaultConfigurationFromExtConfTemplateAsValuedArray')
45 ->will($this->returnValue(array()));
46 $extensionKey = uniqid('some-extension');
48 $currentConfiguration = array(
59 'key2.subkey1' => array(
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);
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')
80 ->expects($this->once())
81 ->method('getDefaultConfigurationRawString')
82 ->will($this->returnValue('foo'));
84 $tsStyleConfig = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\ConfigurationForm');
86 $objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
87 $configurationUtility->_set('objectManager', $objectManagerMock);
89 ->expects($this->once())
91 ->with('TYPO3\\CMS\\Core\\TypoScript\\ConfigurationForm')
92 ->will($this->returnValue($tsStyleConfig));
95 'checkConfigurationFE' => array(
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',
103 'default_value' => '0'
105 'BE.forceSalted' => array(
106 'cat' => 'advancedbackend',
109 'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
110 'name' => 'BE.forceSalted',
112 'default_value' => '0'
116 ->expects($this->once())
117 ->method('ext_initTSstyleConfig')
118 ->will($this->returnValue($constants));
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'
126 $tsStyleConfig->setup
['constants']['TSConstantEditor.'] = $setupTsConstantEditor;
129 'checkConfigurationFE' => array(
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',
137 'default_value' => '0',
138 'subcat_label' => 'Enable features',
140 'BE.forceSalted' => array(
141 'cat' => 'advancedbackend',
144 'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
145 'name' => 'BE.forceSalted',
147 'default_value' => '0',
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!'
157 $result = $configurationUtility->getDefaultConfigurationFromExtConfTemplateAsValuedArray(uniqid('some_extension'));
158 $this->assertEquals($expected, $result);
162 * Data provider for convertValuedToNestedConfiguration
166 public function convertValuedToNestedConfigurationDataProvider() {
168 'plain array' => array(
182 'nested value with 2 levels' => array(
184 'first.firstSub' => array(
187 'second.secondSub' => array(
193 'firstSub' => 'value1'
196 'secondSub' => 'value2'
200 'nested value with 3 levels' => array(
202 'first.firstSub.firstSubSub' => array(
205 'second.secondSub.secondSubSub' => array(
211 'firstSub.' => array(
212 'firstSubSub' => 'value1'
216 'secondSub.' => array(
217 'secondSubSub' => 'value2'
222 'mixed nested value with 2 levels' => array(
225 'value' => 'firstValue'
227 'first.firstSub' => array(
230 'second.secondSub' => array(
235 'first' => 'firstValue',
237 'firstSub' => 'value1'
240 'secondSub' => 'value2'
249 * @dataProvider convertValuedToNestedConfigurationDataProvider
251 * @param array $configuration
252 * @param array $expected
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));
262 * Data provider for convertNestedToValuedConfiguration
266 public function convertNestedToValuedConfigurationDataProvider() {
268 'plain array' => array(
274 'first' => array('value' => 'value1'),
275 'second' => array('value' => 'value2'),
278 'two levels' => array(
280 'first.' => array('firstSub' => 'value1'),
281 'second.' => array('firstSub' => 'value2'),
284 'first.firstSub' => array('value' => 'value1'),
285 'second.firstSub' => array('value' => 'value2'),
288 'three levels' => array(
290 'first.' => array('firstSub.' => array('firstSubSub' => 'value1')),
291 'second.' => array('firstSub.' => array('firstSubSub' => 'value2'))
294 'first.firstSub.firstSubSub' => array('value' => 'value1'),
295 'second.firstSub.firstSubSub' => array('value' => 'value2'),
300 'first.' => array('firstSub' => 'value1'),
301 'second.' => array('firstSub.' => array('firstSubSub' => 'value2')),
305 'first.firstSub' => array('value' => 'value1'),
306 'second.firstSub.firstSubSub' => array('value' => 'value2'),
307 'third' => array('value' => 'value3')
315 * @dataProvider convertNestedToValuedConfigurationDataProvider
317 * @param array $configuration
318 * @param array $expected
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));