Пример #1
0
 /**
  * @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'));
 }
 /**
  * @test
  */
 public function validatorConjunctionReturnsErrorsIfOneValidatorReturnsErrors()
 {
     $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator(array());
     $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
     $errors = new \TYPO3\CMS\Extbase\Error\Result();
     $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
     $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
     $validatorConjunction->addValidator($validatorObject);
     $this->assertTrue($validatorConjunction->validate('some subject')->hasErrors());
 }
 /**
  * @test
  */
 public function findFirstError()
 {
     /*
      * Root
      * 	- A
      * 	- B
      * 		- C (With Error)
      */
     $rootResult = new \TYPO3\CMS\Extbase\Error\Result();
     $rootResult->forProperty('A');
     $rootResult->forProperty('B')->forProperty('C')->addError(new \TYPO3\CMS\Extbase\Error\Error('Fehler', 123456));
     $foundError = $this->controller->_call('findFirstError', $rootResult);
     /** @var \TYPO3\CMS\Extbase\Error\Error $foundError */
     $this->assertInstanceOf('\\TYPO3\\CMS\\Extbase\\Error\\Error', $foundError);
     $this->assertEquals(123456, $foundError->getCode());
 }
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors()
 {
     $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
     $error1 = new \TYPO3\CMS\Extbase\Error\Error('Error', 123);
     $error2 = new \TYPO3\CMS\Extbase\Error\Error('Error2', 123);
     $errors1 = new \TYPO3\CMS\Extbase\Error\Result();
     $errors1->addError($error1);
     $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
     $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
     $errors2 = new \TYPO3\CMS\Extbase\Error\Result();
     $errors2->addError($error2);
     $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
     $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
     $validatorDisjunction->addValidator($validatorObject);
     $validatorDisjunction->addValidator($secondValidatorObject);
     $this->assertEquals(array($error1, $error2), $validatorDisjunction->validate('some subject')->getErrors());
 }
 /**
  * @test
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function validateDetectsFailuresInRecursiveTargetsII()
 {
     $classNameA = $this->getUniqueId('A');
     eval('class ' . $classNameA . '{ public $b; public $uuid = 0xF; }');
     $classNameB = $this->getUniqueId('B');
     eval('class ' . $classNameB . '{ public $a; public $uuid = 0xF; }');
     $A = new $classNameA();
     $B = new $classNameB();
     $A->b = $B;
     $B->a = $A;
     $aValidator = $this->getValidator();
     $bValidator = $this->getValidator();
     $aValidator->injectConfigurationManager($this->configurationManager);
     $bValidator->injectConfigurationManager($this->configurationManager);
     $aValidator->addPropertyValidator('b', $bValidator);
     $bValidator->addPropertyValidator('a', $aValidator);
     $error1 = new \TYPO3\CMS\Extbase\Error\Error('error1', 123);
     $result1 = new \TYPO3\CMS\Extbase\Error\Result();
     $result1->addError($error1);
     $mockUuidValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
     $mockUuidValidator->expects($this->any())->method('validate')->with(15)->will($this->returnValue($result1));
     $aValidator->addPropertyValidator('uuid', $mockUuidValidator);
     $bValidator->addPropertyValidator('uuid', $mockUuidValidator);
     $this->assertSame(array('b.uuid' => array($error1), 'uuid' => array($error1)), $aValidator->validate($A)->getFlattenedErrors());
 }
Пример #6
0
 /**
  * @test
  */
 public function mergeShouldMergeTwoResults()
 {
     $notice1 = $this->getMockMessage('Notice');
     $notice2 = $this->getMockMessage('Notice');
     $notice3 = $this->getMockMessage('Notice');
     $warning1 = $this->getMockMessage('Warning');
     $warning2 = $this->getMockMessage('Warning');
     $warning3 = $this->getMockMessage('Warning');
     $error1 = $this->getMockMessage('Error');
     $error2 = $this->getMockMessage('Error');
     $error3 = $this->getMockMessage('Error');
     $otherResult = new \TYPO3\CMS\Extbase\Error\Result();
     $otherResult->addNotice($notice1);
     $otherResult->forProperty('foo.bar')->addNotice($notice2);
     $this->result->forProperty('foo')->addNotice($notice3);
     $otherResult->addWarning($warning1);
     $this->result->addWarning($warning2);
     $this->result->addWarning($warning3);
     $otherResult->forProperty('foo')->addError($error1);
     $otherResult->forProperty('foo')->addError($error2);
     $otherResult->addError($error3);
     $this->result->merge($otherResult);
     $this->assertSame(array($notice1), $this->result->getNotices(), 'Notices are not merged correctly without recursion');
     $this->assertSame(array($notice3), $this->result->forProperty('foo')->getNotices(), 'Original sub-notices are overridden.');
     $this->assertSame(array($notice2), $this->result->forProperty('foo')->forProperty('bar')->getNotices(), 'Sub-notices are not copied.');
     $this->assertSame(array($warning2, $warning3, $warning1), $this->result->getWarnings());
     $this->assertSame(array($error3), $this->result->getErrors());
     $this->assertSame(array($error1, $error2), $this->result->forProperty('foo')->getErrors());
 }
Пример #7
0
 /**
  * Get all property mapping / validation errors
  *
  * @return \TYPO3\CMS\Extbase\Error\Result
  */
 public function getValidationResults()
 {
     $results = new \TYPO3\CMS\Extbase\Error\Result();
     /** @var Argument $argument */
     foreach ($this as $argument) {
         $argumentValidationResults = $argument->getValidationResults();
         if ($argumentValidationResults === null) {
             continue;
         }
         $results->forProperty($argument->getName())->merge($argumentValidationResults);
     }
     return $results;
 }
Пример #8
0
 /**
  * @test
  * @author Sebastian Kurfürst <*****@*****.**>
  */
 public function setValueShouldSetValidationErrorsIfValidatorIsSetAndValidationFailed()
 {
     $error = new \TYPO3\CMS\Extbase\Error\Error('Some Error', 1234);
     $mockValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate', 'getOptions'));
     $validationMessages = new \TYPO3\CMS\Extbase\Error\Result();
     $validationMessages->addError($error);
     $mockValidator->expects($this->once())->method('validate')->with('convertedValue')->will($this->returnValue($validationMessages));
     $this->simpleValueArgument->setValidator($mockValidator);
     $this->setupPropertyMapperAndSetValue();
     $this->assertFalse($this->simpleValueArgument->isValid());
     $this->assertEquals(array($error), $this->simpleValueArgument->getValidationResults()->getErrors());
 }
Пример #9
0
 /**
  * Validate object
  *
  * @param mixed $object
  *
  * @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException
  * @throws \InvalidArgumentException
  * @return boolean|\TYPO3\CMS\Extbase\Error\Result
  */
 public function validate($object)
 {
     $messages = new \TYPO3\CMS\Extbase\Error\Result();
     if (self::$instancesCurrentlyUnderValidation === null) {
         self::$instancesCurrentlyUnderValidation = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     }
     if ($object === null) {
         return $messages;
     }
     if (!$this->canValidate($object)) {
         /** @var \TYPO3\CMS\Extbase\Error\Error $error */
         $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Error\\Error', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_notvalidatable', 'StoreFinder'), 1301599551);
         $messages->addError($error);
         return $messages;
     }
     if (self::$instancesCurrentlyUnderValidation->contains($object)) {
         return $messages;
     } else {
         self::$instancesCurrentlyUnderValidation->attach($object);
     }
     $this->model = $object;
     $propertyValidators = $this->getValidationRulesFromSettings();
     foreach ($propertyValidators as $propertyName => $validatorsNames) {
         if (!property_exists($object, $propertyName)) {
             /** @var \TYPO3\CMS\Extbase\Error\Error $error */
             $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Error\\Error', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_notexists', 'StoreFinder'), 1301599575);
             $messages->addError($error);
         } else {
             $this->currentPropertyName = $propertyName;
             $propertyValue = $this->getPropertyValue($object, $propertyName);
             $this->checkProperty($propertyValue, (array) $validatorsNames, $messages->forProperty($propertyName));
         }
     }
     self::$instancesCurrentlyUnderValidation->detach($object);
     return $messages;
 }