54 protected function getValidator(array $options = array(), array $mockedMethods = array(
'translateErrorMessage')) {
55 return $this->
getAccessibleMock($this->validatorClassName, $mockedMethods, array($options),
'', TRUE);
63 'TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver',
64 array(
'createValidator',
'buildBaseValidatorConjunction',
'getBaseValidatorConjunction')
67 $this->configurationManager = $this->getMock(
68 'TYPO3\CMS\Extbase\Configuration\ConfigurationManager',
69 array(
'isFeatureEnabled'),
74 $this->configurationManager->expects($this->any())
75 ->method(
'isFeatureEnabled')
76 ->with(
'rewrittenPropertyMapper')
77 ->will($this->returnValue(TRUE));
78 $this->validator->injectConfigurationManager($this->configurationManager);
79 $this->validator->_set(
'validatorResolver', $this->mockValidatorResolver);
86 $this->assertFalse($this->validator->validate(NULL)->hasErrors());
93 $this->assertTrue($this->validator->validate(
new \StdClass())->hasErrors());
100 $this->validator->_set(
'options', array(
'elementValidator' =>
'EmailAddress'));
101 $this->mockValidatorResolver->expects($this->exactly(4))
102 ->method(
'createValidator')
103 ->with(
'EmailAddress')
104 ->will($this->returnValue($this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator', array(
'translateErrorMessage'))));
105 $this->validator->_set(
'validatorResolver', $this->mockValidatorResolver);
106 $arrayOfEmailAddresses = array(
108 'not a valid address',
113 $result = $this->validator->validate($arrayOfEmailAddresses);
115 $this->assertTrue(
$result->hasErrors());
116 $this->assertSame(2, count(
$result->getFlattenedErrors()));
124 eval(
'class ' . $classNameA .
'{ public $b = array(); public $integer = 5; }');
126 eval(
'class ' . $classNameB .
'{ public $a; public $c; public $integer = "Not an integer"; }');
127 $A =
new $classNameA();
128 $B =
new $classNameB();
135 $aValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array(
'translateErrorMessage'), array(array()));
136 $aValidator->injectConfigurationManager($this->configurationManager);
137 $this->validator->_set(
'options', array(
'elementValidator' =>
'Integer'));
138 $integerValidator = $this->getMock(
'TYPO3\\CMS\\Extbase\\Validation\\Validator\\IntegerValidator', array(
'translateErrorMessage'), array(array()));
140 $this->mockValidatorResolver->expects($this->any())
141 ->method(
'createValidator')
143 ->will($this->returnValue($integerValidator));
144 $this->mockValidatorResolver->expects($this->any())
145 ->method(
'buildBaseValidatorConjunction')
146 ->will($this->returnValue($aValidator));
149 $aValidator->addPropertyValidator(
'b', $this->validator);
150 $aValidator->addPropertyValidator(
'integer', $integerValidator);
152 $result = $aValidator->validate($A)->getFlattenedErrors();
153 $this->assertEquals(1221560494,
$result[
'b.0'][0]->getCode());
160 $parentObject = new \TYPO3\CMS\Extbase\Tests\Fixture\Entity(
'Foo');
161 $elementType =
'\TYPO3\CMS\Extbase\Tests\Fixture\Entity';
162 $lazyObjectStorage = new \TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage(
165 array(
'someNotEmptyValue')
170 $validator->expects($this->never())->method(
'isValid');
171 $validator->injectConfigurationManager($this->configurationManager);
172 $this->mockValidatorResolver->expects($this->never())->method(
'createValidator');
180 $entity = new \TYPO3\CMS\Extbase\Tests\Fixture\Entity(
'Foo');
181 $elementType =
'\TYPO3\CMS\Extbase\Tests\Fixture\Entity';
182 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
183 $objectStorage->attach($entity);
184 $aValidator = new \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator(array());
185 $aValidator->injectConfigurationManager($this->configurationManager);
187 $this->mockValidatorResolver->expects($this->never())->method(
'createValidator');
188 $this->mockValidatorResolver->expects($this->once())
189 ->method(
'getBaseValidatorConjunction')
191 ->will($this->returnValue($aValidator));
193 $this->validator->_set(
'options', array(
'elementType' => $elementType));
195 $this->validator->validate($objectStorage);
collectionValidatorCallsCollectionElementValidatorWhenValidatingObjectStorages()
collectionValidatorValidatesEveryElementOfACollectionWithTheGivenElementValidator()
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.
static setProperty(&$subject, $propertyName, $propertyValue, $forceDirectAccess=FALSE)
getValidator(array $options=array(), array $mockedMethods=array('translateErrorMessage'))
collectionValidatorValidatesNestedObjectStructuresWithoutEndlessLooping()
collectionValidatorFailsForAValueNotBeingACollection()
collectionValidatorReturnsNoErrorsForANullValue()
collectionValidatorIsValidEarlyReturnsOnUnitializedLazyObjectStorages()