[+TASK] Extbase (MVC): Backported changes in Request. Request::getControllerActionNam...
authorBastian Waidelich <bastian@typo3.org>
Fri, 18 Jun 2010 10:27:53 +0000 (10:27 +0000)
committerBastian Waidelich <bastian@typo3.org>
Fri, 18 Jun 2010 10:27:53 +0000 (10:27 +0000)
[~TASK] Extbase (MVC): Some comment tweaks

typo3/sysext/extbase/Classes/MVC/Controller/ActionController.php
typo3/sysext/extbase/Classes/MVC/Request.php
typo3/sysext/extbase/Tests/MVC/Controller/ActionController_testcase.php

index 19c0675..e253248 100644 (file)
@@ -202,9 +202,9 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
        }
 
        /**
-        * Determines the action method and assures that the method exists.
+        * Resolves and checks the current action method name
         *
-        * @return string The action method name
+        * @return string Method name of the current action
         * @throws Tx_Extbase_MVC_Exception_NoSuchAction if the action specified in the request object does not exist (and if there's no default action either).
         */
        protected function resolveActionMethodName() {
index 6a3fa7d..d8c8c90 100644 (file)
@@ -212,7 +212,7 @@ class Tx_Extbase_MVC_Request implements Tx_Extbase_MVC_RequestInterface {
        /**
         * Sets the name of the action contained in this request.
         *
-        * Note that the action name must start with a lower case letter.
+        * Note that the action name must start with a lower case letter and is case sensitive.
         *
         * @param string $actionName: Name of the action to execute by the controller
         * @return void
@@ -233,6 +233,16 @@ class Tx_Extbase_MVC_Request implements Tx_Extbase_MVC_RequestInterface {
         * @api
         */
        public function getControllerActionName() {
+               $controllerObjectName = $this->getControllerObjectName();
+               if ($controllerObjectName !== '' && ($this->controllerActionName === strtolower($this->controllerActionName))) {
+                       $actionMethodName = $this->controllerActionName . 'Action';
+                       foreach (get_class_methods($controllerObjectName) as $existingMethodName) {
+                               if (strtolower($existingMethodName) === strtolower($actionMethodName)) {
+                                       $this->controllerActionName = substr($existingMethodName, 0, -6);
+                                       break;
+                               }
+                       }
+               }
                return $this->controllerActionName;
        }
 
index da49545..7c4265b 100644 (file)
@@ -214,6 +214,35 @@ class Tx_Extbase_MVC_Controller_ActionController_testcase extends Tx_Extbase_Bas
         * @test
         * @author Robert Lemke <robert@typo3.org>
         */
+       public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest() {
+               $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
+               $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
+
+               $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array('fooBarAction'), array(), '', FALSE);
+               $mockController->_set('request', $mockRequest);
+
+               $this->assertEquals('fooBarAction', $mockController->_call('resolveActionMethodName'));
+       }
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_MVC_Exception_NoSuchAction
+        * @author Robert Lemke <robert@typo3.org>
+        */
+       public function resolveActionMethodNameThrowsAnExceptionIfTheActionDefinedInTheRequestDoesNotExist() {
+               $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
+               $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
+
+               $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array('otherBarAction'), array(), '', FALSE);
+               $mockController->_set('request', $mockRequest);
+
+               $mockController->_call('resolveActionMethodName');
+       }
+
+       /**
+        * @test
+        * @author Robert Lemke <robert@typo3.org>
+        */
        public function initializeActionMethodArgumentsRegistersArgumentsFoundInTheSignatureOfTheCurrentActionMethod() {
                $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);