[BUGFIX] Fix generation of class schema for namespaced arguments
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 13 Oct 2012 13:14:24 +0000 (15:14 +0200)
committerMarkus Günther <mail@markus-guenther.de>
Sat, 13 Oct 2012 13:37:03 +0000 (15:37 +0200)
When creating argument objects extbase tries to generate
a class schema if the argument is an object. This did
not work for namespaced classes as they have not been
recognized yet.

On the way add some test cases for the TypeHandlingService
as it is related to this.

Change-Id: Ie8ee8f4ffd4fa52814a3332e45c659e2183ee201
Fixes: #41948
Releases: 6.0
Reviewed-on: http://review.typo3.org/15554
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
Reviewed-by: Nico de Haen
Tested-by: Nico de Haen
Reviewed-by: Markus Günther
Tested-by: Markus Günther
typo3/sysext/extbase/Classes/Mvc/Controller/Argument.php
typo3/sysext/extbase/Tests/Unit/Mvc/Controller/ArgumentTest.php
typo3/sysext/extbase/Tests/Unit/Service/TypeHandlingServiceTest.php

index 06af68b..3b42f58 100644 (file)
@@ -233,7 +233,8 @@ class Argument {
         */
        public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\Service $reflectionService) {
                $this->reflectionService = $reflectionService;
-               $this->dataTypeClassSchema = strpos($this->dataType, '_') !== FALSE ? $this->reflectionService->getClassSchema($this->dataType) : NULL;
+               // Check for classnames (which have at least one underscore or backslash)
+               $this->dataTypeClassSchema = strpbrk($this->dataType, '_\\') !== FALSE ? $this->reflectionService->getClassSchema($this->dataType) : NULL;
        }
 
        /**
index 39a1290..c84a774 100644 (file)
@@ -182,6 +182,53 @@ class ArgumentTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        }
 
        /**
+        * @return array
+        */
+       public function validClassNameDataTypes() {
+               return array(
+                       array('Tx_Foo_Bar'),
+                       array('ExtbaseTeam\\BlogExample\\Foo\\Bar'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider validClassNameDataTypes
+        */
+       public function classSchemaIsBuiltForClassNameDataTypesWhenReflectionServiceIsInjected($dataType) {
+               /** @var $argument \TYPO3\CMS\Extbase\Mvc\Controller\Argument|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $argument = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('dummy'), array(), '', FALSE);
+               $argument->_set('dataType', $dataType);
+               $reflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\Service');
+               $reflectionService->expects($this->once())->method('getClassSchema')->with($dataType);
+               $argument->injectReflectionService($reflectionService);
+       }
+
+       /**
+        * @return array
+        */
+       public function primitiveOrBuiltInObjectsDataTypes() {
+               return array(
+                       array('integer'),
+                       array('array'),
+                       array('DateTime'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider primitiveOrBuiltInObjectsDataTypes
+        */
+       public function classSchemaIsNotBuiltForPrimitiveDataTypesWhenReflectionServiceIsInjected($dataType) {
+               /** @var $argument \TYPO3\CMS\Extbase\Mvc\Controller\Argument|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $argument = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('dummy'), array(), '', FALSE);
+               $argument->_set('dataType', $dataType);
+               $reflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\Service');
+               $reflectionService->expects($this->never())->method('getClassSchema');
+               $argument->injectReflectionService($reflectionService);
+       }
+
+       /**
         * @test
         * @author Karsten Dambekalns <karsten@typo3.org>
         */
index 3c8af26..a98dd48 100644 (file)
@@ -68,13 +68,17 @@ class TypeHandlingServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
                        array('int', array('type' => 'integer', 'elementType' => NULL)),
                        array('string', array('type' => 'string', 'elementType' => NULL)),
                        array('DateTime', array('type' => 'DateTime', 'elementType' => NULL)),
+                       array('\DateTime', array('type' => 'DateTime', 'elementType' => NULL)),
                        array('Tx_Extbase_Bar', array('type' => 'Tx_Extbase_Bar', 'elementType' => NULL)),
-                       array('Tx_Extbase_Bar', array('type' => 'Tx_Extbase_Bar', 'elementType' => NULL)),
+                       array('\\ExtbaseTeam\\BlogExample\\Foo\\Bar', array('type' => 'ExtbaseTeam\\BlogExample\\Foo\\Bar', 'elementType' => NULL)),
                        array('array<integer>', array('type' => 'array', 'elementType' => 'integer')),
                        array('ArrayObject<string>', array('type' => 'ArrayObject', 'elementType' => 'string')),
                        array('SplObjectStorage<Tx_Extbase_Bar>', array('type' => 'SplObjectStorage', 'elementType' => 'Tx_Extbase_Bar')),
+                       array('SplObjectStorage<\\ExtbaseTeam\\BlogExample\\Foo\\Bar>', array('type' => 'SplObjectStorage', 'elementType' => 'ExtbaseTeam\\BlogExample\\Foo\\Bar')),
                        array('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ObjectStorage<Tx_Extbase_Bar>', array('type' => 'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ObjectStorage', 'elementType' => 'Tx_Extbase_Bar')),
-                       array('Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Bar>', array('type' => 'Tx_Extbase_Persistence_ObjectStorage', 'elementType' => 'Tx_Extbase_Bar'))
+                       array('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ObjectStorage<\\ExtbaseTeam\\BlogExample\\Foo\\Bar>', array('type' => 'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ObjectStorage', 'elementType' => 'ExtbaseTeam\\BlogExample\\Foo\\Bar')),
+                       array('Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Bar>', array('type' => 'Tx_Extbase_Persistence_ObjectStorage', 'elementType' => 'Tx_Extbase_Bar')),
+                       array('Tx_Extbase_Persistence_ObjectStorage<\\ExtbaseTeam\\BlogExample\\Foo\\Bar>', array('type' => 'Tx_Extbase_Persistence_ObjectStorage', 'elementType' => 'ExtbaseTeam\\BlogExample\\Foo\\Bar')),
                );
        }
 
@@ -86,7 +90,7 @@ class TypeHandlingServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
         * @param mixed $expectedResult
         */
        public function parseTypeReturnsArrayWithInformation($type, $expectedResult) {
-               $this->assertEquals($this->typeHandlingService->parseType($type), $expectedResult);
+               $this->assertEquals($expectedResult, $this->typeHandlingService->parseType($type));
        }
 
        /**