[BUGFIX] TypeConverter can handle oldschool classnames
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 5 Mar 2013 21:01:13 +0000 (22:01 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Wed, 6 Mar 2013 19:17:37 +0000 (20:17 +0100)
In case an extension provides oldschool classnames, the
setTypeConverterOptions functions fail due to mismatched arraykey.
This key is the classname of the converter.
Test for oldschool classnames and replace the arraykey with the
namespaced version solves the issue.

Fixes: #45977
Releases: 6.0, 6.1
Change-Id: I88debadda628ee166aea6ebdbf173a6239779303
Reviewed-on: https://review.typo3.org/18709
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/extbase/Classes/Property/PropertyMappingConfiguration.php
typo3/sysext/extbase/Tests/Unit/Property/PropertyMappingConfigurationTest.php

index e42a62c..0ad17e6 100644 (file)
@@ -26,6 +26,8 @@ namespace TYPO3\CMS\Extbase\Property;
  *
  * @api
  */
+use TYPO3\CMS\Core\Core\ClassLoader;
+
 class PropertyMappingConfiguration implements \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface {
 
        /**
@@ -234,6 +236,9 @@ class PropertyMappingConfiguration implements \TYPO3\CMS\Extbase\Property\Proper
         * @api
         */
        public function setTypeConverterOptions($typeConverter, array $options) {
+               if (strpos($typeConverter, '_') !== FALSE) {
+                       $typeConverter = ClassLoader::getClassNameForAlias($typeConverter);
+               }
                $this->configuration[$typeConverter] = $options;
        }
 
@@ -248,6 +253,9 @@ class PropertyMappingConfiguration implements \TYPO3\CMS\Extbase\Property\Proper
         * @api
         */
        public function setTypeConverterOption($typeConverter, $optionKey, $optionValue) {
+               if (strpos($typeConverter, '_') !== FALSE) {
+                       $typeConverter = ClassLoader::getClassNameForAlias($typeConverter);
+               }
                $this->configuration[$typeConverter][$optionKey] = $optionValue;
        }
 
index 54fad74..c225add 100644 (file)
@@ -86,12 +86,38 @@ class PropertyMappingConfigurationTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
        }
 
        /**
+        * DataProvider for typeConfiguration tests
+        * @return array
+        */
+       public function provideTypeConverterSettings () {
+               return array(
+                       // kept for historical reasons, this test was the initial one
+                       'dummy data' => array(
+                               'someConverter',
+                               'someConverter',
+                               array('k1' => 'v1', 'k2' => 'v2')
+                       ),
+                       'typeConverterName oldschool' => array(
+                               'Tx_Extbase_Property_TypeConverter_DateTimeConverter',
+                               'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
+                               array('k1' => 'v1', 'k2' => 'v2')
+                       ),
+                       'typeConverterName namespaced' => array(
+                               'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
+                               'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
+                               array('k1' => 'v1', 'k2' => 'v2')
+                       )
+               );
+       }
+
+       /**
+        * @dataProvider provideTypeConverterSettings
         * @test
         */
-       public function setTypeConverterOptionsCanBeRetrievedAgain() {
-               $this->propertyMappingConfiguration->setTypeConverterOptions('someConverter', array('k1' => 'v1', 'k2' => 'v2'));
-               $this->assertEquals('v1', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k1'));
-               $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue('someConverter', 'k2'));
+       public function setTypeConverterOptionsCanBeRetrievedAgain($converterName, $converterClass, $values) {
+               $this->propertyMappingConfiguration->setTypeConverterOptions($converterName, $values);
+               $this->assertEquals($values['k1'], $this->propertyMappingConfiguration->getConfigurationValue($converterClass, 'k1'));
+               $this->assertEquals($values['k2'], $this->propertyMappingConfiguration->getConfigurationValue($converterClass, 'k2'));
        }
 
        /**