/** * @test * @author Robert Lemke <*****@*****.**> */ public function addingAnArgumentReplacesArgumentWithSameName() { $arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface')); $firstArgument = new \F3\FLOW3\MVC\Controller\Argument('argumentName1234', 'Text'); $arguments->addArgument($firstArgument); $secondArgument = new \F3\FLOW3\MVC\Controller\Argument('argumentName1234', 'Text'); $arguments->addArgument($secondArgument); $this->assertSame($secondArgument, $arguments->getArgument('argumentName1234'), 'The added and retrieved argument is not the same.'); }
/** * @test * @author Christopher Hlubek <*****@*****.**> */ 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 Robert Lemke <*****@*****.**> */ 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')); }