[+BUGFIX] Extbase (MVC): Improve Error Handling in Request Builder
authorSebastian Kurfürst <sebastian@typo3.org>
Thu, 20 Jan 2011 06:17:23 +0000 (06:17 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Thu, 20 Jan 2011 06:17:23 +0000 (06:17 +0000)
In the RequestBuilder, there is no error-handling which you get,
in case you've forgotten to configure the controllerActions in ext_localconf.php.

This patch adds some exceptions - you can't go without this config and things will break lateron anyway.

Thanks to Felix Oertel for the Patch!

Resolves: #11302

typo3/sysext/extbase/Classes/MVC/Web/RequestBuilder.php
typo3/sysext/extbase/Tests/Unit/MVC/Web/RequestBuilderTest.php

index d54ebce..de63f20 100644 (file)
@@ -136,14 +136,27 @@ class Tx_Extbase_MVC_Web_RequestBuilder implements t3lib_Singleton {
 
                if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions)) {
                        $controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING);
-               } else {
+               } elseif (!empty($this->defaultControllerName)) {
                        $controllerName = $this->defaultControllerName;
+               } else {
+                       throw new Tx_Extbase_MVC_Exception(
+                               'The default controller can not be determined.<br />'
+                               . 'Please check for Tx_Extbase_Utility_Extension::configurePlugin() in your ext_localconf.php.',
+                               1295479650
+                       );
                }
+
                $allowedActions = $this->allowedControllerActions[$controllerName];
                if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
                        $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING);
-               } else {
+               } elseif (!empty($this->defaultActionName)) {
                        $actionName = $this->defaultActionName;
+               } else {
+                       throw new Tx_Extbase_MVC_Exception(
+                               'The default action can not be determined for controller "' . $controllerName . '".<br />'
+                               . 'Please check Tx_Extbase_Utility_Extension::configurePlugin() in your ext_localconf.php.',
+                               1295479651
+                       );
                }
 
                $request = $this->objectManager->create('Tx_Extbase_MVC_Web_Request');
index d7c4e25..6527883 100644 (file)
@@ -216,6 +216,28 @@ class Tx_Extbase_Tests_Unit_MVC_Web_RequestBuilderTest extends Tx_Extbase_Tests_
 
        /**
         * @test
+        * @expectedException Tx_Extbase_MVC_Exception
+        */
+       public function buildThrowsExceptionIfControllerConfigurationIsEmptyOrNotSet() {
+               unset($this->configuration['controllerConfiguration']);
+               $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($this->mockConfigurationManager);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_MVC_Exception
+        */
+       public function buildThrowsExceptionIfControllerConfigurationHasNoDefaultActionDefined() {
+               $this->configuration['controllerConfiguration']['TheFirstController'] = array();
+               $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($this->mockConfigurationManager);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
         */
        public function buildSetsParametersFromGetAndPostVariables() {
                $this->configuration['extensionName'] = 'SomeExtensionName';