33 $this->validatorResolver = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(
'dummy'));
34 $this->mockObjectManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
35 $this->validatorResolver->_set(
'objectManager', $this->mockObjectManager);
44 $extensionName =
'tx_foo';
46 $realClassName =
'Tx_' . $extensionName .
'_Validation_Validator_' . $className .
'Validator';
47 $validatorName = $extensionName .
':' . $className;
48 eval(
'class ' . $realClassName .
' implements TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface {}');
49 $this->assertEquals($realClassName, $this->validatorResolver->_call(
'resolveValidatorObjectName', $validatorName));
57 $validatorName =
'tx_foo:' . $className;
58 $this->setExpectedException(
'TYPO3\\CMS\\Extbase\\Validation\\Exception\\NoSuchValidatorException',
'', 1365799920);
59 $this->validatorResolver->_call(
'resolveValidatorObjectName', $validatorName);
66 $extensionName =
'tx_foo';
68 $realClassName =
'Tx_' . $extensionName .
'_Validation_Validator_' . $className .
'Validator';
69 $validatorName = $extensionName .
':' . $className;
70 eval(
'class ' . $realClassName .
'{}');
71 $this->setExpectedException(
'TYPO3\\CMS\\Extbase\\Validation\\Exception\\NoSuchValidatorException',
'', 1365776838);
72 $this->validatorResolver->_call(
'resolveValidatorObjectName', $validatorName);
82 $expectedValidatorName = $className .
'Validator';
83 eval(
'class ' . $expectedValidatorName .
' implements TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface {}');
85 $expectedValidatorName,
86 $this->validatorResolver->_call(
'resolveValidatorObjectName', $className)
95 $this->setExpectedException(
'TYPO3\\CMS\\Extbase\\Validation\\Exception\\NoSuchValidatorException',
'', 1365799920);
96 $this->validatorResolver->_call(
'resolveValidatorObjectName', $className);
104 $expectedValidatorName = $className .
'Validator';
105 eval(
'class ' . $expectedValidatorName .
'{}');
106 $this->setExpectedException(
'TYPO3\\CMS\\Extbase\\Validation\\Exception\\NoSuchValidatorException',
'', 1365776838);
107 $this->validatorResolver->_call(
'resolveValidatorObjectName', $className);
117 array(
'TYPO3\\CMS\\Mypkg\\Validation\\Validator',
'MySecondValidator',
'TYPO3.CMS.Mypkg:MySecond'),
118 array(
'Acme\\Mypkg\\Validation\\Validator',
'MyThirdValidator',
'Acme.Mypkg:MyThird')
131 eval(
'namespace ' . $namespace .
'; class ' . $className .
' implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {}');
132 $this->assertSame($namespace .
'\\' . $className, $this->validatorResolver->_call(
'resolveValidatorObjectName', $shorthandValidatorname));
139 eval(
'namespace TYPO3\\CMS\\Extbase\\Validation\\Validator;' . LF .
'class FooValidator implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {}');
140 $this->assertSame(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\FooValidator', $this->validatorResolver->_call(
'resolveValidatorObjectName',
'Foo'));
148 $validatorOptions = array(
'requiredOption' =>
'foo',
'demoOption' =>
'bar');
149 $mockValidator = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Tests\\Unit\\Validation\\Validator\\Fixture\\AbstractValidatorClass', array(
'dummy'), array($validatorOptions), $className);
150 $this->mockObjectManager->expects($this->any())->method(
'get')->with($className, $validatorOptions)->will($this->returnValue($mockValidator));
153 $validatorResolver->expects($this->once())->method(
'resolveValidatorObjectName')->with($className)->will($this->returnValue($className));
155 $this->assertEquals($validatorOptions, $validator->_get(
'options'));
156 $this->assertSame($mockValidator, $validator);
163 $this->markTestSkipped(
'');
165 $this->setExpectedException(
'\\TYPO3\\CMS\\Extbase\\Validation\\Exception\NoSuchValidatorException',
'', 1365799920);
166 $this->validatorResolver->createValidator($className);
173 $this->markTestSkipped(
'Functionality is different now.');
174 $mockConjunctionValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(),
'', FALSE);
175 $validatorResolver = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(
'buildBaseValidatorConjunction'), array(),
'', FALSE);
176 $validatorResolver->expects($this->once())->method(
'buildBaseValidatorConjunction')->with(
'Tx_Virtual_Foo')->will($this->returnValue($mockConjunctionValidator));
178 $this->assertSame($mockConjunctionValidator,
$result,
'#1');
180 $this->assertSame($mockConjunctionValidator,
$result,
'#2');
188 $mockController = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array(
'fooAction'), array(),
'', FALSE);
189 $methodParameters = array();
190 $mockReflectionService = $this->getMock(
'TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(),
'', FALSE);
191 $mockReflectionService->expects($this->once())->method(
'getMethodParameters')->with(get_class($mockController),
'fooAction')->will($this->returnValue($methodParameters));
195 $this->assertSame(array(),
$result);
204 $mockObject = $this->getMock(
'stdClass', array(
'fooMethod'), array(),
'', FALSE);
205 $methodParameters = array(
213 $methodTagsValues = array(
219 '$arg1 Foo(bar = baz), Bar',
220 '$arg2 VENDOR\\ModelCollection\\Domain\\Model\\Model' 223 $mockReflectionService = $this->getMock(
'TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(),
'', FALSE);
224 $mockReflectionService->expects($this->once())->method(
'getMethodTagsValues')->with(get_class($mockObject),
'fooAction')->will($this->returnValue($methodTagsValues));
225 $mockReflectionService->expects($this->once())->method(
'getMethodParameters')->with(get_class($mockObject),
'fooAction')->will($this->returnValue($methodParameters));
226 $mockStringValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
227 $mockArrayValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
228 $mockFooValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
229 $mockBarValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
230 $mockQuuxValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
231 $conjunction1 = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(),
'', FALSE);
232 $conjunction1->expects($this->at(0))->method(
'addValidator')->with($mockStringValidator);
233 $conjunction1->expects($this->at(1))->method(
'addValidator')->with($mockFooValidator);
234 $conjunction1->expects($this->at(2))->method(
'addValidator')->with($mockBarValidator);
235 $conjunction2 = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(),
'', FALSE);
236 $conjunction2->expects($this->at(0))->method(
'addValidator')->with($mockArrayValidator);
237 $conjunction2->expects($this->at(1))->method(
'addValidator')->with($mockQuuxValidator);
238 $mockArguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
239 $mockArguments->addArgument(
new \
TYPO3\CMS\Extbase\Mvc\Controller\Argument(
'arg1',
'dummyValue'));
240 $mockArguments->addArgument(
new \
TYPO3\CMS\Extbase\Mvc\Controller\Argument(
'arg2',
'dummyValue'));
242 $validatorResolver->expects($this->at(0))->method(
'createValidator')->with(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($conjunction1));
243 $validatorResolver->expects($this->at(1))->method(
'createValidator')->with(
'string')->will($this->returnValue($mockStringValidator));
244 $validatorResolver->expects($this->at(2))->method(
'createValidator')->with(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($conjunction2));
245 $validatorResolver->expects($this->at(3))->method(
'createValidator')->with(
'array')->will($this->returnValue($mockArrayValidator));
246 $validatorResolver->expects($this->at(4))->method(
'createValidator')->with(
'Foo', array(
'bar' =>
'baz'))->will($this->returnValue($mockFooValidator));
247 $validatorResolver->expects($this->at(5))->method(
'createValidator')->with(
'Bar')->will($this->returnValue($mockBarValidator));
248 $validatorResolver->expects($this->at(6))->method(
'createValidator')->with(
'VENDOR\\ModelCollection\\Domain\\Model\\Model')->will($this->returnValue($mockQuuxValidator));
251 $this->assertEquals(array(
'arg1' => $conjunction1,
'arg2' => $conjunction2),
$result);
260 $mockObject = $this->getMock(
'stdClass', array(
'fooMethod'), array(),
'', FALSE);
261 $methodParameters = array(
266 $methodTagsValues = array(
271 '$arg2 VENDOR\\ModelCollection\\Domain\\Model\\Model' 274 $mockReflectionService = $this->getMock(
'TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(),
'', FALSE);
275 $mockReflectionService->expects($this->once())->method(
'getMethodTagsValues')->with(get_class($mockObject),
'fooAction')->will($this->returnValue($methodTagsValues));
276 $mockReflectionService->expects($this->once())->method(
'getMethodParameters')->with(get_class($mockObject),
'fooAction')->will($this->returnValue($methodParameters));
277 $mockStringValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
278 $mockQuuxValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(),
'', FALSE);
279 $conjunction1 = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(),
'', FALSE);
280 $conjunction1->expects($this->at(0))->method(
'addValidator')->with($mockStringValidator);
282 $validatorResolver->expects($this->at(0))->method(
'createValidator')->with(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($conjunction1));
283 $validatorResolver->expects($this->at(1))->method(
'createValidator')->with(
'string')->will($this->returnValue($mockStringValidator));
284 $validatorResolver->expects($this->at(2))->method(
'createValidator')->with(
'VENDOR\\ModelCollection\\Domain\\Model\\Model')->will($this->returnValue($mockQuuxValidator));
286 $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject),
'fooAction');
295 $mockObject = $this->getMock(
'stdClass');
296 $className = get_class($mockObject);
297 $propertyTagsValues = array(
299 'var' => array(
'string'),
301 'Foo(bar= baz), Bar',
306 'var' => array(
'integer'),
308 'VENDOR\\ModelCollection\\Domain\\Validator\\ModelValidator' 313 $mockReflectionService = $this->getMock(
'TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(),
'', FALSE);
314 $mockReflectionService->expects($this->at(0))->method(
'getClassPropertyNames')->with($className)->will($this->returnValue(array(
'foo',
'bar')));
315 $mockReflectionService->expects($this->at(1))->method(
'getPropertyTagsValues')->with($className,
'foo')->will($this->returnValue($propertyTagsValues[
'foo']));
316 $mockReflectionService->expects($this->at(2))->method(
'getPropertyTagsValues')->with($className,
'bar')->will($this->returnValue($propertyTagsValues[
'bar']));
317 $mockObjectValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array(
'dummy'), array(),
'', FALSE);
318 $mockObjectManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(),
'', FALSE);
319 $mockObjectManager->expects($this->at(0))->method(
'get')->with(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator')->will($this->returnValue($mockObjectValidator));
323 $validatorResolver->expects($this->at(0))->method(
'createValidator')->with(
'Foo', array(
'bar' =>
'baz'))->will($this->returnValue($mockObjectValidator));
324 $validatorResolver->expects($this->at(1))->method(
'createValidator')->with(
'Bar')->will($this->returnValue($mockObjectValidator));
325 $validatorResolver->expects($this->at(2))->method(
'createValidator')->with(
'Baz')->will($this->returnValue($mockObjectValidator));
326 $validatorResolver->expects($this->at(3))->method(
'createValidator')->with(
'VENDOR\\ModelCollection\\Domain\\Validator\\ModelValidator')->will($this->returnValue($mockObjectValidator));
337 'no replace' => array(
'VENDOR\\ModelCollection\\Domain\\Model\\Model',
'VENDOR\\ModelCollection\\Domain\\Validator\\ModelValidator'),
338 'replace in not namespaced class' => array(
'Tx_ModelCollection_Domain_Model_Model',
'Tx_ModelCollection_Domain_Validator_ModelValidator'),
339 'replace in namespaced class' => array(
'VENDOR\\ModelCollection\\Domain\\Model\\Model',
'VENDOR\\ModelCollection\\Domain\\Validator\\ModelValidator')
351 $mockObjectManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(),
'', FALSE);
354 $validatorResolver->expects($this->once())->method(
'createValidator')->with($validatorClassName)->will($this->returnValue(NULL));
355 $validatorResolver->_call(
'buildBaseValidatorConjunction', $modelClassName, $modelClassName);
363 $validatorName = $this->
getUniqueId(
'FooValidator');
364 eval(
'namespace TYPO3\CMS\Extbase\Validation\Validator;' . LF .
'class ' . $validatorName .
'Validator implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {}');
365 $mockValidatorResolver = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(
'getValidatorType'));
366 $mockValidatorResolver->expects($this->once())->method(
'getValidatorType')->with($validatorName)->will($this->returnValue($validatorName));
368 $mockValidatorResolver->_call(
'resolveValidatorObjectName', $validatorName);
376 $this->assertEquals(
'Integer', $this->validatorResolver->_call(
'getValidatorType',
'integer'));
377 $this->assertEquals(
'Integer', $this->validatorResolver->_call(
'getValidatorType',
'int'));
378 $this->assertEquals(
'String', $this->validatorResolver->_call(
'getValidatorType',
'string'));
379 $this->assertEquals(
'Array', $this->validatorResolver->_call(
'getValidatorType',
'array'));
380 $this->assertEquals(
'Float', $this->validatorResolver->_call(
'getValidatorType',
'float'));
381 $this->assertEquals(
'Float', $this->validatorResolver->_call(
'getValidatorType',
'double'));
382 $this->assertEquals(
'Boolean', $this->validatorResolver->_call(
'getValidatorType',
'boolean'));
383 $this->assertEquals(
'Boolean', $this->validatorResolver->_call(
'getValidatorType',
'bool'));
384 $this->assertEquals(
'Boolean', $this->validatorResolver->_call(
'getValidatorType',
'bool'));
385 $this->assertEquals(
'Number', $this->validatorResolver->_call(
'getValidatorType',
'number'));
386 $this->assertEquals(
'Number', $this->validatorResolver->_call(
'getValidatorType',
'numeric'));
394 $this->assertEquals(
'Raw', $this->validatorResolver->_call(
'getValidatorType',
'mixed'));
409 'argumentName' =>
'var',
410 'validators' => array(
411 array(
'validatorName' =>
'Bar',
'validatorOptions' => array())
418 'argumentName' =>
'var',
419 'validators' => array(
420 array(
'validatorName' =>
'Bar',
'validatorOptions' => array()),
421 array(
'validatorName' =>
'Foo',
'validatorOptions' => array())
426 '$var Baz (Foo=Bar)',
428 'argumentName' =>
'var',
429 'validators' => array(
430 array(
'validatorName' =>
'Baz',
'validatorOptions' => array(
'Foo' =>
'Bar'))
435 '$var Buzz (Foo="B=a, r", Baz=1)',
437 'argumentName' =>
'var',
438 'validators' => array(
439 array(
'validatorName' =>
'Buzz',
'validatorOptions' => array(
'Foo' =>
'B=a, r',
'Baz' =>
'1'))
444 '$var Foo(Baz=1, Bar=Quux)',
446 'argumentName' =>
'var',
447 'validators' => array(
448 array(
'validatorName' =>
'Foo',
'validatorOptions' => array(
'Baz' =>
'1',
'Bar' =>
'Quux'))
453 '$var Pax, Foo(Baz = \'1\', Bar = Quux)',
455 'argumentName' =>
'var',
456 'validators' => array(
457 array(
'validatorName' =>
'Pax',
'validatorOptions' => array()),
458 array(
'validatorName' =>
'Foo',
'validatorOptions' => array(
'Baz' =>
'1',
'Bar' =>
'Quux'))
463 '$var Reg (P="[at]*(h|g)"), Quux',
465 'argumentName' =>
'var',
466 'validators' => array(
467 array(
'validatorName' =>
'Reg',
'validatorOptions' => array(
'P' =>
'[at]*(h|g)')),
468 array(
'validatorName' =>
'Quux',
'validatorOptions' => array())
473 '$var Baz (Foo="B\\"ar")',
475 'argumentName' =>
'var',
476 'validators' => array(
477 array(
'validatorName' =>
'Baz',
'validatorOptions' => array(
'Foo' =>
'B"ar'))
482 '$var F3_TestPackage_Quux',
484 'argumentName' =>
'var',
485 'validators' => array(
486 array(
'validatorName' =>
'F3_TestPackage_Quux',
'validatorOptions' => array())
491 '$var Baz(Foo="5"), Bar(Quux="123")',
493 'argumentName' =>
'var',
494 'validators' => array(
495 array(
'validatorName' =>
'Baz',
'validatorOptions' => array(
'Foo' =>
'5')),
496 array(
'validatorName' =>
'Bar',
'validatorOptions' => array(
'Quux' =>
'123'))
501 '$var Baz(Foo="2"), Bar(Quux=123, Pax="a weird \\"string\\" with *freaky* \\stuff")',
503 'argumentName' =>
'var',
504 'validators' => array(
505 array(
'validatorName' =>
'Baz',
'validatorOptions' => array(
'Foo' =>
'2')),
506 array(
'validatorName' =>
'Bar',
'validatorOptions' => array(
'Quux' =>
'123',
'Pax' =>
'a weird "string" with *freaky* \\stuff'))
510 'namespaced validator class name' => array(
511 'annotation' =>
'$var F3\TestPackage\Quux',
513 'argumentName' =>
'var',
514 'validators' => array(
515 array(
'validatorName' =>
'F3\TestPackage\Quux',
'validatorOptions' => array())
519 'shorthand notation for system validator' => array(
520 'annotation' =>
'$var TYPO3.CMS.Mypkg:MySecond',
522 'argumentName' =>
'var',
523 'validators' => array(
524 array(
'validatorName' =>
'TYPO3.CMS.Mypkg:MySecond',
'validatorOptions' => array())
528 'shorthand notation for custom validator with parameter' => array(
529 'annotation' =>
'$var Acme.Mypkg:MyThird(Foo="2")',
531 'argumentName' =>
'var',
532 'validators' => array(
533 array(
'validatorName' =>
'Acme.Mypkg:MyThird',
'validatorOptions' => array(
'Foo' =>
'2'))
548 $result = $this->validatorResolver->_call(
'parseValidatorAnnotation', $annotation);
549 $this->assertEquals(
$result, $expectedResult);
createValidatorThrowsNoSuchValidatorExceptionIfAValidatorCouldNotBeResolved()
getValidatorTypeCorrectlyRenamesPhpDataTypes()
buildMethodArgumentsValidatorConjunctionsThrowsExceptionIfValidationAnnotationForNonExistingArgumentExists()
buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction()
getBaseValidatorCachesTheResultOfTheBuildBaseValidatorChainCalls()
getValidatorTypeRenamesMixedToRaw()
buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments()
buildBaseValidatorConjunctionCreatesValidatorFromClassName($modelClassName, $validatorClassName)
resolveValidatorObjectNameReturnsValidatorNameIfClassExists()
resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExistsButDoesNotImplementValidatorInterface()
resolveValidatorObjectNameThrowsNoSuchValidatorExceptionIfClassExistsButDoesNotImplementValidatorInterface()
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
resolveValidatorObjectNameCallsGetValidatorType()
parseValidatorAnnotationCanParseAnnotations($annotation, $expectedResult)
resolveValidatorObjectNameThrowsNoSuchValidatorExceptionIfClassNotExists()
resolveValidatorObjectNameCanResolveShortNamesOfBuiltInValidators()
resolveValidatorObjectNameWithShortHandNotationThrowsExceptionIfClassNotExists()
buildMethodArgumentsValidatorConjunctionsBuildsAConjunctionFromValidateAnnotationsOfTheSpecifiedMethod()
resolveValidatorObjectNameCanResolveNamespacedShorthandValidatornames($namespace, $className, $shorthandValidatorname)
namespacedShorthandValidatornames()
resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExists()
createValidatorResolvesAndReturnsAValidatorAndPassesTheGivenOptions()