[BUGFIX] Reset 'vendorName' in RequestBuilder to NULL for new requests
authorAndreas Kiessling <andreas.kiessling@web.de>
Sat, 17 Nov 2012 10:36:55 +0000 (11:36 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 17 Nov 2012 10:51:31 +0000 (11:51 +0100)
It is currently impossible to use extensions with AND without
namespaces on the same page, since the vendorName is not reset
when a new request is built. So when the request is analyzed later on,
a vendor from a previous plugin may be found and thus the wrong
classname is built.

This patch resets the vendorName to NULL in method 'loadDefaultValues'.

Releases: 6.0
Fixes: #42782

Change-Id: Ie2d74a7140b325826fb752505e7569069f77146c
Reviewed-on: http://review.typo3.org/16481
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Mvc/Web/RequestBuilder.php
typo3/sysext/extbase/Tests/Unit/Mvc/Web/RequestBuilderTest.php

index f14c2a0..65a20d6 100644 (file)
@@ -128,8 +128,10 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
                if (empty($configuration['pluginName'])) {
                        throw new \TYPO3\CMS\Extbase\Mvc\Exception('"pluginName" is not properly configured. Request can\'t be dispatched!', 1289843277);
                }
-               if (NULL !== $configuration['vendorName']) {
+               if (!empty($configuration['vendorName'])) {
                        $this->vendorName = $configuration['vendorName'];
+               } else {
+                       $this->vendorName = NULL;
                }
                $this->extensionName = $configuration['extensionName'];
                $this->pluginName = $configuration['pluginName'];
@@ -160,7 +162,7 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
                $actionName = $this->resolveActionName($controllerName, $parameters);
                /** @var $request \TYPO3\CMS\Extbase\Mvc\Web\Request */
                $request = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
-               if (NULL !== $this->vendorName) {
+               if ($this->vendorName !== NULL) {
                        $request->setControllerVendorName($this->vendorName);
                }
                $request->setPluginName($this->pluginName);
index caa14cc..0766edb 100644 (file)
@@ -59,21 +59,6 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        protected $mockRequest;
 
-       /**
-        * @var array
-        */
-       protected $getBackup = array();
-
-       /**
-        * @var array
-        */
-       protected $postBackup = array();
-
-       /**
-        * @var array
-        */
-       protected $serverBackup = array();
-
        public function setUp() {
                $this->requestBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\RequestBuilder', array('dummy'));
                $this->configuration = array(
@@ -98,9 +83,6 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
                $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
                $this->mockExtensionService = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\ExtensionService');
-               $this->getBackup = $_GET;
-               $this->postBackup = $_POST;
-               $this->serverBackup = $_SERVER;
        }
 
        /**
@@ -116,12 +98,6 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->requestBuilder->injectExtensionService($this->mockExtensionService);
        }
 
-       public function tearDown() {
-               $_GET = $this->getBackup;
-               $_POST = $this->postBackup;
-               $_SERVER = $this->serverBackup;
-       }
-
        /**
         * @test
         */
@@ -200,6 +176,45 @@ class RequestBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        */
+       public function buildSetsVendorNameIfConfigured() {
+               $this->injectDependencies();
+               $expectedVendor = 'Vendor';
+               $this->configuration['vendorName'] = $expectedVendor;
+               $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($mockConfigurationManager);
+               $this->requestBuilder->injectExtensionService($this->mockExtensionService);
+               $this->mockRequest->expects($this->once())->method('setControllerVendorName')->with($expectedVendor);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        */
+       public function buildDoesNotSetVendorNameIfNotConfiguredInSecondRequest() {
+               $this->injectDependencies();
+               $expectedVendor = 'Vendor';
+               $this->configuration['vendorName'] = $expectedVendor;
+
+               $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($mockConfigurationManager);
+               $this->mockRequest->expects($this->once())->method('setControllerVendorName')->with($expectedVendor);
+
+               $this->requestBuilder->build();
+
+               unset($this->configuration['vendorName']);
+               $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($mockConfigurationManager);
+
+               $this->mockRequest->expects($this->never())->method('setControllerVendorName');
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
         * @expectedException \TYPO3\CMS\Extbase\Mvc\Exception
         */
        public function buildThrowsExceptionIfExtensionNameIsNotConfigured() {