[~TASK] Extbase: Moved isActionCacheable() from UriBuilder to Utility/Extension helpe...
authorBastian Waidelich <bastian@typo3.org>
Mon, 24 Jan 2011 16:44:45 +0000 (16:44 +0000)
committerBastian Waidelich <bastian@typo3.org>
Mon, 24 Jan 2011 16:44:45 +0000 (16:44 +0000)
Moved the protected method to a public static functions in Tx_Extbase_Utility_Extension
and added respective unit tests.
Note: We're not happy with all the public static functions in Utility/Extension.php
but that's currently the place for those helper functions.

typo3/sysext/extbase/Classes/MVC/Web/Routing/UriBuilder.php
typo3/sysext/extbase/Classes/Utility/Extension.php
typo3/sysext/extbase/Tests/Unit/MVC/Web/Routing/UriBuilderTest.php
typo3/sysext/extbase/Tests/Unit/Utility/ExtensionTest.php

index 8b38043..cb1e0cb 100644 (file)
@@ -468,8 +468,8 @@ class Tx_Extbase_MVC_Web_Routing_UriBuilder {
                $this->arguments = t3lib_div::array_merge_recursive_overrule($this->arguments, $prefixedControllerArguments);
 
                if ($actionName !== NULL
-                       && $this->getUseCacheHash() === TRUE
-                       && !$this->isActionCacheable($actionName, $controllerArguments['controller'], $extensionName, $pluginName)) {
+                       && $this->useCacheHash === TRUE
+                       && !Tx_Extbase_Utility_Extension::isActionCacheable($extensionName, $controllerArguments['controller'], $pluginName, $actionName)) {
                                $this->setUseCacheHash(FALSE);
                }
 
@@ -647,31 +647,5 @@ class Tx_Extbase_MVC_Web_Routing_UriBuilder {
                return $result;
        }
 
-       /**
-        * Checks if the given action is cacheable or not.
-        *
-        * @param string $actionName Name of the action to be called
-        * @param string $controllerName Name of the target controller.
-        * @param string $extensionName Name of the target extension, without underscores.
-        * @param string $pluginName Name of the target plugin.
-        * @return boolean
-        */
-       protected function isActionCacheable($actionName, $controllerName, $extensionName, $pluginName) {
-               $frameworkConfiguration = $this->configurationManager->getConfiguration(
-                       Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
-                       $extensionName,
-                       $pluginName
-               );
-
-               if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName])
-                       && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName])
-                       && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])
-                       && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
-                               return FALSE;
-               }
-
-               return TRUE;
-       }
-
 }
 ?>
\ No newline at end of file
index 8ebcaf9..23a2ec5 100644 (file)
@@ -507,6 +507,29 @@ tt_content.' . $pluginSignature . ' {
        }
 
        /**
+        * Checks if the given action is cacheable or not.
+        *
+        * @param string $extensionName Name of the target extension, without underscores
+        * @param string $pluginName Name of the target plugin
+        * @param string $controllerName Name of the target controller
+        * @param string $actionName Name of the action to be called
+        * @return boolean TRUE if the specified plugin action is cacheable, otherwise FALSE
+        */
+       static public function isActionCacheable($extensionName, $pluginName, $controllerName, $actionName) {
+               $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
+               $configurationManager = $objectManager->get('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $frameworkConfiguration = $configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
+
+               if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName])
+                       && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName])
+                       && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])
+                       && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
+                               return FALSE;
+               }
+               return TRUE;
+       }
+
+       /**
         * Determines the target page of the specified plugin.
         * If plugin.tx_$pluginSignature.view.defaultPid is set, this value is used as target page id
         * If defaultPid is set to "auto", a the target pid is determined by loading the tt_content record that contains this plugin
index c65ce5a..3900185 100644 (file)
@@ -178,6 +178,28 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
        /**
         * @test
         */
+       public function uriForDisablesCacheHashForNonCacheableActions() {
+               $mockConfiguration = array(
+                       'controllerConfiguration' => array(
+                               'SomeController' => array(
+                                       'nonCacheableActions' => array('someNonCacheableAction')
+                               )
+                       )
+               );
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $this->assertTrue($this->uriBuilder->getUseCacheHash());
+               $this->uriBuilder->uriFor('someNonCacheableAction', array(), 'SomeController', 'SomeExtension');
+               $this->assertFalse($this->uriBuilder->getUseCacheHash());
+       }
+
+       /**
+        * @test
+        */
        public function buildBackendUriKeepsQueryParametersIfAddQueryStringIsSet() {
                t3lib_div::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar'));
 
index 0e99ba8..38f30f6 100644 (file)
@@ -498,6 +498,42 @@ plugin.tx_myextension {
        /**
         * @test
         */
+       public function isActionCacheableReturnsTrueByDefault() {
+               $mockConfiguration = array();
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $actualResult = Tx_Extbase_Utility_Extension::isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
+               $this->assertTrue($actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function isActionCacheableReturnsFalseIfActionIsNotCacheable() {
+               $mockConfiguration = array(
+                       'controllerConfiguration' => array(
+                               'SomeController' => array(
+                                       'nonCacheableActions' => array('someAction')
+                               )
+                       )
+               );
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $actualResult = Tx_Extbase_Utility_Extension::isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
+               $this->assertFalse($actualResult);
+       }
+
+       /**
+        * @test
+        */
        public function getTargetPidByPluginSignatureReturnsNullIfConfigurationManagerIsNotInitialized() {
                $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
                $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(NULL));