/** * @test */ public function numberValidatorReturnsFalseForAString() { $expectedResult = new \TYPO3\CMS\Extbase\Error\Result(); // we only test for the error code, after the message translation method is mocked $expectedResult->addError(new \TYPO3\CMS\Extbase\Validation\Error(NULL, 1221563685)); $this->assertEquals($expectedResult, $this->validator->validate('not a number')); }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Property\Exception */ public function setValue($rawValue) { if ($rawValue === null) { $this->value = null; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } try { $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); } catch (TargetNotFoundException $e) { // for optional arguments no exeption is thrown. if ($this->isRequired()) { throw $e; } } $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== null) { // @todo Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; }
/** * @test */ public function collectionValidatorCallsCollectionElementValidatorWhenValidatingObjectStorages() { $entity = new \TYPO3\CMS\Extbase\Tests\Fixture\Entity('Foo'); $elementType = \TYPO3\CMS\Extbase\Tests\Fixture\Entity::class; $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorage->attach($entity); $aValidator = new \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator(array()); $this->mockValidatorResolver->expects($this->never())->method('createValidator'); $this->mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with($elementType)->will($this->returnValue($aValidator)); $this->validator->_set('options', array('elementType' => $elementType)); $this->validator->validate($objectStorage); }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException if the argument is not a valid object of type $dataType */ public function setValue($rawValue) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { // TODO: Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException if the argument is not a valid object of type $dataType */ public function setValue($rawValue) { if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { // TODO: Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; } else { if ($rawValue === NULL || is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; } else { $this->value = $this->transformValue($rawValue); } return $this; } }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Property\Exception */ public function setValue($rawValue) { if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } try { $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); } catch (TargetNotFoundException $e) { // for optional arguments no exeption is thrown. if ($this->isRequired()) { throw $e; } } $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { // TODO: Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; } else { if ($rawValue === NULL || is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; } else { $this->value = $this->transformValue($rawValue); } return $this; } }