[BUGFIX] EM 6.0 parse configuration type 'options' correctly
authorJigal van Hemert <jigal@xs4all.nl>
Wed, 31 Oct 2012 21:45:33 +0000 (22:45 +0100)
committerDmitry Dulepov <dmitry@typo3.org>
Thu, 1 Nov 2012 11:08:32 +0000 (12:08 +0100)
The labels for the options are in the options= part, not in the
label= part. Parsing the options correctly renders the select
box as intended.

Change-Id: I5a3c9e888f248a91c1c79f7a69f82a6a87880a3e
Fixes: #42252
Releases: 6.0
Reviewed-on: http://review.typo3.org/16090
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
typo3/sysext/extensionmanager/Classes/Domain/Repository/ConfigurationItemRepository.php
typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php

index e1e2834..67fbd19 100644 (file)
@@ -127,13 +127,17 @@ class ConfigurationItemRepository {
         * @return array
         */
        protected function extractInformationForConfigFieldsOfTypeOptions(array $configurationOption) {
-               preg_match('/options\\[(.*)\\]/is', $configurationOption['type'], $typeMatches);
-               preg_match('/options\\[(.*)\\]/is', $configurationOption['label'], $labelMatches);
-               $optionValues = explode(',', $typeMatches[1]);
-               $optionLabels = explode(',', $labelMatches[1]);
-               $configurationOption['generic'] = $labelMatches ? array_combine($optionLabels, $optionValues) : array_combine($optionValues, $optionValues);
+               preg_match('/options\[(.*)\]/is', $configurationOption['type'], $typeMatches);
+               $optionItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $typeMatches[1]);
+               foreach ($optionItems as $optionItem) {
+                       $optionPair = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('=', $optionItem);
+                       if (count($optionPair) === 2) {
+                               $configurationOption['generic'][$optionPair[0]] = $optionPair[1];
+                       } else {
+                               $configurationOption['generic'][$optionPair[0]] = $optionPair[0];
+                       }
+               }
                $configurationOption['type'] = 'options';
-               $configurationOption['label'] = str_replace($labelMatches[0], '', $configurationOption['label']);
                return $configurationOption;
        }
 
index e7bb3e1..6aaff0c 100644 (file)
@@ -181,6 +181,36 @@ class ConfigurationItemRepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base
         * @test
         * @return void
         */
+       public function extractInformationForConfigFieldsOfTypeOptionsWithLabelsAndValuesAddsGenericTypeAndLabelInformation() {
+               $option = array(
+                       'cat' => 'basic',
+                       'subcat_name' => 'enable',
+                       'subcat' => 'a/enable/100z',
+                       '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]',
+                       'label' => 'Default configuration settings',
+                       'name' => 'defaultConfiguration',
+                       'value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
+                       'default_value' => 'Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.)',
+                       'genericComparisonValue' => array(
+                               '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'
+                       ),
+                       'typeComparisonValue' => 'options'
+               );
+               $optionModified = $this->configurationItemRepository->_callRef('extractInformationForConfigFieldsOfTypeOptions', $option);
+               $this->assertArrayHasKey('generic', $optionModified);
+               $this->assertArrayHasKey('type', $optionModified);
+               $this->assertArrayHasKey('label', $optionModified);
+               $this->assertEquals($option['genericComparisonValue'], $optionModified['generic']);
+               $this->assertEquals($option['typeComparisonValue'], $optionModified['type']);
+       }
+
+       /**
+        *
+        * @test
+        * @return void
+        */
        public function mergeDefaultConfigurationWithNoCurrentValuesReturnsTheDefaultConfiguration() {
 
                        // @TODO: Possible tests that can be added if ConfigurationManager is not static