[+TASK] Extbase (Tests): Fixed Extbase unit tests
authorBastian Waidelich <bastian@typo3.org>
Wed, 12 Jan 2011 15:27:48 +0000 (15:27 +0000)
committerBastian Waidelich <bastian@typo3.org>
Wed, 12 Jan 2011 15:27:48 +0000 (15:27 +0000)
Additionally some code cleanups and minor tweaks

This resolves: #10792

13 files changed:
typo3/sysext/extbase/Classes/MVC/Controller/ActionController.php
typo3/sysext/extbase/Classes/MVC/Controller/Argument.php
typo3/sysext/extbase/Classes/MVC/Web/Routing/UriBuilder.php
typo3/sysext/extbase/Classes/Persistence/Repository.php
typo3/sysext/extbase/Tests/Unit/MVC/Controller/ActionControllerTest.php
typo3/sysext/extbase/Tests/Unit/MVC/Controller/ArgumentTest.php
typo3/sysext/extbase/Tests/Unit/MVC/Controller/ArgumentsTest.php
typo3/sysext/extbase/Tests/Unit/MVC/Web/RequestBuilderTest.php
typo3/sysext/extbase/Tests/Unit/MVC/Web/Routing/UriBuilderTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/QueryResultTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php
typo3/sysext/extbase/Tests/Unit/Reflection/ServiceTest.php
typo3/sysext/extbase/Tests/Unit/Utility/ExtensionTest.php

index 25026ef..58eb480 100644 (file)
@@ -123,7 +123,9 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
         * @return void
         */
        public function processRequest(Tx_Extbase_MVC_RequestInterface $request, Tx_Extbase_MVC_ResponseInterface $response) {
-               if (!$this->canProcessRequest($request)) throw new Tx_Extbase_MVC_Exception_UnsupportedRequestType(get_class($this) . ' does not support requests of type "' . get_class($request) . '". Supported types are: ' . implode(' ', $this->supportedRequestTypes) , 1187701131);
+               if (!$this->canProcessRequest($request)) {
+                       throw new Tx_Extbase_MVC_Exception_UnsupportedRequestType(get_class($this) . ' does not support requests of type "' . get_class($request) . '". Supported types are: ' . implode(' ', $this->supportedRequestTypes) , 1187701131);
+               }
 
                $this->request = $request;
                $this->request->setDispatched(TRUE);
@@ -147,7 +149,9 @@ class Tx_Extbase_MVC_Controller_ActionController extends Tx_Extbase_MVC_Controll
                $this->checkRequestHash();
                $this->controllerContext = $this->buildControllerContext();
                $this->view = $this->resolveView();
-               if ($this->view !== NULL) $this->initializeView($this->view);
+               if ($this->view !== NULL) {
+                       $this->initializeView($this->view);
+               }
                $this->callActionMethod();
        }
 
index ff9264f..542114c 100644 (file)
@@ -309,7 +309,9 @@ class Tx_Extbase_MVC_Controller_Argument {
                        $this->validator = $this->objectManager->create('Tx_Extbase_Validation_Validator_ConjunctionValidator');
                }
                foreach ($objectNames as $objectName) {
-                       if (!class_exists($objectName)) $objectName = 'Tx_Extbase_Validation_Validator_' . $objectName;
+                       if (!class_exists($objectName)) {
+                               $objectName = 'Tx_Extbase_Validation_Validator_' . $objectName;
+                       }
                        $this->validator->addValidator($this->objectManager->get($objectName));
                }
                return $this;
index b5e35f3..3daf718 100644 (file)
@@ -111,6 +111,14 @@ class Tx_Extbase_MVC_Web_Routing_UriBuilder {
         */
        public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
                $this->configurationManager = $configurationManager;
+       }
+
+       /**
+        * Life-cycle method that is called by the DI container as soon as this object is completely built
+        *
+        * @return void
+        */
+       public function initializeObject() {
                $this->contentObject = $this->configurationManager->getContentObject();
        }
 
@@ -416,7 +424,7 @@ class Tx_Extbase_MVC_Web_Routing_UriBuilder {
 
        /**
         * Creates an URI used for linking to an Extbase action.
-        * Works in Frondend and Backend mode of TYPO3.
+        * Works in Frontend and Backend mode of TYPO3.
         *
         * @param string $actionName Name of the action to be called
         * @param array $controllerArguments Additional query parameters. Will be "namespaced" and merged with $this->arguments.
@@ -451,10 +459,10 @@ class Tx_Extbase_MVC_Web_Routing_UriBuilder {
                if ($this->format !== '') {
                        $controllerArguments['format'] = $this->format;
                }
-               $pluginNamespace = Tx_Extbase_Utility_Extension::getPluginNamespace($extensionName, $pluginName);
                if ($this->argumentPrefix !== NULL) {
                        $prefixedControllerArguments = array($this->argumentPrefix => $controllerArguments);
                } else {
+                       $pluginNamespace = Tx_Extbase_Utility_Extension::getPluginNamespace($extensionName, $pluginName);
                        $prefixedControllerArguments = array($pluginNamespace => $controllerArguments);
                }
                $this->arguments = t3lib_div::array_merge_recursive_overrule($this->arguments, $prefixedControllerArguments);
@@ -589,7 +597,7 @@ class Tx_Extbase_MVC_Web_Routing_UriBuilder {
                        // if we have a LazyLoadingProxy here, make sure to get the real instance for further processing
                        if ($argumentValue instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
                                $argumentValue = $argumentValue->_loadRealInstance();
-                               // also update the value in the arguments array, because the lazyLoaded object could be 
+                               // also update the value in the arguments array, because the lazyLoaded object could be
                                // hidden and thus the $argumentValue would be NULL.
                                $arguments[$argumentKey] = $argumentValue;
                        }
index f942e31..a4a9203 100644 (file)
@@ -123,10 +123,10 @@ class Tx_Extbase_Persistence_Repository implements Tx_Extbase_Persistence_Reposi
        }
 
        /**
-        * @param Tx_Extbase_Persistence_Manager $persistenceManager
+        * @param Tx_Extbase_Persistence_ManagerInterface $persistenceManager
         * @return void
         */
-       public function injectPersistenceManager(Tx_Extbase_Persistence_Manager $persistenceManager) {
+       public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $persistenceManager) {
                $this->persistenceManager = $persistenceManager;
                $this->persistenceManager->registerRepositoryClassName($this->getRepositoryClassName());
        }
@@ -295,7 +295,10 @@ class Tx_Extbase_Persistence_Repository implements Tx_Extbase_Persistence_Reposi
                        $query = $this->createQuery();
                        $query->getQuerySettings()->setRespectSysLanguage(FALSE);
                        $query->getQuerySettings()->setRespectStoragePage(FALSE);
-                       $object = $query->matching($query->equals('uid', $uid))
+                       $object = $query
+                                       ->matching(
+                                               $query->equals('uid', $uid)
+                                       )
                                        ->execute()
                                        ->getFirst();
                        if ($object !== NULL) {
index b59d82f..e28be51 100644 (file)
@@ -32,26 +32,50 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extba
         */
        protected $actionController;
 
+       /**
+        * @var Tx_Extbase_Object_ObjectManagerInterface
+        */
+       protected $mockObjectManager;
+
+       /**
+        * @var Tx_Extbase_MVC_Web_Routing_UriBuilder
+        */
+       protected $mockUriBuilder;
+
        public function setUp() {
                $this->actionController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController');
+               //$this->mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder');
+               //$this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               //$this->mockObjectManager->expects($this->any())->method('create')->with('Tx_Extbase_MVC_Web_Routing_UriBuilder')->will($this->returnValue($this->mockUriBuilder));
+               //$this->actionController->_set('objectManager', $this->mockObjectManager);
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function processRequestSticksToSpecifiedSequence() {
                $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array(), array(), '', FALSE);
                $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE);
 
+               $mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder');
+               $mockUriBuilder->expects($this->once())->method('setRequest')->with($mockRequest);
+
+               $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE);
+
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Web_Routing_UriBuilder')->will($this->returnValue($mockUriBuilder));
+
                $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response', array(), array(), '', FALSE);
 
                $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
 
-               $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array(
-                       'initializeFooAction', 'initializeAction', 'resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'resolveView', 'initializeView', 'callActionMethod', 'checkRequestHash'),
+               $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array(
+                       'initializeFooAction', 'initializeAction', 'resolveActionMethodName', 'initializeActionMethodArguments',
+                       'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext',
+                       'resolveView', 'initializeView', 'callActionMethod'),
                        array(), '', FALSE);
-               $mockController->_set('objectFactory', $mockObjectFactory);
+
+               $mockController->_set('objectManager', $mockObjectManager);
                $mockController->expects($this->at(0))->method('resolveActionMethodName')->will($this->returnValue('fooAction'));
                $mockController->expects($this->at(1))->method('initializeActionMethodArguments');
                $mockController->expects($this->at(2))->method('initializeActionMethodValidators');
@@ -59,9 +83,8 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extba
                $mockController->expects($this->at(4))->method('initializeFooAction');
                $mockController->expects($this->at(5))->method('mapRequestArgumentsToControllerArguments');
                $mockController->expects($this->at(6))->method('checkRequestHash');
-               $mockController->expects($this->at(7))->method('resolveView')->will($this->returnValue($mockView));
-               $mockController->expects($this->at(8))->method('initializeView');
-               $mockController->expects($this->at(9))->method('callActionMethod');
+               $mockController->expects($this->at(7))->method('buildControllerContext');
+               $mockController->expects($this->at(8))->method('resolveView');
 
                $mockController->processRequest($mockRequest, $mockResponse);
                $this->assertSame($mockRequest, $mockController->_get('request'));
@@ -183,17 +206,18 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extba
                $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface');
                $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE);
 
-               $mockFluidTemplateView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface', array('setControllerContext', 'getViewHelper', 'assign', 'assignMultiple', 'render', 'hasTemplate', 'initializeView'));
+               $mockFluidTemplateView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
                $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
-               $mockFluidTemplateView->expects($this->once())->method('hasTemplate')->will($this->returnValue(TRUE));
+               $mockFluidTemplateView->expects($this->once())->method('canRender')->with($mockControllerContext)->will($this->returnValue(TRUE));
 
                $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface', array(), array(), '', FALSE);
-               $mockObjectManager->expects($this->at(0))->method('get')->with('Tx_Fluid_View_TemplateView')->will($this->returnValue($mockFluidTemplateView));
+               $mockObjectManager->expects($this->at(0))->method('create')->with('Tx_Fluid_View_TemplateView')->will($this->returnValue($mockFluidTemplateView));
 
-               $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('buildControllerContext'), array(), '', FALSE);
-               $mockController->expects($this->once())->method('buildControllerContext')->will($this->returnValue($mockControllerContext));
+               $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('buildControllerContext', 'resolveViewObjectName', 'setViewConfiguration'), array(), '', FALSE);
+               $mockController->expects($this->once())->method('resolveViewObjectName')->will($this->returnValue(FALSE));
                $mockController->_set('session', $mockSession);
                $mockController->_set('objectManager', $mockObjectManager);
+               $mockController->_set('controllerContext', $mockControllerContext);
 
                $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
        }
@@ -207,7 +231,7 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extba
                $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
                $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
                $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
-               $mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('MyFormat'));
+               $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
 
                $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface', array(), array(), '', FALSE);
 
@@ -510,7 +534,7 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extba
                $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
                $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
 
-               $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('pushFlashMessage'), array(), '', FALSE);
+               $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('pushFlashMessage', 'clearCacheOnError'), array(), '', FALSE);
                $mockController->_set('request', $mockRequest);
                $mockController->_set('flashMessages', $mockFlashMessages);
                $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
@@ -528,7 +552,7 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extba
                $this->markTestIncomplete('To be implemented');
        }
 
-        /**
+       /**
         * Data Provider for checkRequestHashDoesNotThrowExceptionInNormalOperations
         */
        public function checkRequestHashInNormalOperation() {
index 9eaa66d..37aa0c3 100644 (file)
@@ -133,9 +133,12 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentTest extends Tx_Extbase_Tests
         */
        public function setNewValidatorConjunctionCreatesANewValidatorConjunctionObject() {
                $argument = new Tx_Extbase_MVC_Controller_Argument('dummy', 'Text');
+               $mockConjunctionValidator = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator');
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_Validation_Validator_ConjunctionValidator')->will($this->returnValue($mockConjunctionValidator));
+               $argument->injectObjectManager($mockObjectManager);
                $argument->setNewValidatorConjunction(array());
-
-               $this->assertType('Tx_Extbase_Validation_Validator_ConjunctionValidator', $argument->getValidator(), 'The returned validator is not a conjunction as expected.');
+               $this->assertSame($mockConjunctionValidator, $argument->getValidator());
        }
 
        /**
@@ -161,6 +164,11 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentTest extends Tx_Extbase_Tests
                $mockValidatorConjunction->expects($this->at(1))->method('addValidator')->with($validator2);
 
                $argument = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_Argument'), array('dummy'), array(), '', FALSE);
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->never())->method('create');
+               $mockObjectManager->expects($this->at(0))->method('get')->with('Validator1')->will($this->returnValue($validator1));
+               $mockObjectManager->expects($this->at(1))->method('get')->with('Validator2')->will($this->returnValue($validator2));
+               $argument->injectObjectManager($mockObjectManager);
                $argument->_set('validator', $mockValidatorConjunction);
                $argument->setNewValidatorConjunction(array('Validator1', 'Validator2'));
        }
index 06070bc..79f9227 100644 (file)
@@ -31,8 +31,8 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
         * @test
         */
        public function argumentsObjectIsOfScopePrototype() {
-               $arguments1 = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments2 = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
+               $arguments1 = new Tx_Extbase_MVC_Controller_Arguments();
+               $arguments2 = new Tx_Extbase_MVC_Controller_Arguments();
                $this->assertNotSame($arguments1, $arguments2, 'The arguments object is not of scope prototype!');
        }
 
@@ -40,8 +40,8 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
         * @test
         */
        public function addingAnArgumentManuallyWorks() {
-               $arguments = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
-               $newArgument = $this->objectManager->get('Tx_Extbase_MVC_Controller_Argument', 'argumentName1234', 'dummyValue');
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments();
+               $newArgument = new Tx_Extbase_MVC_Controller_Argument('argumentName1234', 'dummyValue');
 
                $arguments->addArgument($newArgument);
                $this->assertSame($newArgument, $arguments->getArgument('argumentName1234'), 'The added and retrieved argument is not the same.');
@@ -69,11 +69,14 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
         */
        public function addNewArgumentProvidesFluentInterface() {
                $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array(), '', FALSE);
-               $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
-               $mockArguments->expects($this->any())->method('createArgument')->will($this->returnValue($mockArgument));
 
-               $newArgument = $mockArguments->addNewArgument('someArgument');
-               $this->assertType('Tx_Extbase_MVC_Controller_Argument', $newArgument, 'addNewArgument() did not return an argument object.');
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Controller_Argument')->will($this->returnValue($mockArgument));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments->injectObjectManager($mockObjectManager);
+
+               $newArgument = $arguments->addNewArgument('someArgument');
+               $this->assertSame($newArgument, $mockArgument);
        }
 
        /**
@@ -105,7 +108,7 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
         * @test
         */
        public function getArgumentWithNonExistingArgumentNameThrowsException() {
-               $arguments = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments();
                try {
                        $arguments->getArgument('someArgument');
                        $this->fail('getArgument() did not throw an exception although the specified argument does not exist.');
@@ -173,13 +176,16 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
        public function addNewArgumentCreatesAndAddsNewArgument() {
                $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
                $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
-               $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
-               $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'))->will($this->returnValue($mockArgument));
 
-               $addedArgument = $mockArguments->addNewArgument('dummyName');
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Controller_Argument')->will($this->returnValue($mockArgument));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments->injectObjectManager($mockObjectManager);
+
+               $addedArgument = $arguments->addNewArgument('dummyName');
                $this->assertType('Tx_Extbase_MVC_Controller_Argument', $addedArgument, 'addNewArgument() either did not add a new argument or did not return it.');
 
-               $retrievedArgument = $mockArguments['dummyName'];
+               $retrievedArgument = $arguments['dummyName'];
                $this->assertSame($addedArgument, $retrievedArgument, 'The added and the retrieved argument are not the same.');
        }
 
@@ -189,10 +195,12 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
        public function addNewArgumentAssumesTextDataTypeByDefault() {
                $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
                $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
-               $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
-               $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'), $this->equalTo('Text'))->will($this->returnValue($mockArgument));
 
-               $addedArgument = $mockArguments->addNewArgument('dummyName');
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Controller_Argument', 'dummyName', 'Text')->will($this->returnValue($mockArgument));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments->injectObjectManager($mockObjectManager);
+               $arguments->addNewArgument('dummyName');
        }
 
        /**
@@ -200,25 +208,28 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
         */
        public function addNewArgumentCanAddArgumentsMarkedAsRequired() {
                $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'setRequired'), array(), '', FALSE);
-               $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
-               $mockArgument->expects($this->any())->method('setRequired')->with(TRUE);
-               $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
-               $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'), $this->equalTo('Text'))->will($this->returnValue($mockArgument));
-
-               $addedArgument = $mockArguments->addNewArgument('dummyName', 'Text', TRUE);
+               $mockArgument->expects($this->once())->method('getName')->will($this->returnValue('dummyName'));
+               $mockArgument->expects($this->once())->method('setRequired')->with(TRUE);
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Controller_Argument', 'dummyName', 'Text')->will($this->returnValue($mockArgument));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments->injectObjectManager($mockObjectManager);
+               $arguments->addNewArgument('dummyName', 'Text', TRUE);
        }
 
        /**
         * @test
         */
        public function addNewArgumentCanAddArgumentsMarkedAsOptionalWithDefaultValues() {
-               $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'setRequired'), array(), '', FALSE);
-               $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('dummyName'));
-               $mockArgument->expects($this->any())->method('setRequired')->with(TRUE);
-               $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('createArgument'));
-               $mockArguments->expects($this->any())->method('createArgument')->with($this->equalTo('dummyName'), $this->equalTo('Text'))->will($this->returnValue($mockArgument));
-
-               $addedArgument = $mockArguments->addNewArgument('dummyName', 'Text', TRUE);
+               $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'setRequired', 'setDefaultValue'), array(), '', FALSE);
+               $mockArgument->expects($this->once())->method('getName')->will($this->returnValue('dummyName'));
+               $mockArgument->expects($this->once())->method('setRequired')->with(FALSE);
+               $mockArgument->expects($this->once())->method('setDefaultValue')->with('someDefaultValue');
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Controller_Argument', 'dummyName', 'Text')->will($this->returnValue($mockArgument));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments->injectObjectManager($mockObjectManager);
+               $arguments->addNewArgument('dummyName', 'Text', FALSE, 'someDefaultValue');
        }
 
        /**
@@ -227,7 +238,7 @@ class Tx_Extbase_Tests_Unit_MVC_Controller_ArgumentsTest extends Tx_Extbase_Test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
        public function callingInvalidMethodThrowsException() {
-               $arguments = $this->objectManager->get('Tx_Extbase_MVC_Controller_Arguments');
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments();
                $arguments->nonExistingMethod();
        }
 
index 858c39f..d7c4e25 100644 (file)
 class Tx_Extbase_Tests_Unit_MVC_Web_RequestBuilderTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
 
        /**
+        * @var Tx_Extbase_MVC_Web_RequestBuilder
+        */
+       protected $requestBuilder;
+
+       /**
+        * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
+        */
+       protected $mockConfigurationManager;
+
+       /**
+        * @var array
+        */
+       protected $configuration;
+
+       /**
+        * @var Tx_Extbase_Object_ObjectManagerInterface
+        */
+       protected $mockObjectManager;
+
+       /**
+        * @var Tx_Extbase_MVC_Web_Request
+        */
+       protected $mockRequest;
+
+       /**
         * @var array
         */
        protected $getBackup = array();
@@ -37,112 +62,165 @@ class Tx_Extbase_Tests_Unit_MVC_Web_RequestBuilderTest extends Tx_Extbase_Tests_
         */
        protected $postBackup = array();
 
-       public function __construct() {
-               require_once(t3lib_extMgm::extPath('extbase', 'Classes/MVC/Web/RequestBuilder.php'));
-       }
+       /**
+        * @var array
+        */
+       protected $serverBackup = array();
 
        public function setUp() {
+               $this->requestBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_RequestBuilder', array('dummy'));
                $this->configuration = array(
                        'userFunc' => 'Tx_Extbase_Dispatcher->dispatch',
                        'pluginName' => 'Pi1',
                        'extensionName' => 'MyExtension',
                        'controller' => 'TheFirstController',
                        'action' => 'show',
-                       'switchableControllerActions' => array(
+                       'controllerConfiguration' => array(
                                'TheFirstController' => array(
-                                       'controller' => 'TheFirstController',
-                                       'actions' => 'show,index, ,new,create,delete,edit,update,setup,test'
+                                       'actions' => array('show', 'index', 'new', 'create', 'delete', 'edit', 'update', 'setup', 'test')
                                ),
                                'TheSecondController' => array(
-                                       'controller' => 'TheSecondController',
-                                       'actions' => 'show, index'
+                                       'actions' => array('show', 'index')
                                ),
                                'TheThirdController' => array(
-                                       'controller' => 'TheThirdController',
-                                       'actions' => 'delete,create'
+                                       'actions' => array('delete', 'create')
                                )
                        )
                );
-               $this->builder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_RequestBuilder'), array('dummy'));
+               $this->mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $this->mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
+               $this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+
                $this->getBackup = $_GET;
                $this->postBackup = $_POST;
+               $this->serverBackup = $_SERVER;
+       }
+
+       /**
+        * @return void
+        */
+       protected function injectDependencies() {
+               $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($this->mockConfigurationManager);
+
+               $this->mockObjectManager->expects($this->any())->method('create')->with('Tx_Extbase_MVC_Web_Request')->will($this->returnValue($this->mockRequest));
+               $this->requestBuilder->injectObjectManager($this->mockObjectManager);
        }
 
        public function tearDown() {
                $_GET = $this->getBackup;
                $_POST = $this->postBackup;
+               $_SERVER = $this->serverBackup;
        }
 
        /**
         * @test
         */
        public function buildReturnsAWebRequestObject() {
-               $this->builder->initialize($this->configuration);
-               $request = $this->builder->build();
-               $this->assertEquals('Tx_Extbase_MVC_Web_Request', get_class($request));
-               $this->assertEquals('Pi1', $request->getPluginName());
-               $this->assertEquals('MyExtension', $request->getControllerExtensionName());
-               $this->assertEquals('TheFirstController', $request->getControllerName());
-               $this->assertEquals('show', $request->getControllerActionName());
+               $this->injectDependencies();
+               $request = $this->requestBuilder->build();
+               $this->assertSame($this->mockRequest, $request);
        }
 
        /**
         * @test
         */
-       public function buildWithoutConfigurationReturnsAWebRequestObjectWithDefaultSettings() {
-               $request = $this->builder->build();
-               $this->assertEquals('plugin', $request->getPluginName());
-               $this->assertEquals('Extbase', $request->getControllerExtensionName());
-               $this->assertEquals('Standard', $request->getControllerName());
-               $this->assertEquals('index', $request->getControllerActionName());
+       public function buildSetsRequestPluginName() {
+               $this->injectDependencies();
+               $this->mockRequest->expects($this->once())->method('setPluginName')->with('Pi1');
+               $this->requestBuilder->build();
        }
 
        /**
         * @test
         */
-       public function buildWithMissingControllerConfigurationsReturnsAWebRequestObjectWithDefaultControllerSettings() {
-               $configuration = $this->configuration;
-               unset($configuration['controller']);
-               unset($configuration['action']);
-               unset($configuration['switchableControllerActions']);
-               $this->builder->initialize($configuration);
-               $request = $this->builder->build();
-               $this->assertEquals('Pi1', $request->getPluginName());
-               $this->assertEquals('MyExtension', $request->getControllerExtensionName());
-               $this->assertEquals('Standard', $request->getControllerName());
-               $this->assertEquals('index', $request->getControllerActionName());
+       public function buildSetsRequestControllerExtensionName() {
+               $this->injectDependencies();
+               $this->mockRequest->expects($this->once())->method('setControllerExtensionName')->with('MyExtension');
+               $this->requestBuilder->build();
        }
 
        /**
         * @test
         */
-       public function buildWithMissingActionsReturnsAWebRequestObjectWithDefaultControllerSettings() {
-               $configuration = $this->configuration;
-               unset($configuration['action']);
-               unset($configuration['switchableControllerActions']);
-               $this->builder->initialize($configuration);
-               $request = $this->builder->build();
-               $this->assertEquals('Pi1', $request->getPluginName());
-               $this->assertEquals('MyExtension', $request->getControllerExtensionName());
-               $this->assertEquals('TheFirstController', $request->getControllerName());
-               $this->assertEquals('index', $request->getControllerActionName());
+       public function buildSetsRequestControllerName() {
+               $this->injectDependencies();
+               $this->mockRequest->expects($this->once())->method('setControllerName')->with('TheFirstController');
+               $this->requestBuilder->build();
        }
 
        /**
         * @test
         */
-       public function buildSetsTheRequestURIInTheRequestObject() {
-               $this->builder->initialize($this->configuration);
-               $request = $this->builder->build();
-               $this->assertEquals(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), $request->getRequestURI());
+       public function buildSetsRequestControllerActionName() {
+               $this->injectDependencies();
+               $this->mockRequest->expects($this->once())->method('setControllerActionName')->with('show');
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        */
+       public function buildSetsRequestRequestURI() {
+               $this->injectDependencies();
+               $expectedRequestUri = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
+               $this->mockRequest->expects($this->once())->method('setRequestURI')->with($expectedRequestUri);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        */
+       public function buildSetsRequestBaseURI() {
+               $this->injectDependencies();
+               $expectedBaseUri = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
+               $this->mockRequest->expects($this->once())->method('setBaseURI')->with($expectedBaseUri);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        */
+       public function buildSetsRequestMethod() {
+               $this->injectDependencies();
+               $_SERVER['REQUEST_METHOD'] = 'SomeRequestMethod';
+               $expectedMethod = 'SomeRequestMethod';
+               $this->mockRequest->expects($this->once())->method('setMethod')->with($expectedMethod);
+               $this->requestBuilder->build();
+       }
+
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_MVC_Exception
+        */
+       public function buildThrowsExceptionIfExtensionNameIsNotConfigured() {
+               unset($this->configuration['extensionName']);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($mockConfigurationManager);
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        * @expectedException Tx_Extbase_MVC_Exception
+        */
+       public function buildThrowsExceptionIfPluginNameIsNotConfigured() {
+               unset($this->configuration['pluginName']);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
+               $this->requestBuilder->injectConfigurationManager($mockConfigurationManager);
+               $this->requestBuilder->build();
        }
 
        /**
         * @test
         */
        public function buildSetsParametersFromGetAndPostVariables() {
-               $this->builder->_set('extensionName', 'someExtensionName');
-               $this->builder->_set('pluginName', 'somePluginName');
+               $this->configuration['extensionName'] = 'SomeExtensionName';
+               $this->configuration['pluginName'] = 'SomePluginName';
+               $this->injectDependencies();
 
                $_GET = array(
                        'tx_someotherextensionname_somepluginname' => array(
@@ -166,24 +244,40 @@ class Tx_Extbase_Tests_Unit_MVC_Web_RequestBuilderTest extends Tx_Extbase_Tests_
                                )
                        )
                );
+               $this->mockRequest->expects($this->at(7))->method('setArgument')->with('parameter1', 'value1');
+               $this->mockRequest->expects($this->at(8))->method('setArgument')->with('parameter2', array('parameter3' => 'value3', 'parameter4' => 'value4'));
 
-               $request = $this->builder->build();
-               $expectedResult = array(
-                       'parameter1' => 'value1',
-                       'parameter2' => array(
-                               'parameter3' => 'value3',
-                               'parameter4' => 'value4',
-                       ),
+               $this->requestBuilder->build();
+       }
+
+       /**
+        * @test
+        */
+       public function buildSetsFormatFromGetAndPostVariables() {
+               $this->configuration['extensionName'] = 'SomeExtensionName';
+               $this->configuration['pluginName'] = 'SomePluginName';
+               $this->injectDependencies();
+
+               $_GET = array(
+                       'tx_someextensionname_somepluginname' => array(
+                               'format' => 'GET',
+                       )
                );
-               $actualResult = $request->getArguments();
-               $this->assertEquals($expectedResult, $actualResult);
+               $_POST = array(
+                       'tx_someextensionname_somepluginname' => array(
+                               'format' => 'POST',
+                       )
+               );
+               $this->mockRequest->expects($this->at(7))->method('setFormat')->with('POST');
+
+               $this->requestBuilder->build();
        }
 
        /**
         * @test
         */
-       public function initializeCorrectlySetsAllowedControllerActions() {
-               $this->builder->initialize($this->configuration);
+       public function buildCorrectlySetsAllowedControllerActions() {
+               $this->injectDependencies();
                $expectedResult = array(
                        'TheFirstController' => array(
                                'show', 'index', 'new', 'create', 'delete', 'edit', 'update', 'setup', 'test'
@@ -195,7 +289,8 @@ class Tx_Extbase_Tests_Unit_MVC_Web_RequestBuilderTest extends Tx_Extbase_Tests_
                                'delete', 'create'
                        )
                );
-               $actualResult = $this->builder->_get('allowedControllerActions');
+               $this->requestBuilder->build();
+               $actualResult = $this->requestBuilder->_get('allowedControllerActions');
                $this->assertEquals($expectedResult, $actualResult);
        }
 }
index 74ecb8d..50de815 100644 (file)
@@ -42,12 +42,12 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
        /**
         * @var tslib_cObj
         */
-       protected $contentObject;
+       protected $mockContentObject;
 
        /**
         * @var Tx_Extbase_MVC_Web_Request
         */
-       protected $request;
+       protected $mockRequest;
 
        /**
         * @var Tx_Extbase_MVC_Web_Routing_UriBuilder
@@ -60,11 +60,12 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
 
                $this->getBackup = t3lib_div::_GET();
 
-               $this->contentObject = $this->getMock('tslib_cObj');
-               $this->request = $this->getMock('Tx_Extbase_MVC_Web_Request');
+               $this->mockContentObject = $this->getMock('tslib_cObj');
+               $this->mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
 
-               $this->uriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'), array($this->contentObject));
-               $this->uriBuilder->setRequest($this->request);
+               $this->uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('build'));
+               $this->uriBuilder->setRequest($this->mockRequest);
+               $this->uriBuilder->_set('contentObject', $this->mockContentObject);
        }
 
        public function tearDown() {
@@ -84,6 +85,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                        ->setCreateAbsoluteUri(TRUE)
                        ->setAddQueryString(TRUE)
                        ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
+                       ->setArgumentPrefix('testArgumentPrefix')
                        ->setLinkAccessRestrictedPages(TRUE)
                        ->setTargetPageUid(123)
                        ->setTargetPageType(321)
@@ -96,6 +98,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                $this->assertEquals(TRUE, $this->uriBuilder->getCreateAbsoluteUri());
                $this->assertEquals(TRUE, $this->uriBuilder->getAddQueryString());
                $this->assertEquals(array('test' => 'addQueryStringExcludeArguments'), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
+               $this->assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix());
                $this->assertEquals(TRUE, $this->uriBuilder->getLinkAccessRestrictedPages());
                $this->assertEquals(123, $this->uriBuilder->getTargetPageUid());
                $this->assertEquals(321, $this->uriBuilder->getTargetPageType());
@@ -108,7 +111,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         */
        public function uriForPrefixesArgumentsWithExtensionAndPluginNameAndSetsControllerArgument() {
                $expectedArguments = array('tx_someextension_someplugin' => array('foo' => 'bar', 'baz' => array('extbase' => 'fluid'), 'controller' => 'SomeController'));
-
+               $GLOBALS['TSFE'] = NULL;
                $this->uriBuilder->uriFor(NULL, array('foo' => 'bar', 'baz' => array('extbase' => 'fluid')), 'SomeController', 'SomeExtension', 'SomePlugin');
                $this->assertEquals($expectedArguments, $this->uriBuilder->getArguments());
        }
@@ -140,7 +143,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function uriForSetsControllerFromRequestIfControllerIsNotSet() {
-               $this->request->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
+               $this->mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('SomeControllerFromRequest'));
 
                $expectedArguments = array('tx_someextension_someplugin' => array('controller' => 'SomeControllerFromRequest'));
 
@@ -152,7 +155,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function uriForSetsExtensionNameFromRequestIfExtensionNameIsNotSet() {
-               $this->request->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
+               $this->mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('SomeExtensionNameFromRequest'));
 
                $expectedArguments = array('tx_someextensionnamefromrequest_someplugin' => array('controller' => 'SomeController'));
 
@@ -164,7 +167,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function uriForSetsPluginNameFromRequestIfPluginNameIsNotSet() {
-               $this->request->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
+               $this->mockRequest->expects($this->once())->method('getPluginName')->will($this->returnValue('SomePluginNameFromRequest'));
 
                $expectedArguments = array('tx_someextension_somepluginnamefromrequest' => array('controller' => 'SomeController'));
 
@@ -264,7 +267,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
        public function buildBackendUriCreatesAbsoluteUrisIfSpecified() {
                t3lib_div::_GETset(array('M' => 'moduleKey'));
 
-               $this->request->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://baseuri/' . TYPO3_mainDir));
+               $this->mockRequest->expects($this->any())->method('getBaseURI')->will($this->returnValue('http://baseuri/' . TYPO3_mainDir));
                $this->uriBuilder->setCreateAbsoluteUri(TRUE);
 
                $expectedResult = 'http://baseuri/' . TYPO3_mainDir . 'mod.php?M=moduleKey';
@@ -276,10 +279,11 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function buildFrontendUriCreatesTypoLink() {
-               $uriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'), array($this->contentObject));
+               $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
+               $uriBuilder->_set('contentObject', $this->mockContentObject);
                $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('someTypoLinkConfiguration')));
 
-               $this->contentObject->expects($this->once())->method('typoLink_URL')->with(array('someTypoLinkConfiguration'));
+               $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('someTypoLinkConfiguration'));
 
                $uriBuilder->buildFrontendUri();
        }
@@ -288,7 +292,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function buildFrontendUriCreatesRelativeUrisByDefault() {
-               $this->contentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
+               $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('relative/uri'));
 
                $expectedResult = 'relative/uri';
                $actualResult = $this->uriBuilder->buildFrontendUri();
@@ -300,7 +304,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function buildFrontendUriDoesNotStripLeadingSlashesFromRelativeUris() {
-               $this->contentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
+               $this->mockContentObject->expects($this->once())->method('typoLink_URL')->will($this->returnValue('/relative/uri'));
 
                $expectedResult = '/relative/uri';
                $actualResult = $this->uriBuilder->buildFrontendUri();
@@ -312,10 +316,11 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
         * @test
         */
        public function buildFrontendUriCreatesAbsoluteUrisIfSpecified() {
-               $uriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'), array($this->contentObject));
+               $uriBuilder = $this->getAccessibleMock('Tx_Extbase_MVC_Web_Routing_UriBuilder', array('buildTypolinkConfiguration'));
+               $uriBuilder->_set('contentObject', $this->mockContentObject);
                $uriBuilder->expects($this->once())->method('buildTypolinkConfiguration')->will($this->returnValue(array('foo' => 'bar')));
 
-               $this->contentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE))->will($this->returnValue('http://baseuri/relative/uri'));
+               $this->mockContentObject->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar', 'forceAbsoluteUrl' => TRUE))->will($this->returnValue('http://baseuri/relative/uri'));
                $uriBuilder->setCreateAbsoluteUri(TRUE);
 
                $expectedResult = 'http://baseuri/relative/uri';
@@ -334,6 +339,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                        ->setCreateAbsoluteUri(TRUE)
                        ->setAddQueryString(TRUE)
                        ->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))
+                       ->setArgumentPrefix('testArgumentPrefix')
                        ->setLinkAccessRestrictedPages(TRUE)
                        ->setTargetPageUid(123)
                        ->setTargetPageType(321)
@@ -348,6 +354,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                $this->assertEquals(FALSE, $this->uriBuilder->getCreateAbsoluteUri());
                $this->assertEquals(FALSE, $this->uriBuilder->getAddQueryString());
                $this->assertEquals(array(), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
+               $this->assertEquals(NULL, $this->uriBuilder->getArgumentPrefix());
                $this->assertEquals(FALSE, $this->uriBuilder->getLinkAccessRestrictedPages());
                $this->assertEquals(NULL, $this->uriBuilder->getTargetPageUid());
                $this->assertEquals(0, $this->uriBuilder->getTargetPageType());
@@ -521,7 +528,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                $mockEntity->name = 'foo';
 
                $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
-               $actualResult = $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockEntity));
+               $mockUriBuilder->_call('convertDomainObjectsToIdentityArrays', array('object' => $mockEntity));
        }
 
        /**
index d512ebd..3017dcf 100644 (file)
@@ -32,17 +32,17 @@ class Tx_Extbase_Tests_Unit_Persistence_QueryResultTest extends Tx_Extbase_Tests
        /**
         * @var Tx_Extbase_Persistence_QueryInterface
         */
-       protected $query;
+       protected $mockQuery;
 
        /**
         * @var Tx_Extbase_Persistence_ManagerInterface
         */
-       protected $persistenceManager;
+       protected $mockPersistenceManager;
 
        /**
         * @var Tx_Extbase_Persistence_DataMapper
         */
-       protected $dataMapper;
+       protected $mockDataMapper;
 
        /**
         * Sets up this test case
@@ -50,16 +50,16 @@ class Tx_Extbase_Tests_Unit_Persistence_QueryResultTest extends Tx_Extbase_Tests
         * @return void
         */
        public function setUp() {
-               $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
-               $this->persistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));
-               $this->persistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));
-               $this->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper');
-               $this->query = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
-               $this->queryResult = new Tx_Extbase_Persistence_QueryResult($this->query);
-               $this->queryResult->injectPersistenceManager($this->persistenceManager);
-               $this->queryResult->injectDataMapper($this->dataMapper);
+               $this->mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
+               $this->mockPersistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));
+               $this->mockPersistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));
+               $this->mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper');
+               $this->mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
+               $this->queryResult = new Tx_Extbase_Persistence_QueryResult($this->mockQuery);
+               $this->queryResult->injectPersistenceManager($this->mockPersistenceManager);
+               $this->queryResult->injectDataMapper($this->mockDataMapper);
                $this->sampleResult = array(array('foo' => 'Foo1', 'bar' => 'Bar1'), array('foo' => 'Foo2', 'bar' => 'Bar2'));
-               $this->dataMapper->expects($this->any())->method('map')->will($this->returnValue($this->sampleResult));
+               $this->mockDataMapper->expects($this->any())->method('map')->will($this->returnValue($this->sampleResult));
        }
 
        /**
@@ -73,7 +73,7 @@ class Tx_Extbase_Tests_Unit_Persistence_QueryResultTest extends Tx_Extbase_Tests
         * @test
         */
        public function getQueryReturnsAClone() {
-               $this->assertNotSame($this->query, $this->queryResult->getQuery());
+               $this->assertNotSame($this->mockQuery, $this->queryResult->getQuery());
        }
 
        /**
@@ -114,8 +114,8 @@ class Tx_Extbase_Tests_Unit_Persistence_QueryResultTest extends Tx_Extbase_Tests
         * @test
         */
        public function countDoesNotInitializeProxy() {
-               $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array('initialize'), array($this->query));
-               $queryResult->injectPersistenceManager($this->persistenceManager);
+               $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array('initialize'), array($this->mockQuery));
+               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
                $queryResult->expects($this->never())->method('initialize');
                $queryResult->count();
        }
@@ -124,8 +124,8 @@ class Tx_Extbase_Tests_Unit_Persistence_QueryResultTest extends Tx_Extbase_Tests
         * @test
         */
        public function countCallsGetObjectCountByQueryOnPersistenceManager() {
-               $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array('initialize'), array($this->query));
-               $queryResult->injectPersistenceManager($this->persistenceManager);
+               $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array('initialize'), array($this->mockQuery));
+               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
                $this->assertEquals(2, $queryResult->count());
        }
 
@@ -154,12 +154,22 @@ class Tx_Extbase_Tests_Unit_Persistence_QueryResultTest extends Tx_Extbase_Tests
         * @test
         */
        public function initializeExecutesQueryWithArrayFetchMode() {
-               $queryResult = $this->getAccessibleMock('Tx_Extbase_Persistence_QueryResult', array('dummy'), array($this->query));
-               $queryResult->injectPersistenceManager($this->persistenceManager);
-               $queryResult->injectDataMapper($this->dataMapper);
-               $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue(array('FAKERESULT')));
+               $queryResult = $this->getAccessibleMock('Tx_Extbase_Persistence_QueryResult', array('dummy'), array($this->mockQuery));
+               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
+               $queryResult->injectDataMapper($this->mockDataMapper);
+               $this->mockPersistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->mockQuery)->will($this->returnValue(array('FAKERESULT')));
                $queryResult->_call('initialize');
        }
 
+       /**
+        * @test
+        */
+       public function usingCurrentOnTheQueryResultReturnsAWarning() {
+               $queryResult = new Tx_Extbase_Persistence_QueryResult($this->mockQuery);
+               $expectedResult = 'You should never see this warning. If you do, you probably used PHP array functions like current() on the Tx_Extbase_Persistence_QueryResult. To retrieve the first result, you can use the getFirst() method.';
+               $actualResult = current($queryResult);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
 }
 ?>
\ No newline at end of file
index 9e61275..f4b0834 100644 (file)
@@ -30,24 +30,29 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
        protected $repository;
 
        /**
+        * @var Tx_Extbase_Object_ObjectManagerInterface
+        */
+       protected $mockObjectManager;
+
+       /**
         * @var Tx_Extbase_Persistence_IdentityMap
         */
-       protected $identityMap;
+       protected $mockIdentityMap;
 
        /**
         * @var Tx_Extbase_Persistence_QueryFactory
         */
-       protected $queryFactory;
+       protected $mockQueryFactory;
 
        /**
         * @var Tx_Extbase_Persistence_ManagerInterface
         */
-       protected $persistenceManager;
+       protected $mockPersistenceManager;
 
        /**
         * @var Tx_Extbase_Persistence_QueryInterface
         */
-       protected $query;
+       protected $mockQuery;
 
        /**
         * @var Tx_Extbase_Persistence_QuerySettingsInterface
@@ -55,14 +60,18 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
        protected $querySettings;
 
        public function setUp() {
-               $this->identityMap = $this->getMock('Tx_Extbase_Persistence_IdentityMap');
-               $this->queryFactory = $this->getMock('Tx_Extbase_Persistence_QueryFactory');
-               $this->query = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
-               $this->querySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');
-               $this->query->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->querySettings));
-               $this->queryFactory->expects($this->any())->method('create')->will($this->returnValue($this->query));
-               $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
-               $this->repository = $this->getAccessibleMock('Tx_Extbase_Persistence_Repository', array('dummy'), array($this->identityMap, $this->queryFactory, $this->persistenceManager));
+               $this->mockIdentityMap = $this->getMock('Tx_Extbase_Persistence_IdentityMap');
+               $this->mockQueryFactory = $this->getMock('Tx_Extbase_Persistence_QueryFactory');
+               $this->mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
+               $this->mockQuerySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');
+               $this->mockQuery->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->mockQuerySettings));
+               $this->mockQueryFactory->expects($this->any())->method('create')->will($this->returnValue($this->mockQuery));
+               $this->mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
+               $this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface');
+               $this->repository = $this->getAccessibleMock('Tx_Extbase_Persistence_Repository', array('dummy'), array($this->mockObjectManager));
+               $this->repository->injectIdentityMap($this->mockIdentityMap);
+               $this->repository->injectQueryFactory($this->mockQueryFactory);
+               $this->repository->injectPersistenceManager($this->mockPersistenceManager);
        }
 
        /**
@@ -165,7 +174,7 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
                        }
                }');
 
-               $this->repository = new $mockClassName($this->identityMap, $this->queryFactory, $this->persistenceManager);
+               $this->repository = new $mockClassName($this->mockObjectManager);
                $this->assertEquals($modelClassName, $this->repository->_getObjectType());
        }
 
@@ -173,7 +182,7 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         * @test
         */
        public function createQueryCallsQueryFactoryWithExpectedClassName() {
-               $this->queryFactory->expects($this->once())->method('create')->with('ExpectedType');
+               $this->mockQueryFactory->expects($this->once())->method('create')->with('ExpectedType');
                $this->repository->_set('objectType', 'ExpectedType');
                $this->repository->createQuery();
        }
@@ -183,7 +192,7 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         */
        public function findAllCreatesQueryAndReturnsResultOfExecuteCall() {
                $expectedResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
-               $this->query->expects($this->once())->method('execute')->with()->will($this->returnValue($expectedResult));
+               $this->mockQuery->expects($this->once())->method('execute')->with()->will($this->returnValue($expectedResult));
                $this->assertSame($expectedResult, $this->repository->findAll());
        }
 
@@ -193,24 +202,41 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
        public function findByUidReturnsResultOfGetObjectByIdentifierCall() {
                $fakeUid = '123';
                $object = new stdClass();
+               $this->repository->_set('objectType', 'someObjectType');
 
-               $this->persistenceManager->expects($this->once())->method('getObjectByIdentifier')->with($fakeUid)->will($this->returnValue($object));
-               $this->repository->_set('objectType', 'stdClass');
+               $this->mockIdentityMap->expects($this->once())->method('hasIdentifier')->with($fakeUid, 'someObjectType')->will($this->returnValue(TRUE));
+               $this->mockIdentityMap->expects($this->once())->method('getObjectByIdentifier')->with($fakeUid)->will($this->returnValue($object));
 
-               $this->assertSame($object, $this->repository->findByUid($fakeUid));
+               $expectedResult = $object;
+               $actualResult = $this->repository->findByUid($fakeUid);
+               $this->assertSame($expectedResult, $actualResult);
        }
 
        /**
         * @test
         */
-       public function findByUidReturnsNullIfObjectOfMismatchingTypeWasFoundByGetObjectByIdentifierCall() {
-               $fakeUUID = '123';
+       public function findByUidQueriesObjectAndRegistersItIfItWasNotFoundInIdentityMap() {
+               $fakeUid = '123';
                $object = new stdClass();
+               $this->repository->_set('objectType', 'someObjectType');
+
+               $mockQuerySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');
+               $this->mockQuery->expects($this->atLeastOnce())->method('getQuerySettings')->will($this->returnValue($mockQuerySettings));
 
-               $this->persistenceManager->expects($this->once())->method('getObjectByIdentifier')->with($fakeUUID)->will($this->returnValue($object));
-               $this->repository->_set('objectType', 'otherExpectedClass');
+               $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
 
-               $this->assertNULL($this->repository->findByUuid($fakeUUID));
+               $this->mockQuery->expects($this->once())->method('equals')->with('uid', $fakeUid)->will($this->returnValue('matchingConstraint'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchingConstraint')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
+               $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));
+
+               $this->mockIdentityMap->expects($this->once())->method('hasIdentifier')->with($fakeUid, 'someObjectType')->will($this->returnValue(FALSE));
+               $this->mockIdentityMap->expects($this->once())->method('registerObject')->with($object, $fakeUid);
+               $this->mockQueryFactory->expects($this->once())->method('create')->with('someObjectType')->will($this->returnValue($this->mockQuery));
+
+               $expectedResult = $object;
+               $actualResult = $this->repository->findByUid($fakeUid);
+               $this->assertSame($expectedResult, $actualResult);
        }
 
        /**
@@ -221,12 +247,17 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         * @test
         * @return void
         */
-       public function replaceReconstitutedEntityByNewObject() {
-               $existingObject = new stdClass;
-               $newObject = new stdClass;
+       public function replaceReplacesReconstitutedEntityByNewObject() {
+               $existingObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
+               $newObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
+
+               $mockBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
+               $this->mockPersistenceManager->expects($this->once())->method('getBackend')->will($this->returnValue($mockBackend));
+               $mockBackend->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
+               $mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
 
-               $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('86ea8820-19f6-11de-8c30-0800200c9a66'));
-               $this->persistenceManager->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+               $mockSession = $this->getMock('Tx_Extbase_Persistence_Session');
+               $this->mockPersistenceManager->expects($this->once())->method('getSession')->will($this->returnValue($mockSession));
 
                $this->repository->_set('objectType', get_class($newObject));
                $this->repository->replace($existingObject, $newObject);
@@ -241,15 +272,20 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         * @test
         * @return void
         */
-       public function replaceReconstitutedObjectWhichIsMarkedToBeRemoved() {
-               $existingObject = new stdClass;
-               $newObject = new stdClass;
+       public function replaceRemovesReconstitutedObjectWhichIsMarkedToBeRemoved() {
+               $existingObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
+               $newObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
 
                $removedObjects = new SplObjectStorage;
                $removedObjects->attach($existingObject);
 
-               $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('86ea8820-19f6-11de-8c30-0800200c9a66'));
-               $this->persistenceManager->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+               $mockBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
+               $this->mockPersistenceManager->expects($this->once())->method('getBackend')->will($this->returnValue($mockBackend));
+               $mockBackend->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
+               $mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+
+               $mockSession = $this->getMock('Tx_Extbase_Persistence_Session');
+               $this->mockPersistenceManager->expects($this->once())->method('getSession')->will($this->returnValue($mockSession));
 
                $this->repository->_set('objectType', get_class($newObject));
                $this->repository->_set('removedObjects', $removedObjects);
@@ -267,15 +303,20 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         * @test
         * @return void
         */
-       public function replaceNewObjectByNewObject() {
-               $existingObject = new stdClass;
-               $newObject = new stdClass;
+       public function replaceAddsNewObjectToAddedObjects() {
+               $existingObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
+               $newObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
 
                $addedObjects = new SplObjectStorage;
                $addedObjects->attach($existingObject);
 
-               $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL));
-               $this->persistenceManager->expects($this->never())->method('replaceObject');
+               $mockBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface');
+               $this->mockPersistenceManager->expects($this->once())->method('getBackend')->will($this->returnValue($mockBackend));
+               $mockBackend->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL));
+               $mockBackend->expects($this->never())->method('replaceObject');
+
+               $mockSession = $this->getMock('Tx_Extbase_Persistence_Session');
+               $this->mockPersistenceManager->expects($this->once())->method('getSession')->will($this->returnValue($mockSession));
 
                $this->repository->_set('objectType', get_class($newObject));
                $this->repository->_set('addedObjects', $addedObjects);
@@ -300,25 +341,23 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         */
        public function updateReplacesAnObjectWithTheSameUuidByTheGivenObject() {
                $existingObject = new stdClass;
-               $modifiedObject = $this->getMock('FooBar' . uniqid(), array('FLOW3_Persistence_isClone'));
-               $modifiedObject->expects($this->once())->method('FLOW3_Persistence_isClone')->will($this->returnValue(TRUE));
-
-               $this->persistenceManager->expects($this->once())->method('getIdentifierByObject')->with($modifiedObject)->will($this->returnValue('86ea8820-19f6-11de-8c30-0800200c9a66'));
-               $this->persistenceManager->expects($this->once())->method('getObjectByIdentifier')->with('86ea8820-19f6-11de-8c30-0800200c9a66')->will($this->returnValue($existingObject));
-
-               $this->repository->expects($this->once())->method('replaceObject')->with($existingObject, $modifiedObject);
-
-               $this->repository->_set('objectType', get_class($modifiedObject));
-               $this->repository->update($modifiedObject);
+               $modifiedObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
+               $modifiedObject->expects($this->once())->method('getUid')->will($this->returnValue('123'));
+
+               $repository = $this->getAccessibleMock('Tx_Extbase_Persistence_Repository', array('findByUid', 'replace'));
+               $repository->expects($this->once())->method('findByUid')->with('123')->will($this->returnValue($existingObject));
+               $repository->expects($this->once())->method('replace')->with($existingObject, $modifiedObject);
+               $repository->_set('objectType', get_class($modifiedObject));
+               $repository->update($modifiedObject);
        }
 
        /**
         * @test
-        * @expectedException Tx_Extbase_Persistence_Exception_IllegalObjectType
+        * @expectedException Tx_Extbase_Persistence_Exception_UnknownObject
         */
-       public function updateRejectsNonClonedObjects() {
-               $someObject = $this->getMock('FooBar' . uniqid(), array('FLOW3_Persistence_isClone'));
-               $someObject->expects($this->once())->method('FLOW3_Persistence_isClone')->will($this->returnValue(FALSE));
+       public function updateRejectsUnknownObjects() {
+               $someObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface');
+               $someObject->expects($this->once())->method('getUid')->will($this->returnValue(NULL));
 
                $this->repository->_set('objectType', get_class($someObject));
 
@@ -339,12 +378,9 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
         */
        public function magicCallMethodAcceptsFindBySomethingCallsAndExecutesAQueryWithThatCriteria() {
                $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
-               $mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
-               $mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
-               $mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($mockQuery));
-               $mockQuery->expects($this->once())->method('execute')->with()->will($this->returnValue($mockQueryResult));
-
-               $this->repository->expects($this->once())->method('createQuery')->will($this->returnValue($mockQuery));
+               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
 
                $this->assertSame($mockQueryResult, $this->repository->findByFoo('bar'));
        }
@@ -356,12 +392,10 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
                $object = new stdClass();
                $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
                $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));
-               $mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
-               $mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
-               $mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($mockQuery));
-               $mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
-
-               $this->repository->expects($this->once())->method('createQuery')->will($this->returnValue($mockQuery));
+               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('setLimit')->with(1)->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
 
                $this->assertSame($object, $this->repository->findOneByFoo('bar'));
        }
@@ -372,12 +406,9 @@ class Tx_Extbase_Tests_Unit_Persistence_RepositoryTest extends Tx_Extbase_Tests_
        public function magicCallMethodAcceptsCountBySomethingCallsAndExecutesAQueryWithThatCriteria() {
                $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
                $mockQueryResult->expects($this->once())->method('count')->will($this->returnValue(2));
-               $mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
-               $mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
-               $mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($mockQuery));
-               $mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
-
-               $this->repository->expects($this->once())->method('createQuery')->will($this->returnValue($mockQuery));
+               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
 
                $this->assertSame(2, $this->repository->countByFoo('bar'));
        }
index b114a31..e10af45 100644 (file)
@@ -35,9 +35,12 @@ class Tx_Extbase_Tests_Unit_Reflection_ServiceTest extends Tx_Extbase_Tests_Unit
 
        }
 
-       public function test_GetMethodTagsValues() {
+       /**
+        * @test
+        */
+       public function getMethodTagsValues() {
                $service = new Tx_Extbase_Reflection_Service();
-               $tagsValues = $service->getMethodTagsValues('Tx_Extbase_Reflection_Service_testcase', 'fixtureMethodForMethodTagsValues');
+               $tagsValues = $service->getMethodTagsValues('Tx_Extbase_Tests_Unit_Reflection_ServiceTest', 'fixtureMethodForMethodTagsValues');
 
                $this->assertEquals(array(
                        'param' => array('array $foo The foo parameter'),
@@ -45,9 +48,12 @@ class Tx_Extbase_Tests_Unit_Reflection_ServiceTest extends Tx_Extbase_Tests_Unit
                ), $tagsValues);
        }
 
-       public function test_GetMethodParameters() {
+       /**
+        * @test
+        */
+       public function getMethodParameters() {
                $service = new Tx_Extbase_Reflection_Service();
-               $parameters = $service->getMethodParameters('Tx_Extbase_Reflection_Service_testcase', 'fixtureMethodForMethodTagsValues');
+               $parameters = $service->getMethodParameters('Tx_Extbase_Tests_Unit_Reflection_ServiceTest', 'fixtureMethodForMethodTagsValues');
 
                $this->assertEquals(array(
                        'foo' => array(
index 9e3a5b7..0e99ba8 100644 (file)
@@ -47,8 +47,7 @@ class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
        protected $tsfeBackup;
 
        public function setUp() {
-               global $TYPO3_CONF_VARS;
-               $this->typo3ConfVars = $TYPO3_CONF_VARS;
+               $this->typo3ConfVars = $GLOBALS['TYPO3_CONF_VARS'];
                $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
                $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('fullQuoteStr', 'exec_SELECTgetRows'));
                $this->tsfeBackup = $GLOBALS['TSFE'];
@@ -67,44 +66,54 @@ class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
                                ),
                        'extensionname_someplugin' => 'USER',
                        'extensionname_someplugin.' => array(
-                               'userFunc' => 'tx_extbase_dispatcher->dispatch',
-                               'pluginName' => 'SomePlugin',
+                               'userFunc' => 'tx_extbase_core_bootstrap->run',
                                'extensionName' => 'ExtensionName',
-                               'controller' => 'ControllerName',
-                               'action' => 'index',
-                               'switchableControllerActions.' => array(
-                                       'ControllerName.' => array(
-                                               'actions' => 'index,otherAction',
-                                       ),
-                               ),
+                               'pluginName' => 'SomePlugin',
                        ),
                        'someotherextensionname_secondplugin' => 'USER',
                        'someotherextensionname_secondplugin.' => array(
-                               'userFunc' => 'tx_extbase_dispatcher->dispatch',
-                               'pluginName' => 'SecondPlugin',
+                               'userFunc' => 'tx_extbase_core_bootstrap->run',
                                'extensionName' => 'SomeOtherExtensionName',
-                               'controller' => 'ControllerName',
-                               'action' => 'index',
-                               'switchableControllerActions.' => array(
-                                       'ControllerName.' => array(
-                                               'actions' => 'index,otherAction',
-                                       ),
-                                       'SecondControllerName.' => array(
-                                               'actions' => 'someAction,someOtherAction',
-                                               'nonCacheableActions' => 'someOtherAction',
-                                       ),
-                               ),
+                               'pluginName' => 'SecondPlugin',
                        ),
                        'extensionname_thirdplugin' => 'USER',
                        'extensionname_thirdplugin.' => array(
-                               'userFunc' => 'tx_extbase_dispatcher->dispatch',
-                               'pluginName' => 'ThirdPlugin',
+                               'userFunc' => 'tx_extbase_core_bootstrap->run',
                                'extensionName' => 'ExtensionName',
-                               'controller' => 'ControllerName',
-                               'action' => 'index',
-                               'switchableControllerActions.' => array(
-                                       'ControllerName.' => array(
-                                               'actions' => 'otherAction,thirdAction',
+                               'pluginName' => 'ThirdPlugin',
+                       ),
+               );
+               $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'] = array(
+                       'ExtensionName' => array(
+                               'plugins' => array(
+                                       'SomePlugin' => array(
+                                               'controllers' => array(
+                                                       'ControllerName' => array(
+                                                               'actions' => array('index', 'otherAction')
+                                                       ),
+                                               ),
+                                       ),
+                                       'ThirdPlugin' => array(
+                                               'controllers' => array(
+                                                       'ControllerName' => array(
+                                                               'actions' => array('otherAction', 'thirdAction')
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+                       'SomeOtherExtensionName' => array(
+                               'plugins' => array(
+                                       'SecondPlugin' => array(
+                                               'controllers' => array(
+                                                       'ControllerName' => array(
+                                                               'actions' => array('index', 'otherAction')
+                                                       ),
+                                                       'SecondControllerName' => array(
+                                                               'actions' => array('someAction', 'someOtherAction'),
+                                                               'nonCacheableActions' => array('someOtherAction')
+                                                       )
+                                               ),
                                        ),
                                ),
                        ),
@@ -112,8 +121,7 @@ class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
        }
 
        public function tearDown() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS = $this->typo3ConfVars;
+               $GLOBALS['TYPO3_CONF_VARS'] = $this->typo3ConfVars;
                $GLOBALS['TSFE'] = $this->tsfeBackup;
        }
 
@@ -122,19 +130,19 @@ class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginWorksForMinimalisticSetup() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
                        array('Blog' => 'index')
                );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
+               $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
 
                $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
                $this->assertContains('
-       pluginName = Pi1
-       extensionName = MyExtension', $staticTypoScript);
+       userFunc = tx_extbase_core_bootstrap->run
+       extensionName = MyExtension
+       pluginName = Pi1', $staticTypoScript);
 
        $this->assertNotContains('USER_INT', $staticTypoScript);
        }
@@ -145,15 +153,14 @@ class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginCreatesCorrectDefaultTypoScriptSetup() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
                        array('Blog' => 'index')
                );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
-               $defaultTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup'];
+               $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+               $defaultTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'];
                $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
                $this->assertContains('
 plugin.tx_myextension {
@@ -179,8 +186,7 @@ plugin.tx_myextension {
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginWorksForASingleControllerAction() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
@@ -188,27 +194,33 @@ plugin.tx_myextension {
                                'FirstController' => 'index'
                                )
                );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
+               $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
 
                $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
                $this->assertContains('
-       pluginName = Pi1
-       extensionName = MyExtension', $staticTypoScript);
-               $this->assertContains('
-       controller = FirstController
-       action = index', $staticTypoScript);
-               $this->assertNotContains('USER_INT', $staticTypoScript);
+       extensionName = MyExtension
+       pluginName = Pi1', $staticTypoScript);
+
+               $expectedResult = array(
+                       'controllers' => array(
+                               'FirstController' => array(
+                                       'actions' => array('index')
+                               )
+                       ),
+                       'pluginType' => 'list_type'
+               );
+               $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
        }
 
        /**
         * @test
+        * @expectedException InvalidArgumentException
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
-       public function configurePluginWithEmptyPluginNameResultsInAnError() {
-               $this->setExpectedException('InvalidArgumentException');
+       public function configurePluginThrowsExceptionIfExtensionNameIsEmpty() {
                Tx_Extbase_Utility_Extension::configurePlugin(
-                       'MyExtension',
                        '',
+                       'SomePlugin',
                        array(
                                'FirstController' => 'index'
                                )
@@ -217,42 +229,52 @@ plugin.tx_myextension {
 
        /**
         * @test
+        * @expectedException InvalidArgumentException
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
-       public function configurePluginWithEmptyExtensionNameResultsInAnError() {
-               $this->setExpectedException('InvalidArgumentException');
+       public function configurePluginThrowsExceptionIfPluginNameIsEmpty() {
                Tx_Extbase_Utility_Extension::configurePlugin(
+                       'MyExtension',
                        '',
-                       'Pi1',
                        array(
                                'FirstController' => 'index'
                                )
                );
        }
 
+
        /**
         * @test
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginRespectsDefaultActionAsANonCacheableAction() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
                        array(
-                               'FirstController' => 'index,show,new,create,delete,edit,update'
+                               'FirstController' => 'index,show,new, create,delete,edit,update'
                                ),
                        array(
                                'FirstController' => 'index,show'
                                )
                        );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
+               $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+               $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
                $this->assertContains('
-tt_content.list.20.myextension_pi1 = USER
-tt_content.list.20.myextension_pi1 {', $staticTypoScript);
-               $this->assertContains('FirstController.nonCacheableActions = index,show
-', $staticTypoScript);
+       extensionName = MyExtension
+       pluginName = Pi1', $staticTypoScript);
+
+               $expectedResult = array(
+                       'controllers' => array(
+                               'FirstController' => array(
+                                       'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
+                                       'nonCacheableActions' => array('index', 'show')
+                               )
+                       ),
+                       'pluginType' => 'list_type'
+               );
+               $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
        }
 
        /**
@@ -260,25 +282,33 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginRespectsNonDefaultActionAsANonCacheableAction() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
                        array(
-                               'FirstController' => 'index,show,new,create,delete,edit,update'
+                               'FirstController' => 'index,show,new, create,delete,edit,update'
                                ),
                        array(
-                               'FirstController' => 'show,new'
+                               'FirstController' => 'new,show'
                                )
                        );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
-
+               $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+               $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
                $this->assertContains('
-tt_content.list.20.myextension_pi1 = USER
-tt_content.list.20.myextension_pi1 {', $staticTypoScript);
-               $this->assertContains('FirstController.nonCacheableActions = show,new
-', $staticTypoScript);
+       extensionName = MyExtension
+       pluginName = Pi1', $staticTypoScript);
+
+               $expectedResult = array(
+                       'controllers' => array(
+                               'FirstController' => array(
+                                       'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
+                                       'nonCacheableActions' => array('new', 'show')
+                               )
+                       ),
+                       'pluginType' => 'list_type'
+               );
+               $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
        }
 
        /**
@@ -286,8 +316,7 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
@@ -298,24 +327,27 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
                                ),
                        array(
                                'FirstController' => 'new,create,edit,update',
-                               'SecondController' => 'delete',
                                'ThirdController' => 'create'
                                )
                        );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
-
-               $this->assertContains('
-tt_content.list.20.myextension_pi1 = USER
-tt_content.list.20.myextension_pi1 {', $staticTypoScript);
-
-               $this->assertContains('FirstController.nonCacheableActions = new,create,edit,update
-', $staticTypoScript);
 
-               $this->assertContains('SecondController.nonCacheableActions = delete
-', $staticTypoScript);
-
-               $this->assertContains('ThirdController.nonCacheableActions = create
-', $staticTypoScript);
+               $expectedResult = array(
+                       'controllers' => array(
+                               'FirstController' => array(
+                                       'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
+                                       'nonCacheableActions' => array('new', 'create', 'edit', 'update')
+                               ),
+                               'SecondController' => array(
+                                       'actions' => array('index', 'show', 'delete')
+                               ),
+                               'ThirdController' => array(
+                                       'actions' => array('create'),
+                                       'nonCacheableActions' => array('create')
+                               )
+                       ),
+                       'pluginType' => 'list_type'
+               );
+               $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
        }
 
 
@@ -324,8 +356,7 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @see Tx_Extbase_Utility_Extension::registerPlugin
         */
        public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault() {
-               global $TYPO3_CONF_VARS;
-               $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
                Tx_Extbase_Utility_Extension::configurePlugin(
                        'MyExtension',
                        'Pi1',
@@ -340,20 +371,25 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
                                'ThirdController' => 'create'
                                )
                        );
-               $staticTypoScript = $TYPO3_CONF_VARS['FE']['defaultTypoScript_setup.']['43'];
-
-               $this->assertContains('
-tt_content.list.20.myextension_pi1 = USER
-tt_content.list.20.myextension_pi1 {', $staticTypoScript);
 
-               $this->assertContains('FirstController.nonCacheableActions = index,new,create,edit,update
-', $staticTypoScript);
-
-               $this->assertContains('SecondController.nonCacheableActions = delete
-', $staticTypoScript);
-
-               $this->assertContains('ThirdController.nonCacheableActions = create
-', $staticTypoScript);
+               $expectedResult = array(
+                       'controllers' => array(
+                               'FirstController' => array(
+                                       'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
+                                       'nonCacheableActions' => array('index', 'new', 'create', 'edit', 'update')
+                               ),
+                               'SecondController' => array(
+                                       'actions' => array('index', 'show', 'delete'),
+                                       'nonCacheableActions' => array('delete')
+                               ),
+                               'ThirdController' => array(
+                                       'actions' => array('create'),
+                                       'nonCacheableActions' => array('create')
+                               )
+                       ),
+                       'pluginType' => 'list_type'
+               );
+               $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
        }
 
        /**
@@ -361,36 +397,41 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         *
         * @return array
         */
-       public function getPluginNamespaceByPluginSignatureDataProvider() {
+       public function getPluginNamespaceDataProvider() {
                return array(
-                       array('someextension_someplugin', 'tx_someextension_someplugin'),
-                       array('nonexistingextension_someplugin', 'tx_nonexistingextension_someplugin'),
-                       array('InvalidPluginNamespace', 'tx_InvalidPluginNamespace'),
+                       array('SomeExtension', 'SomePlugin', 'tx_someextension_someplugin'),
+                       array('NonExistingExtension', 'SomePlugin', 'tx_nonexistingextension_someplugin'),
+                       array('Invalid', '', 'tx_invalid_'),
                );
        }
 
        /**
         * @test
-        * @dataProvider getPluginNamespaceByPluginSignatureDataProvider
+        * @dataProvider getPluginNamespaceDataProvider
         */
-       public function getPluginNamespaceByPluginSignatureTests($pluginSignature, $expectedResult) {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup'));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
-               $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespaceByPluginSignature($pluginSignature);
-               $this->assertEquals($expectedResult, $actualResult, 'Failing for $pluginSignature: "' . $pluginSignature . '"');
+       public function getPluginNamespaceTests($extensionName, $pluginName, $expectedResult) {
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array()));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespace($extensionName, $pluginName);
+               $this->assertEquals($expectedResult, $actualResult, 'Failing for extension: "' . $extensionName . '", plugin: "' . $pluginName . '"');
        }
 
        /**
         * @test
         */
        public function pluginNamespaceCanBeOverridden() {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getConfiguration'));
-               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'SomeExtension', 'SomePlugin')->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                $expectedResult = 'overridden_plugin_namespace';
-               $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespaceByPluginSignature('somePluginSignature');
+               $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespace('SomeExtension', 'SomePlugin');
                $this->assertEquals($expectedResult, $actualResult);
        }
 
@@ -404,7 +445,7 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
                        array('ExtensionName', 'ControllerName', 'someNonExistingAction', NULL),
                        array('ExtensionName', 'ControllerName', 'index', 'SomePlugin'),
                        array('ExtensionName', 'ControllerName', 'thirdAction', 'ThirdPlugin'),
-                       array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'thirdAction', 'ThirdPlugin'),
+                       array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'thirdAction', NULL),
                        array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'ThIrDaCtIoN', NULL),
                        array('SomeOtherExtensionName', 'ControllerName', 'otherAction', 'SecondPlugin'),
                );
@@ -415,6 +456,12 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @dataProvider getPluginNameByActionDataProvider
         */
        public function getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult) {
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                $actualResult = Tx_Extbase_Utility_Extension::getPluginNameByAction($extensionName, $controllerName, $actionName);
                $this->assertEquals($expectedResult, $actualResult, 'Failing for $extensionName: "' . $extensionName . '", $controllerName: "' . $controllerName . '", $actionName: "' . $actionName . '" - ');
        }
@@ -424,37 +471,68 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @expectedException Tx_Extbase_Exception
         */
        public function getPluginNameByActionThrowsExceptionIfMoreThanOnePluginMatches() {
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                Tx_Extbase_Utility_Extension::getPluginNameByAction('ExtensionName', 'ControllerName', 'otherAction');
        }
 
        /**
         * @test
         */
+       public function getPluginNameByActionReturnsCurrentIfItCanHandleTheActionEvenIfMoreThanOnePluginMatches() {
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('extensionName' => 'CurrentExtension', 'pluginName' => 'CurrentPlugin', 'controllerConfiguration' => array('ControllerName' => array('actions' => array('otherAction'))))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $actualResult = Tx_Extbase_Utility_Extension::getPluginNameByAction('CurrentExtension', 'ControllerName', 'otherAction');
+               $expectedResult = 'CurrentPlugin';
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
        public function getTargetPidByPluginSignatureReturnsNullIfConfigurationManagerIsNotInitialized() {
-               $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPluginSignature('plugin_signature'));
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(NULL));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'PluginName'));
        }
 
        /**
         * @test
         */
-       public function getTargetPidByPluginSignatureReturnsNullIfDefaultPidIsNotConfigured() {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getConfiguration'));
-               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with($GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['extensionname_someplugin.'])->will($this->returnValue(array()));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
-               $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPluginSignature('extensionname_someplugin'));
+       public function getTargetPidByPluginSignatureReturnsNullIfDefaultPidIsZero() {
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 0))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
+               $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'PluginName'));
        }
 
        /**
         * @test
         */
        public function getTargetPidByPluginSignatureReturnsTheConfiguredDefaultPid() {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getConfiguration'));
-               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with($GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['extensionname_someplugin.'])->will($this->returnValue(array('view' => array('defaultPid' => '123'))));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 123))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                $expectedResult = 123;
-               $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPluginSignature('extensionname_someplugin');
+               $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
                $this->assertEquals($expectedResult, $actualResult);
        }
 
@@ -462,10 +540,12 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @test
         */
        public function getTargetPidByPluginSignatureDeterminesTheTargetPidIfDefaultPidIsAuto() {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getConfiguration'));
-               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with($GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['extensionname_someplugin.'])->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                $pluginSignature = 'extensionname_someplugin';
                $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
                $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->with('tt_content')->will($this->returnValue(' AND enable_fields'));
@@ -473,12 +553,12 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
                $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with(
                        'pid',
                        'tt_content',
-                       'list_type="pluginSignature" AND enable_fields',
+                       'list_type="pluginSignature" AND CType="list" AND enable_fields',
                        '',
                        ''
                )->will($this->returnValue(array(array('pid' => '321'))));
                $expectedResult = 321;
-               $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPluginSignature($pluginSignature);
+               $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
                $this->assertEquals($expectedResult, $actualResult);
        }
 
@@ -486,15 +566,17 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @test
         */
        public function getTargetPidByPluginSignatureReturnsNullIfTargetPidCouldNotBeDetermined() {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getConfiguration'));
-               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with($GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['extensionname_someplugin.'])->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
                $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
                $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
                $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array()));
-               $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPluginSignature('extensionname_someplugin'));
+               $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin'));
        }
 
        /**
@@ -502,15 +584,17 @@ tt_content.list.20.myextension_pi1 {', $staticTypoScript);
         * @expectedException Tx_Extbase_Exception
         */
        public function getTargetPidByPluginSignatureThrowsExceptionIfMoreThanOneTargetPidsWereFound() {
-               $dispatcher = new Tx_Extbase_Dispatcher();
-               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManager', array('getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getConfiguration'));
-               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with($GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['extensionname_someplugin.'])->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
-               $dispatcher->injectConfigurationManager($mockConfigurationManager);
+               $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
+               $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
+               $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
+               $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
+               t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
+
                $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
                $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
                $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
                $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array(array('pid' => 123), array('pid' => 124))));
-               Tx_Extbase_Utility_Extension::getTargetPidByPluginSignature('extensionname_someplugin');
+               Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
        }
 
 }