/**
  * @test
  */
 public function validatorConjunctionReturnsErrorsIfOneValidatorReturnsErrors()
 {
     $validatorConjunction = new \TYPO3\Flow\Validation\Validator\ConjunctionValidator(array());
     $validatorObject = $this->getMock(\TYPO3\Flow\Validation\Validator\ValidatorInterface::class);
     $errors = new \TYPO3\Flow\Error\Result();
     $errors->addError(new \TYPO3\Flow\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 validateReturnsAllErrorsIfAllValidatorsReturnErrrors()
 {
     $validatorDisjunction = new \TYPO3\Flow\Validation\Validator\DisjunctionValidator(array());
     $error1 = new \TYPO3\Flow\Error\Error('Error', 123);
     $error2 = new \TYPO3\Flow\Error\Error('Error2', 123);
     $errors1 = new \TYPO3\Flow\Error\Result();
     $errors1->addError($error1);
     $validatorObject = $this->getMock(\TYPO3\Flow\Validation\Validator\ValidatorInterface::class);
     $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
     $errors2 = new \TYPO3\Flow\Error\Result();
     $errors2->addError($error2);
     $secondValidatorObject = $this->getMock(\TYPO3\Flow\Validation\Validator\ValidatorInterface::class);
     $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
  */
 public function validateDetectsFailuresInRecursiveTargetsII()
 {
     $classNameA = 'A' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameA . '{ public $b; public $uuid = 0xF; }');
     $classNameB = 'B' . md5(uniqid(mt_rand(), true));
     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->addPropertyValidator('b', $bValidator);
     $bValidator->addPropertyValidator('a', $aValidator);
     $error1 = new \TYPO3\Flow\Error\Error('error1', 123);
     $result1 = new \TYPO3\Flow\Error\Result();
     $result1->addError($error1);
     $mockUuidValidator = $this->getMock(\TYPO3\Flow\Validation\Validator\ValidatorInterface::class);
     $mockUuidValidator->expects($this->any())->method('validate')->with(0xf)->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());
 }
 /**
  * @test
  */
 public function setValueShouldSetValidationErrorsIfValidatorIsSetAndValidationFailed()
 {
     $error = new \TYPO3\Flow\Error\Error('Some Error', 1234);
     $mockValidator = $this->getMock(\TYPO3\Flow\Validation\Validator\ValidatorInterface::class);
     $validationMessages = new \TYPO3\Flow\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());
 }
 /**
  * Validate a null value with the given schema
  *
  * @param mixed $value
  * @param array $schema
  * @return \TYPO3\Flow\Error\Result
  */
 protected function validateNullType($value, array $schema)
 {
     $result = new \TYPO3\Flow\Error\Result();
     if ($value !== null) {
         $result->addError($this->createError('type=NULL', 'type=' . gettype($value)));
     }
     return $result;
 }
 /**
  * @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\Flow\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());
 }
Esempio n. 7
0
 /**
  * @param string $firstname
  * @param string $lastname
  * @param string $email
  * @param string $username
  * @param string $password
  * @return \TYPO3\Flow\Error\Result
  */
 public function addUser($firstname, $lastname, $email, $username, $password)
 {
     $result = new \TYPO3\Flow\Error\Result();
     try {
         $userData = ['name' => $username, 'first-name' => $firstname, 'last-name' => $lastname, 'email' => $email, 'password' => ['value' => $password], 'active' => TRUE];
         $uri = rtrim($this->crowdBaseUri, '/') . '/rest/usermanagement/1/user';
         $response = $this->httpClient->post($uri, array('body' => json_encode($userData)));
         $responseData = json_decode($response->getBody()->getContents(), TRUE);
         // TODO Check response data?
     } catch (ClientException $e) {
         $responseError = json_decode($e->getResponse()->getBody()->getContents());
         if (isset($responseError->reason)) {
             switch ($responseError->reason) {
                 case 'INVALID_USER':
                     $result->addError(new \TYPO3\Flow\Error\Error($responseError->message));
                     return $result;
             }
         }
         $userData['password']['value'] = '********';
         $this->systemLogger->logException($e, array('uri' => $uri, 'requestData' => $userData, 'responseStatus' => $e->getResponse()->getStatusCode(), 'responseBody' => $e->getResponse()->getBody()->getContents()));
         $result->addError(new \TYPO3\Flow\Error\Error('There was an unspecified error'));
     }
     return $result;
 }
 /**
  * @test
  */
 public function getValidationResultsShouldFetchAllValidationResltsFromArguments()
 {
     $error1 = new \TYPO3\Flow\Error\Error('Validation error', 1234);
     $error2 = new \TYPO3\Flow\Error\Error('Validation error 2', 1235);
     $results1 = new \TYPO3\Flow\Error\Result();
     $results1->addError($error1);
     $results2 = new \TYPO3\Flow\Error\Result();
     $results2->addError($error2);
     $argument1 = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\Argument', array('getValidationResults'), array('name1', 'string'));
     $argument1->expects($this->once())->method('getValidationResults')->will($this->returnValue($results1));
     $argument2 = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\Argument', array('getValidationResults'), array('name2', 'string'));
     $argument2->expects($this->once())->method('getValidationResults')->will($this->returnValue($results2));
     $arguments = new \TYPO3\Flow\Mvc\Controller\Arguments();
     $arguments->addArgument($argument1);
     $arguments->addArgument($argument2);
     $this->assertSame(array('name1' => array($error1), 'name2' => array($error2)), $arguments->getValidationResults()->getFlattenedErrors());
 }