[BUGFIX] ActionController must use namespaced object view pattern 12/21712/2
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Fri, 28 Jun 2013 12:39:48 +0000 (14:39 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 28 Jun 2013 18:42:35 +0000 (20:42 +0200)
The ActionController still uses the old pattern like
Tx_@extension_View_@controller_@action@format for resolving
custom view objects. When using a namespaced extension it
must be possible to also use namespaced view objects.
Therefore a new view object pattern has to be introduced:
@vendor\@extension\View\@controller\@action@format

Releases: 6.2, 6.1, 6.0
Resolves: #47609
Change-Id: Iedc6120469f2277b482c5e1c40b89790404e9bbe
Reviewed-on: https://review.typo3.org/21712
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
typo3/sysext/extbase/Tests/Unit/Mvc/Controller/ActionControllerTest.php

index e7da4e5..85a51b5 100644 (file)
@@ -59,7 +59,14 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
         * @var string
         * @api
         */
-       protected $viewObjectNamePattern = 'Tx_@extension_View_@controller_@action@format';
+       protected $viewObjectNamePattern = '@vendor\@extension\View\@controller\@action@format';
+
+       /**
+        * @var string
+        * @api
+        * @deprecated since Extbase 6.2, will be removed two versions later
+        */
+       protected $deprecatedViewObjectNamePattern = 'Tx_@extension_View_@controller_@action@format';
 
        /**
         * A list of formats and object names of the views which should render them.
@@ -389,7 +396,14 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
         * @api
         */
        protected function resolveViewObjectName() {
-               $possibleViewName = $this->viewObjectNamePattern;
+               $vendorName = $this->request->getControllerVendorName();
+
+               if ($vendorName !== NULL) {
+                       $possibleViewName = str_replace('@vendor', $vendorName, $this->viewObjectNamePattern);
+               } else {
+                       $possibleViewName = $this->deprecatedViewObjectNamePattern;
+               }
+
                $extensionName = $this->request->getControllerExtensionName();
                $possibleViewName = str_replace('@extension', $extensionName, $possibleViewName);
                $possibleViewName = str_replace('@controller', $this->request->getControllerName(), $possibleViewName);
@@ -551,4 +565,4 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
        }
 }
 
-?>
\ No newline at end of file
+?>
index f936fba..92ff596 100644 (file)
@@ -239,6 +239,52 @@ class ActionControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        */
+       public function resolveViewObjectNameUsesDeprecatedViewObjectNamePatternForExtensionsWithoutVendor() {
+               eval('class Tx_MyPackage_View_MyController_MyActionMyFormat {}');
+
+               $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
+               $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
+               $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
+               $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
+               $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue(NULL));
+               $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
+               $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
+               $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
+               $mockController->_set('request', $mockRequest);
+               $mockController->_set('objectManager', $mockObjectManager);
+
+               $this->assertEquals(
+                       'Tx_MyPackage_View_MyController_MyActionMyFormat',
+                       $mockController->_call('resolveViewObjectName')
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function resolveViewObjectNameUsesNamespacedViewObjectNamePatternForExtensionsWithVendor() {
+               eval('namespace MyVendor\MyPackage\View\MyController; class MyActionMyFormat {}');
+
+               $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
+               $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
+               $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
+               $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
+               $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
+               $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
+               $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
+               $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
+               $mockController->_set('request', $mockRequest);
+               $mockController->_set('objectManager', $mockObjectManager);
+
+               $this->assertEquals(
+                       'MyVendor\MyPackage\View\MyController\MyActionMyFormat',
+                       $mockController->_call('resolveViewObjectName')
+               );
+       }
+
+       /**
+        * @test
         * @author Robert Lemke <robert@typo3.org>
         */
        public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest() {