[~TASK] Extbase: Refactored Dispatcher. Moved initialization of cache and reflection...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / MVC / Controller / Arguments_testcase.php
index 8d8efbc..69a3f07 100644 (file)
@@ -29,7 +29,6 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function argumentsObjectIsOfScopePrototype() {
                $arguments1 = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
@@ -39,11 +38,10 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function addingAnArgumentManuallyWorks() {
                $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $newArgument = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Argument', 'argumentName1234');
+               $newArgument = $this->objectManager->getObject('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.');
@@ -51,61 +49,60 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function addingAnArgumentReplacesArgumentWithSameName() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
 
-               $firstArgument = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Argument', 'argumentName1234');
-               $arguments->addArgument($firstArgument);
+               $mockFirstArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockFirstArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
+               $arguments->addArgument($mockFirstArgument);
 
-               $secondArgument = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Argument', 'argumentName1234');
-               $arguments->addArgument($secondArgument);
+               $mockSecondArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockSecondArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
+               $arguments->addArgument($mockSecondArgument);
 
-               $this->assertSame($secondArgument, $arguments->getArgument('argumentName1234'), 'The added and retrieved argument is not the same.');
+               $this->assertSame($mockSecondArgument, $arguments->getArgument('argumentName1234'), 'The added and retrieved argument is not the same.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function addNewArgumentProvidesFluentInterface() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
-
-               $newArgument = $arguments->addNewArgument('someArgument');
+               $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.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function addingArgumentThroughArrayAccessWorks() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $argument = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Argument', 'argumentName1234');
-               $arguments[] = $argument;
+               $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               
+               $arguments[] = $mockArgument;
                $this->assertTrue($arguments->hasArgument('argumentName1234'), 'Added argument does not exist.');
-               $this->assertSame($argument, $arguments->getArgument('argumentName1234'), 'Added and retrieved arguments are not the same.');
+               $this->assertSame($mockArgument, $arguments->getArgument('argumentName1234'), 'Added and retrieved arguments are not the same.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function retrievingArgumentThroughArrayAccessWorks() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
+               $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
 
-               $newArgument = $arguments->addNewArgument('someArgument');
-               $this->assertSame($newArgument, $arguments['someArgument'], 'Argument retrieved by array access is not the one we added.');
+               $arguments[] = $mockArgument;
+               $this->assertSame($mockArgument, $arguments['argumentName1234'], 'Argument retrieved by array access is not the one we added.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function getArgumentWithNonExistingArgumentNameThrowsException() {
                $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
@@ -118,45 +115,53 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function issetReturnsCorrectResult() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
+               $mockArgument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('argumentName1234'));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
 
-               $this->assertFalse(isset($arguments['someArgument']), 'isset() did not return FALSE.');
-               $arguments->addNewArgument('someArgument');
-               $this->assertTrue(isset($arguments['someArgument']), 'isset() did not return TRUE.');
+               $this->assertFalse(isset($arguments['argumentName1234']), 'isset() did not return FALSE.');
+               $arguments[] = $mockArgument;
+               $this->assertTrue(isset($arguments['argumentName1234']), 'isset() did not return TRUE.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function getArgumentNamesReturnsNamesOfAddedArguments() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
-               $arguments->addNewArgument('first');
-               $arguments->addNewArgument('second');
-               $arguments->addNewArgument('third');
-
-               $expectedArgumentNames = array('first', 'second', 'third');
+               $mockArgument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1'));
+               $mockArgument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2'));
+               $mockArgument3 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
+               $mockArgument3->expects($this->any())->method('getName')->will($this->returnValue('argumentName3'));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments[] = $mockArgument1;
+               $arguments[] = $mockArgument2;
+               $arguments[] = $mockArgument3;
+
+               $expectedArgumentNames = array('argumentName1', 'argumentName2', 'argumentName3');
                $this->assertEquals($expectedArgumentNames, $arguments->getArgumentNames(), 'Returned argument names were not as expected.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function getArgumentShortNamesReturnsShortNamesOfAddedArguments() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
-               $arguments->addNewArgument('first')->setShortName('a');
-               $arguments->addNewArgument('second')->setShortName('b');
-               $arguments->addNewArgument('third')->setShortName('c');
+               $mockArgument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
+               $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1'));
+               $mockArgument1->expects($this->any())->method('getShortName')->will($this->returnValue('a'));
+               $mockArgument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
+               $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2'));
+               $mockArgument2->expects($this->any())->method('getShortName')->will($this->returnValue('b'));
+               $mockArgument3 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
+               $mockArgument3->expects($this->any())->method('getName')->will($this->returnValue('argumentName3'));
+               $mockArgument3->expects($this->any())->method('getShortName')->will($this->returnValue('c'));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments[] = $mockArgument1;
+               $arguments[] = $mockArgument2;
+               $arguments[] = $mockArgument3;
 
                $expectedShortNames = array('a', 'b', 'c');
                $this->assertEquals($expectedShortNames, $arguments->getArgumentShortNames(), 'Returned argument short names were not as expected.');
@@ -164,60 +169,56 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function addNewArgumentCreatesAndAddsNewArgument() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
+               $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 = $arguments->addNewArgument('dummyName');
+               $addedArgument = $mockArguments->addNewArgument('dummyName');
                $this->assertType('Tx_Extbase_MVC_Controller_Argument', $addedArgument, 'addNewArgument() either did not add a new argument or did not return it.');
 
-               $retrievedArgument = $arguments['dummyName'];
+               $retrievedArgument = $mockArguments['dummyName'];
                $this->assertSame($addedArgument, $retrievedArgument, 'The added and the retrieved argument are not the same.');
-
-               $this->assertEquals('dummyName', $addedArgument->getName(), 'The name of the added argument is not as expected.');
        }
 
        /**
         * @test
-        * @author Robert Lemke <robert@typo3.org>
         */
        public function addNewArgumentAssumesTextDataTypeByDefault() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
+               $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 = $arguments->addNewArgument('dummyName');
-               $this->assertEquals('Text', $addedArgument->getDataType(), 'addNewArgument() did not create an argument of type "Text" by default.');
+               $addedArgument = $mockArguments->addNewArgument('dummyName');
        }
 
        /**
         * @test
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function addNewArgumentCanAddArgumentsMarkedAsRequired() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
+               $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 = $arguments->addNewArgument('dummyName', 'Text', TRUE);
-               $this->assertTrue($addedArgument->isRequired(), 'addNewArgument() did not create an argument that is marked as required.');
+               $addedArgument = $mockArguments->addNewArgument('dummyName', 'Text', TRUE);
        }
 
        /**
         * @test
-        * @author Sebastian Kurfürst <sebastian@typo3.org>
         */
        public function addNewArgumentCanAddArgumentsMarkedAsOptionalWithDefaultValues() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
+               $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));
 
-               $defaultValue = 'Default Value 42';
-               $addedArgument = $arguments->addNewArgument('dummyName', 'Text', FALSE, $defaultValue);
-               $this->assertEquals($defaultValue, $addedArgument->getValue(), 'addNewArgument() did not store the default value in the argument.');
+               $addedArgument = $mockArguments->addNewArgument('dummyName', 'Text', TRUE);
        }
 
        /**
@@ -227,8 +228,6 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
         */
        public function callingInvalidMethodThrowsException() {
                $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
                $arguments->nonExistingMethod();
        }
 
@@ -237,18 +236,17 @@ class Tx_Extbase_MVC_Controller_Arguments_testcase extends Tx_Extbase_BaseTestCa
         * @author Christopher Hlubek <hlubek@networkteam.com>
         */
        public function removeAllClearsAllArguments() {
-               $arguments = $this->objectManager->getObject('Tx_Extbase_MVC_Controller_Arguments');
-               $arguments->injectPersistenceManager($this->getMock('Tx_Extbase_Persistence_Manager', array(), array(), '', FALSE));
-               $arguments->injectQueryFactory($this->getMock('Tx_Extbase_Persistence_QueryFactory'));
-               $arguments->addNewArgument('foo');
-
+               $mockArgument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
+               $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1'));
+               $mockArgument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getShortName'), array(), '', FALSE);
+               $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2'));
+               $arguments = new Tx_Extbase_MVC_Controller_Arguments;
+               $arguments[] = $mockArgument1;
+               $arguments[] = $mockArgument2;
+
+               $this->assertTrue($arguments->hasArgument('argumentName2'));
                $arguments->removeAll();
-
-               $this->assertFalse($arguments->hasArgument('foo'));
-
-               $arguments->addNewArgument('bar');
-
-               $this->assertTrue($arguments->hasArgument('bar'));
+               $this->assertFalse($arguments->hasArgument('argumentName2'));
        }
 }
 ?>
\ No newline at end of file