/**
  * @test
  * @author Robert Lemke <robert@typo3.org>
  */
 public function mapRequestArgumentsToControllerArgumentsPreparesInformationAndValidatorsAndMapsAndValidates()
 {
     $mockObjectFactory = $this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface');
     $mockValidator = $this->getMock('F3\\FLOW3\\MVC\\Controller\\ArgumentsValidator', array(), array(), '', FALSE);
     $mockObjectManager = $this->getMock('F3\\FLOW3\\Object\\ObjectManagerInterface');
     $mockObjectManager->expects($this->once())->method('getObject')->with('F3\\FLOW3\\MVC\\Controller\\ArgumentsValidator')->will($this->returnValue($mockValidator));
     $mockArgumentFoo = $this->getMock('F3\\FLOW3\\MVC\\Controller\\Argument', array(), array('foo', 'fooType'));
     $mockArgumentFoo->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $mockArgumentBar = $this->getMock('F3\\FLOW3\\MVC\\Controller\\Argument', array(), array('bar', 'barType'));
     $mockArgumentBar->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $mockArguments = new \F3\FLOW3\MVC\Controller\Arguments($mockObjectFactory);
     $mockArguments->addArgument($mockArgumentFoo);
     $mockArguments->addArgument($mockArgumentBar);
     $mockRequest = $this->getMock('F3\\FLOW3\\MVC\\Web\\Request');
     $mockRequest->expects($this->once())->method('getArguments')->will($this->returnValue(array('requestFoo', 'requestBar')));
     $mockMappingResults = $this->getMock('F3\\FLOW3\\Property\\MappingResults');
     $mockPropertyMapper = $this->getMock('F3\\FLOW3\\Property\\PropertyMapper', array(), array(), '', FALSE);
     $mockPropertyMapper->expects($this->once())->method('mapAndValidate')->with(array('foo', 'bar'), array('requestFoo', 'requestBar'), $mockArguments, array(), $mockValidator)->will($this->returnValue(TRUE));
     $mockPropertyMapper->expects($this->once())->method('getMappingResults')->will($this->returnValue($mockMappingResults));
     $controller = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\MVC\\Controller\\AbstractController'), array('dummy'), array(), '', FALSE);
     $controller->_set('arguments', $mockArguments);
     $controller->_set('request', $mockRequest);
     $controller->_set('propertyMapper', $mockPropertyMapper);
     $controller->_set('objectManager', $mockObjectManager);
     $controller->_call('mapRequestArgumentsToControllerArguments');
     $this->assertSame($mockMappingResults, $controller->_get('argumentsMappingResults'));
 }
 /**
  * @test
  * @author Christopher Hlubek <hlubek@networkteam.com>
  */
 public function isPropertyValidCallsAddErrorsForArgumentIfConjunctionIsNotValid()
 {
     $mockValidatorChain = $this->getMock('F3\\FLOW3\\Validation\\Validator\\ValidatorInterface');
     $mockValidatorChain->expects($this->once())->method('isValid')->will($this->returnValue(FALSE));
     $mockValidatorChain->expects($this->once())->method('getErrors')->will($this->returnValue(array('error')));
     $mockArgument = $this->getMock('F3\\FLOW3\\MVC\\Controller\\Argument', array(), array(), '', FALSE);
     $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $mockArgument->expects($this->any())->method('getValidator')->will($this->returnValue($mockValidatorChain));
     $mockArgument->expects($this->any())->method('getDataType')->will($this->returnValue('FooDataType'));
     $mockArgument->expects($this->any())->method('getValue')->will($this->returnValue('defaultValue'));
     $mockArgument->expects($this->any())->method('isRequired')->will($this->returnValue(TRUE));
     $arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface'));
     $arguments->addArgument($mockArgument);
     $validator = $this->getMock('F3\\FLOW3\\MVC\\Controller\\ArgumentsValidator', array('addErrorsForArgument'));
     $validator->expects($this->once())->method('addErrorsForArgument')->with(array('error'), 'foo');
     $validator->isPropertyValid($arguments, 'foo');
 }
 /**
  * @test
  * @author Sebastian Kurfürst <sebastian@typo3.org>
  */
 public function addNewArgumentCanAddArgumentsMarkedAsOptionalWithDefaultValues()
 {
     $mockObjectFactory = $this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface');
     $mockObjectFactory->expects($this->once())->method('create')->with('F3\\FLOW3\\MVC\\Controller\\Argument', 'dummyName', 'Text')->will($this->returnValue(new \F3\FLOW3\MVC\Controller\Argument('someArgument', 'Text')));
     $arguments = new \F3\FLOW3\MVC\Controller\Arguments($mockObjectFactory);
     $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.');
 }