ExtBase:
authorJochen Rau <j.rau@web.de>
Wed, 15 Apr 2009 08:09:57 +0000 (08:09 +0000)
committerJochen Rau <j.rau@web.de>
Wed, 15 Apr 2009 08:09:57 +0000 (08:09 +0000)
* Changed Configuration Manager: You don't have to call loadGlobalSettings() anymore
* Adapted test cases
* Added test cases for Configuration Manager

typo3/sysext/extbase/Classes/Configuration/Manager.php
typo3/sysext/extbase/Classes/Configuration/Source/TypoScriptSource.php
typo3/sysext/extbase/Classes/MVC/Web/RequestBuilder.php
typo3/sysext/extbase/Tests/Configuration/Manager_testcase.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Persistence/ObjectStorage_testcase.php
typo3/sysext/extbase/Tests/Persistence/Session_testcase.php
typo3/sysext/extbase/class.tx_extbase_dispatcher.php

index 807bebf..db61093 100644 (file)
@@ -22,8 +22,6 @@
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
 
-require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
-
 /**
  * A general purpose configuration manager
  *
@@ -59,39 +57,39 @@ class Tx_Extbase_Configuration_Manager implements t3lib_Singleton {
        /**
         * Returns an array with the settings defined for the specified extension.
         *
-        * @param string $extensionName Key of the extension to return the settings for
+        * @param string $extensionName Name of the extension to return the settings for
         * @return array The settings of the specified extension
         */
        public function getSettings($extensionName, $controllerName = '', $actionName = '') {
-               $settings = array();
-               if (is_array($this->settings[$extensionName])) {
-                       $settings = $this->settings[$extensionName];
-                       if (!empty($controllerName) && is_array($settings[$controllerName])) {
-                               if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
-                                       $settings = $settings[$controllerName][$actionName];
-                               } else {
-                                       $settings = $settings[$controllerName];
-                               }
+               if (empty($this->settings[$extensionName])) {
+                       $this->loadGlobalSettings($extensionName);
+               }
+               $settings = $this->settings[$extensionName];
+               if (!empty($controllerName) && is_array($settings[$controllerName])) {
+                       if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
+                               $settings = $settings[$controllerName][$actionName];
+                       } else {
+                               $settings = $settings[$controllerName];
                        }
-                       // TODO Should we provide a hierarchical TS setting overlay?
-                       // if (!empty($controllerName) && is_array($settings[$controllerName])) {
-                       //      foreach ($settings[$controllerName] as $key => $value) {
-                       //              if (array_key_exists($key, $settings)) {
-                       //                      $settings[$key] = $value;
-                       //              }
-                       //      }
-                       // }
-                       // if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
-                       //      foreach ($settings[$controllerName][$actionName] as $key => $value) {
-                       //              if (array_key_exists($key, $settings)) {
-                       //                      $settings[$key] = $value;
-                       //              }
-                       //              if (array_key_exists($key, $settings[$controllerName])) {
-                       //                      $settings[$controllerName][$key] = $value;
-                       //              }
-                       //      }
-                       // }
                }
+               // TODO Should we provide a hierarchical TS setting overlay?
+               // if (!empty($controllerName) && is_array($settings[$controllerName])) {
+               //      foreach ($settings[$controllerName] as $key => $value) {
+               //              if (array_key_exists($key, $settings)) {
+               //                      $settings[$key] = $value;
+               //              }
+               //      }
+               // }
+               // if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
+               //      foreach ($settings[$controllerName][$actionName] as $key => $value) {
+               //              if (array_key_exists($key, $settings)) {
+               //                      $settings[$key] = $value;
+               //              }
+               //              if (array_key_exists($key, $settings[$controllerName])) {
+               //                      $settings[$controllerName][$key] = $value;
+               //              }
+               //      }
+               // }
                return $settings;
        }
 
@@ -106,9 +104,8 @@ class Tx_Extbase_Configuration_Manager implements t3lib_Singleton {
         * @return void
         * @see getSettings()
         */
-       public function loadGlobalSettings($extensionName) {
-               $settings = $this->settings[$extensionName];
-               if (empty($settings)) $settings = array();
+       protected function loadGlobalSettings($extensionName) {
+               $settings = array();
                foreach ($this->configurationSources as $configurationSource) {
                        $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionName));
                }
index d58156d..8f88437 100644 (file)
@@ -37,7 +37,6 @@ class Tx_Extbase_Configuration_Source_TypoScriptSource implements Tx_Extbase_Con
         * @return array The settings as array without trailing dots
         */
         public function load($extensionName) {
-               // SK: same as with dispatcher. strtolower($extensionName) is wrong; example: tt_news -> tx_ttnews
                $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionName) . '.'];
                if (is_array($settings)) $settings = $this->postProcessSettings($settings);
                return $settings;
index 8357bd9..0c46150 100755 (executable)
@@ -66,7 +66,7 @@ class Tx_Extbase_MVC_Web_RequestBuilder {
         *
         * @var array
         **/
-       protected $allowedControllerActions = array('index', 'error');
+       protected $allowedControllerActions;
        
        public function initialize($configuration) {
                $this->pluginKey = $configuration['pluginKey'];
diff --git a/typo3/sysext/extbase/Tests/Configuration/Manager_testcase.php b/typo3/sysext/extbase/Tests/Configuration/Manager_testcase.php
new file mode 100644 (file)
index 0000000..8ef52f1
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+class Tx_Extbase_Configuration_Manager_testcase extends Tx_Extbase_Base_testcase {
+       
+       public function setUp() {
+               $this->settings = array(
+                       'maxItems' => 3,
+                       'Post' => array(
+                               'singlePid' => 25,
+                               'maxItems' => 8,
+                               'index' => array(
+                                       'maxItems' => 5
+                               ),
+                       ),
+                       'Comment' => array(
+                               'content' => array(
+                                       'crop' => 100
+                                       )
+                               )
+                       );
+               
+               $configurationSource = $this->getMock('Tx_Extbase_Configuration_Source_TypoScriptSource', array('load'));
+               $configurationSource->expects($this->any())
+                       ->method('load')
+                       ->with('Tx_Extbase_Foo_Bar')
+                       ->will($this->returnValue($this->settings));
+               $this->configurationSources = array();
+               $this->configurationSources[] = $configurationSource;
+       }
+       
+       public function test_SettingsCanBeLoaded() {
+               $configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_Manager', $this->configurationSources);
+               $settings = $configurationManager->getSettings('Tx_Extbase_Foo_Bar');
+               $this->assertEquals($this->settings, $settings, 'The retrieved settings differs from the retrieved settings.');         
+       }
+       
+}
+?>
\ No newline at end of file
index b6df181..e861a94 100644 (file)
@@ -65,21 +65,6 @@ class Tx_Extbase_Persistence_ObjectStorage_testcase extends Tx_Extbase_Base_test
                $objectStorage[] = $object;
        }
                
-       public function test_AddingAValueOtherThanAnObjectThrowsAnException() {
-               $this->setExpectedException('Tx_Extbase_Exception_InvalidArgumentType');
-               $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
-               $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
-               $objectStorage[$object] = 'foo';
-       }
-       
-       public function test_IfTheOffsetAndTheValueAreNotEqualAnExceptionIsThrown() {
-               $this->setExpectedException('Tx_Extbase_Exception_InvalidArgumentType');
-               $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
-               $object1 = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
-               $object2 = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
-               $objectStorage[$object1] = $object2;
-       }       
-       
        public function test_AnObjectCouldBeSetViaAnOffset() {
                $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
                $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
index b0179a8..d503863 100644 (file)
@@ -46,9 +46,8 @@ class Tx_Extbase_Persistence_Session_testcase extends tx_phpunit_testcase {
                $addedObjects = $persistenceSession->getAddedObjects();
                $removedObjects = $persistenceSession->getRemovedObjects();
                $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
-               
-               $this->assertEquals(1, count($addedObjects), 'The added objects storage holds 0 or more than 1 objects.');
-               $this->assertSame($entity, $addedObjects[0], 'The returned object was not the same as the registered one.');
+
+               $this->assertTrue(!empty($addedObjects[$entity]), 'The object was not added.');
                $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
                $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
        }
@@ -62,8 +61,7 @@ class Tx_Extbase_Persistence_Session_testcase extends tx_phpunit_testcase {
                $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
                
                $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
-               $this->assertEquals(1, count($removedObjects), 'The removed objects storage holds 0 or more than 1 objects.');
-               $this->assertSame($entity, $removedObjects[0], 'The returned object was not the same as the registered one.');
+               $this->assertTrue(!empty($removedObjects[$entity]), 'The object was not registered as removed.');
                $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
        }
 
@@ -74,11 +72,9 @@ class Tx_Extbase_Persistence_Session_testcase extends tx_phpunit_testcase {
                $addedObjects = $persistenceSession->getAddedObjects();
                $removedObjects = $persistenceSession->getRemovedObjects();
                $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
-               
                $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
                $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
-               $this->assertEquals(1, count($reconstitutedObjects), 'The reconstituted objects storage holds 0 or more than 1 objects.');
-               $this->assertSame($entity, $reconstitutedObjects[0], 'The returned object was not the same as the registered one.');
+               $this->assertTrue(!empty($reconstitutedObjects[$entity]), 'The object was not registered as reconstituted.');
        }
 
        public function test_ObjectCanBeUnregisteredAsAdded() {
@@ -216,7 +212,7 @@ class Tx_Extbase_Persistence_Session_testcase extends tx_phpunit_testcase {
                $persistenceSession->registerReconstitutedObject($entity);
                $dirtyObjects = $persistenceSession->getDirtyObjects();
                $this->assertEquals(1, count($dirtyObjects), 'There is more than one dirty object.');
-               $this->assertEquals($entity, $dirtyObjects[0], 'The entity doesn\'t equal to the dirty object retrieved from the persistenceSession.');
+               $this->assertTrue(!empty($dirtyObjects[$entity]), 'The entity doesn\'t equal to the dirty object retrieved from the persistenceSession.');
        }
 
        
index 24943fd..6d6de00 100644 (file)
@@ -48,9 +48,9 @@ class Tx_Extbase_Dispatcher {
        /**
         * Creates a request an dispatches it to a controller.
         *
-        * @param String $content The content
+        * @param string $content The content
         * @param array|NULL $configuration The TS configuration array
-        * @return String $content The processed content
+        * @return string $content The processed content
         */
        public function dispatch($content, $configuration) {
                if (!is_array($configuration)) {
@@ -113,7 +113,6 @@ class Tx_Extbase_Dispatcher {
                        $configurationSources[] = $configurationSource;
                }
                $configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_Manager', $configurationSources);
-               $configurationManager->loadGlobalSettings($extensionName);
                return $configurationManager->getSettings($extensionName);
        }