2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Repository
;
4 /***************************************************************
7 * (c) 2012 Susanne Moog, <susanne.moog@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 * Tests for ConfigurationItemRepository
30 * @package Extension Manager
33 class ConfigurationItemRepositoryTest
extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
{
36 * @var boolean Backup globals
38 protected $backupGlobals = TRUE;
41 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ConfigurationItemRepository|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
43 public $configurationItemRepository;
49 public function setUp() {
50 $this->configurationItemRepository
= $this->getAccessibleMock(
51 'TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ConfigurationItemRepository',
54 $configurationManagerMock = $this->getAccessibleMock(
55 'TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager',
58 $this->configurationItemRepository
->injectConfigurationManager($configurationManagerMock);
66 public function addMetaInformationUnsetsOriginalConfigurationMetaKey() {
67 $configuration = array(
68 '__meta__' => 'metaInformation',
69 'test123' => 'test123'
71 $this->configurationItemRepository
->_callRef('addMetaInformation', $configuration);
72 $this->assertEquals(array('test123' => 'test123'), $configuration);
79 public function addMetaInformationReturnsMetaInformation() {
80 $configuration = array(
81 '__meta__' => 'metaInformation',
82 'test123' => 'test123'
84 $meta = $this->configurationItemRepository
->_callRef('addMetaInformation', $configuration);
85 $this->assertEquals('metaInformation', $meta);
92 public function extractInformationForConfigFieldsOfTypeUserAddsGenericAndTypeInformationDataProvider() {
97 'subcat_name' => 'enable',
98 'subcat' => 'a/enable/z',
99 'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
100 'label' => 'Frontend configuration check',
101 'name' => 'checkConfigurationFE',
103 'default_value' => 0,
104 'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend'
110 'subcat_name' => 'enable',
111 'subcat' => 'a/enable/z',
112 'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend]',
113 'label' => 'Backend configuration check',
114 'name' => 'checkConfigurationBE',
116 'default_value' => 0,
117 'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend'
123 'subcat_name' => 'enable',
124 'subcat' => 'a/enable/z',
125 'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]',
126 'label' => 'Hashing method for the frontend: Defines salted hashing method to use. Choose "Portable PHP password hashing" to stay compatible with other CMS (e.g. Drupal, Wordpress). Choose "MD5 salted hashing" to reuse TYPO3 passwords for OS level authentication (other servers could use TYPO3 passwords). Choose "Blowfish salted hashing" for advanced security to reuse passwords on OS level (Blowfish might not be supported on your system TODO).',
127 'name' => 'FE.saltedPWHashingMethod',
128 'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt',
129 'default_value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt',
130 'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE'
139 * @dataProvider extractInformationForConfigFieldsOfTypeUserAddsGenericAndTypeInformationDataProvider
140 * @param $configurationOption
143 public function extractInformationForConfigFieldsOfTypeUserAddsGenericAndTypeInformation($configurationOption) {
144 $configurationOptionModified = $this->configurationItemRepository
->_callRef('extractInformationForConfigFieldsOfTypeUser', $configurationOption);
145 $this->assertEquals('user', $configurationOptionModified['type']);
146 $this->assertEquals($configurationOption['comparisonGeneric'], $configurationOptionModified['generic']);
154 public function extractInformationForConfigFieldsOfTypeOptionsAddsGenericTypeAndLabelInformation() {
157 'subcat_name' => 'enable',
158 'subcat' => 'a/enable/100z',
159 'type' => 'options[Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.),Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.),Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)]',
160 'label' => 'Default configuration settings',
161 'name' => 'defaultConfiguration',
162 'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
163 'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
164 'genericComparisonValue' => array(
165 'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)' => 'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)',
166 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
167 'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)'
169 'typeComparisonValue' => 'options'
171 $optionModified = $this->configurationItemRepository
->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
172 $this->assertArrayHasKey('generic', $optionModified);
173 $this->assertArrayHasKey('type', $optionModified);
174 $this->assertArrayHasKey('label', $optionModified);
175 $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
176 $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
184 public function extractInformationForConfigFieldsOfTypeOptionsWithLabelsAndValuesAddsGenericTypeAndLabelInformation() {
187 'subcat_name' => 'enable',
188 'subcat' => 'a/enable/100z',
189 'type' => 'options[Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)=MINIMAL,Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.) = TYPICAL,Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)=DEMO]',
190 'label' => 'Default configuration settings',
191 'name' => 'defaultConfiguration',
192 'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
193 'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
194 'genericComparisonValue' => array(
195 'Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.)' => 'MINIMAL',
196 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)' => 'TYPICAL',
197 'Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)' => 'DEMO'
199 'typeComparisonValue' => 'options'
201 $optionModified = $this->configurationItemRepository
->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
202 $this->assertArrayHasKey('generic', $optionModified);
203 $this->assertArrayHasKey('type', $optionModified);
204 $this->assertArrayHasKey('label', $optionModified);
205 $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
206 $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
214 public function mergeDefaultConfigurationWithNoCurrentValuesReturnsTheDefaultConfiguration() {
216 // @TODO: Possible tests that can be added if ConfigurationManager is not static
217 // and can be mocked:
219 // Value is set to null
220 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey] = NULL;
221 $configuration = $this->configurationItemRepository->mergeWithExistingConfiguration($defaultConfiguration, $extension);
222 $this->assertEquals($defaultConfiguration, $configuration);
224 // Value is set to integer
225 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey] = 123;
226 $configuration = $this->configurationItemRepository->mergeWithExistingConfiguration($defaultConfiguration, $extension);
227 $this->assertEquals($defaultConfiguration, $configuration);
229 // valid configuration value - an empty serialized array
230 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey] = 'a:0:{}';
231 $configuration = $this->configurationItemRepository->mergeWithExistingConfiguration($defaultConfiguration, $extension);
232 $this->assertEquals($defaultConfiguration, $configuration);
235 $extensionKey = 'some_non_existing_extension';
237 'key' => $extensionKey
239 $defaultConfiguration = array(
244 $configuration = $this->configurationItemRepository
->_callRef('mergeWithExistingConfiguration', $defaultConfiguration, $extension);
245 $this->assertEquals($defaultConfiguration, $configuration);
253 public function mergeWithExistingConfigurationOverwritesDefaultKeysWithCurrent() {
254 $configurationManagerMock = $this->getAccessibleMock(
255 'TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
256 $configurationManagerMock
257 ->expects($this->once())
258 ->method('getConfigurationValueByPath')
259 ->with('EXT/extConf/testextensionkey')
260 ->will($this->returnValue(
264 'saltedPWHashingMethod' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface_sha1'
271 $this->configurationItemRepository
->injectConfigurationManager($configurationManagerMock);
273 $defaultConfiguration = array(
274 'FE.enabled' => array(
277 'FE.saltedPWHashingMethod' => array(
278 'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'
280 'BE.enabled' => array(
283 'BE.saltedPWHashingMethod' => array(
284 'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'
287 $expectedResult = array(
288 'FE.enabled' => array(
291 'FE.saltedPWHashingMethod' => array(
292 'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface_sha1'
294 'BE.enabled' => array(
297 'BE.saltedPWHashingMethod' => array(
298 'value' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'
300 'CLI.enabled' => array(
304 $result = $this->configurationItemRepository
->_call('mergeWithExistingConfiguration', $defaultConfiguration, array('key' => 'testextensionkey'));
305 $this->assertEquals($expectedResult, $result);
312 public function createArrayFromConstantsCreatesAnArrayWithMetaInformationDataProvider() {
314 'demo data from salted passwords' => array(
316 # cat=basic/enable; type=user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]; label=Frontend configuration check
317 checkConfigurationFE=0
319 # cat=advancedBackend; type=boolean; label=Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.
322 TSConstantEditor.advancedbackend {
323 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!
327 'checkConfigurationFE' => array(
329 'subcat_name' => 'enable',
330 'subcat' => 'a/enable/z',
331 'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
332 'label' => 'Frontend configuration check',
333 'name' => 'checkConfigurationFE',
335 'default_value' => '0'
337 'BE.forceSalted' => array(
338 'cat' => 'advancedbackend',
341 'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
342 'name' => 'BE.forceSalted',
344 'default_value' => '0'
348 'advancedbackend.' => array(
349 '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!',
350 1 => 'BE.forceSalted'
354 'checkConfigurationFE' => array(
356 'subcat_name' => 'enable',
357 'subcat' => 'a/enable/z',
358 'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
359 'label' => 'Frontend configuration check',
360 'name' => 'checkConfigurationFE',
362 'default_value' => '0'
364 'BE.forceSalted' => array(
365 'cat' => 'advancedbackend',
368 'label' => 'Force salted passwords: Enforce usage of SaltedPasswords. Old MD5 hashed passwords will stop working.',
369 'name' => 'BE.forceSalted',
371 'default_value' => '0',
375 'advancedbackend' => array(
376 '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!'
387 * @dataProvider createArrayFromConstantsCreatesAnArrayWithMetaInformationDataProvider
390 * @param $setupTsConstantEditor
394 public function createArrayFromConstantsCreatesAnArrayWithMetaInformation($raw, $constants, $setupTsConstantEditor, $expected) {
395 $tsStyleConfig = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\ConfigurationForm');
396 $configurationItemRepositoryMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ConfigurationItemRepository', array('getT3libTsStyleConfig'));
397 $configurationItemRepositoryMock->expects($this->once())->method('getT3libTsStyleConfig')->will($this->returnValue($tsStyleConfig));
398 $tsStyleConfig->expects($this->once())->method('ext_initTSstyleConfig')->with($raw, $this->anything(), $this->anything(), $this->anything())->will($this->returnValue($constants));
399 $tsStyleConfig->setup
['constants']['TSConstantEditor.'] = $setupTsConstantEditor;
400 $constantsResult = $configurationItemRepositoryMock->createArrayFromConstants($raw, array());
401 $this->assertEquals($expected, $constantsResult);