/** * @test */ 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 VENDOR\\ModelCollection\\Domain\\Model\\Model')); $mockReflectionService = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class, 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(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array(), array(), '', false); $mockArrayValidator = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array(), array(), '', false); $mockFooValidator = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array(), array(), '', false); $mockBarValidator = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array(), array(), '', false); $mockQuuxValidator = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array(), array(), '', false); $conjunction1 = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator::class, 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(\TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator::class, array(), array(), '', false); $conjunction2->expects($this->at(0))->method('addValidator')->with($mockArrayValidator); $conjunction2->expects($this->at(1))->method('addValidator')->with($mockQuuxValidator); $mockArguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments(); $mockArguments->addArgument(new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('arg1', 'dummyValue')); $mockArguments->addArgument(new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('arg2', 'dummyValue')); $validatorResolver = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Validation\ValidatorResolver::class, array('createValidator')); $validatorResolver->expects($this->at(0))->method('createValidator')->with(\TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator::class)->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(\TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator::class)->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('VENDOR\\ModelCollection\\Domain\\Model\\Model')->will($this->returnValue($mockQuuxValidator)); $validatorResolver->_set('reflectionService', $mockReflectionService); $result = $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction'); $this->assertEquals(array('arg1' => $conjunction1, 'arg2' => $conjunction2), $result); }
/** * @test * @author Christopher Hlubek <*****@*****.**> */ public function removeAllClearsAllArguments() { $mockArgument1 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\Argument::class, array('getName', 'getShortName'), array(), '', FALSE); $mockArgument1->expects($this->any())->method('getName')->will($this->returnValue('argumentName1')); $mockArgument2 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\Argument::class, array('getName', 'getShortName'), array(), '', FALSE); $mockArgument2->expects($this->any())->method('getName')->will($this->returnValue('argumentName2')); $arguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments(); $arguments[] = $mockArgument1; $arguments[] = $mockArgument2; $this->assertTrue($arguments->hasArgument('argumentName2')); $arguments->removeAll(); $this->assertFalse($arguments->hasArgument('argumentName2')); }