Esempio n. 1
0
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function removeAllClearsAllArguments()
 {
     $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('argumentName2'));
 }
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function buildMethodArgumentsValidatorConjunctionsBuildsAConjunctionFromValidateAnnotationsOfTheSpecifiedMethod()
 {
     $mockObject = $this->getMock('stdClass', array('fooMethod'), array(), '', FALSE);
     $methodParameters = array('arg1' => array('type' => 'string'), 'arg2' => array('type' => 'array'));
     $methodTagsValues = array('param' => array('string $arg1', 'array $arg2'), 'validate' => array('$arg1 Foo(bar = baz), Bar', '$arg2 F3_TestPackage_Quux'));
     $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
     $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodTagsValues));
     $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodParameters));
     $mockStringValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array(), array(), '', FALSE);
     $mockArrayValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array(), array(), '', FALSE);
     $mockFooValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array(), array(), '', FALSE);
     $mockBarValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array(), array(), '', FALSE);
     $mockQuuxValidator = $this->getMock('Tx_Extbase_Validation_Validator_ValidatorInterface', array(), array(), '', FALSE);
     $conjunction1 = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
     $conjunction1->expects($this->at(0))->method('addValidator')->with($mockStringValidator);
     $conjunction1->expects($this->at(1))->method('addValidator')->with($mockFooValidator);
     $conjunction1->expects($this->at(2))->method('addValidator')->with($mockBarValidator);
     $conjunction2 = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
     $conjunction2->expects($this->at(0))->method('addValidator')->with($mockArrayValidator);
     $conjunction2->expects($this->at(1))->method('addValidator')->with($mockQuuxValidator);
     $mockObjectFactory = $this->getMock('Tx_Extbase_Object_FactoryInterface');
     $mockArguments = new Tx_Extbase_MVC_Controller_Arguments();
     $mockArguments->addArgument(new Tx_Extbase_MVC_Controller_Argument('arg1', 'dummyValue'));
     $mockArguments->addArgument(new Tx_Extbase_MVC_Controller_Argument('arg2', 'dummyValue'));
     $validatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array('createValidator'));
     $validatorResolver->expects($this->at(0))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction1));
     $validatorResolver->expects($this->at(1))->method('createValidator')->with('string')->will($this->returnValue($mockStringValidator));
     $validatorResolver->expects($this->at(2))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction2));
     $validatorResolver->expects($this->at(3))->method('createValidator')->with('array')->will($this->returnValue($mockArrayValidator));
     $validatorResolver->expects($this->at(4))->method('createValidator')->with('Foo', array('bar' => 'baz'))->will($this->returnValue($mockFooValidator));
     $validatorResolver->expects($this->at(5))->method('createValidator')->with('Bar')->will($this->returnValue($mockBarValidator));
     $validatorResolver->expects($this->at(6))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockQuuxValidator));
     $validatorResolver->injectReflectionService($mockReflectionService);
     $result = $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction');
     $this->assertEquals(array('arg1' => $conjunction1, 'arg2' => $conjunction2), $result);
 }
 /**
  * @test
  */
 public function mapRequestArgumentsToControllerArgumentsPreparesInformationAndValidatorsAndMapsAndValidates()
 {
     $mockValidator = new Tx_Extbase_MVC_Controller_ArgumentsValidator();
     // FIXME see original FLOW3 code
     $mockArgumentFoo = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array('foo'), '', FALSE);
     $mockArgumentFoo->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $mockArgumentBar = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array(), array('bar'), '', FALSE);
     $mockArgumentBar->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $mockArguments = new Tx_Extbase_MVC_Controller_Arguments();
     $mockArguments->addArgument($mockArgumentFoo);
     $mockArguments->addArgument($mockArgumentBar);
     $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request');
     $mockRequest->expects($this->once())->method('getArguments')->will($this->returnValue(array('requestFoo', 'requestBar')));
     $mockMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults');
     $mockPropertyMapper = $this->getMock('Tx_Extbase_Property_Mapper', 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('Tx_Extbase_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'));
     // $this->assertTrue(in_array('Tx_Extbase_Validation_Validator_ObjectValidatorInterface', class_implements($controller->_get('argumentsMappingResults'))));
 }