/**
  * @test
  */
 public function validateAddsErrorForMissingReservation()
 {
     $participant = new Person();
     $participant->setType(Person::PERSON_TYPE_PARTICIPANT);
     $expectedResult = new Result();
     $expectedError = new Error('Missing reservation.', 1465389725);
     $expectedResult->addError($expectedError);
     $this->assertEquals($expectedResult, $this->subject->validate($participant));
 }
 /**
  * @param Result $result
  * @return array
  */
 protected function getErrorMessages(Result $result)
 {
     $messages = array();
     /** @var Error $error */
     foreach ($result->getErrors() as $error) {
         $messages[] = htmlspecialchars(LocalizationUtility::translate('formError.' . $error->getCode(), 'BiMarketplace') ?: $error->getMessage());
     }
     return $messages;
 }
 /**
  * Add errors and set validstate to false
  *
  * @param Result $result
  * @return void
  */
 protected function addErrors(Result $result)
 {
     $errors = $result->getErrors();
     if (!empty($errors)) {
         /** @var Error $error */
         foreach ($errors as $error) {
             $this->addError($error->getMessage(), $error->getCode());
         }
         $this->setValidState(false);
     }
 }
예제 #4
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());
 }
예제 #5
0
 /**
  * Sets the notices cache to TRUE and propagates the information
  * upwards the Result-Object Tree
  *
  * @return void
  */
 protected function setNoticesExist()
 {
     $this->noticesExist = TRUE;
     if ($this->parent !== NULL) {
         $this->parent->setNoticesExist();
     }
 }
예제 #6
0
 /**
  * Sets the notices cache to TRUE and propagates the information
  * upwards the Result-Object Tree
  *
  * @return void
  */
 protected function setNoticesExist()
 {
     $this->noticesExist = true;
     if ($this->parent !== null) {
         $this->parent->setNoticesExist();
     }
 }
예제 #7
0
 /**
  * Creates a new validation error object and adds it to $this->errors
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @param array $arguments Arguments to be replaced in message
  * @param string $title title of the error
  * @return void
  */
 protected function addError($message, $code, array $arguments = array(), $title = '')
 {
     if ($this->result !== NULL) {
         // backwards compatibility before Extbase 1.4.0: we cannot expect the "result" object to be there.
         $this->result->addError(new \TYPO3\CMS\Extbase\Validation\Error($message, $code, $arguments, $title));
     }
     // the following is @deprecated since Extbase 1.4.0:
     $this->errors[] = new \TYPO3\CMS\Extbase\Validation\Error($message, $code, $arguments, $title);
 }
예제 #8
0
 /**
  * Add an error with message and code to the property errors
  *
  * @param string $propertyName name of the property to add the error to
  * @param string $message Message to be shwon
  * @param string $code Error code to identify the error
  * @return void
  */
 protected function ___addErrorForProperty($propertyName, $message, $code)
 {
     if (!$this->result->forProperty($propertyName)->hasErrors()) {
         /** @var $error \TYPO3\CMS\Extbase\Validation\PropertyError */
         $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Validation\\PropertyError', $propertyName);
         $error->addErrors(array($this->objectManager->get('TYPO3\\CMS\\Extbase\\Validation\\Error', $message, $code)));
         $this->result->addError($error);
     }
 }
예제 #9
0
 /**
  * Validation process
  *
  * @param Mail $mail
  * @return Result
  */
 public function validate($mail)
 {
     $this->emailFieldMarkerArray = GeneralUtility::trimExplode(',', $this->configuration['emailMarker'], true);
     $this->confirmEmailFieldMarkerArray = GeneralUtility::trimExplode(',', $this->configuration['emailConfirmMarker'], true);
     $result = new Result();
     foreach ($mail->getAnswers() as $answer) {
         if (in_array($answer->getField()->getMarker(), $this->emailFieldMarkerArray)) {
             $emailMarker = $answer->getField()->getMarker();
             $email = $answer->getValue();
         }
         if (in_array($answer->getField()->getMarker(), $this->confirmEmailFieldMarkerArray)) {
             $confirmEmailMarker = $answer->getField()->getMarker();
             $confirmEmail = $answer->getValue();
         }
     }
     if ($email && $confirmEmail && $emailMarker && $confirmEmailMarker && $email !== $confirmEmail) {
         $result->addError(new Error(LocalizationUtility::translate('validation_email_match', 't3ecom'), $confirmEmailMarker));
         $result->addError(new Error(LocalizationUtility::translate('validation_email_match', 't3ecom'), $emailMarker));
     }
     return $result;
 }
예제 #10
0
 public function createFile(array $sourceData, $propertyPath, $allowedTypes, $maxSize)
 {
     $this->messages = new \TYPO3\CMS\Extbase\Error\Result();
     $this->propertyPath = $propertyPath;
     $key = $propertyPath ? $propertyPath : '';
     $this->settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
     $uploadedFileData = $this->getUploadedFileData();
     $this->handleUploadErrors($uploadedFileData);
     if ($this->messages->hasErrors()) {
         $this->fileRepository->clearHeld($key);
         return $this->messages->getFirstError();
     } else {
         if (!$this->settings['file']['dontValidateType']) {
             $this->validateType($uploadedFileData, $allowedTypes);
         }
         if (!$this->settings['file']['dontValidateName']) {
             $this->validateName($uploadedFileData);
         }
         if (!$this->settings['file']['dontValidateSize']) {
             $this->validateSize($uploadedFileData, $maxSize);
         }
     }
     if ($this->messages->hasErrors()) {
         $this->fileRepository->clearHeld($key);
         return $this->messages->getFirstError();
     } else {
         // ok to make a file object
         $pathInfo = pathinfo($uploadedFileData['tmp_name']);
         $fileObject = $this->objectManager->create('CIC\\Cicbase\\Domain\\Model\\File');
         $fileObject->setTitle($sourceData['title']);
         // TODO: Set a default title if it's not provided.
         $fileObject->setDescription($sourceData['description']);
         $fileObject->setIsSaved(false);
         $fileObject->setOwner($GLOBALS['TSFE']->fe_user->user['uid']);
         $fileObject->setSize($uploadedFileData['size']);
         $fileObject->setMimeType($uploadedFileData['type']);
         $fileObject->setOriginalFilename($uploadedFileData['name']);
         $fileObject->setPath($uploadedFileData['tmp_name']);
         $fileObject->setFilename($pathInfo['filename']);
         $fileObject->setCrdate(time());
         $results = $this->fileRepository->hold($fileObject, $key);
         return $results;
     }
 }
예제 #11
0
 /**
  * Internal function which actually does the property mapping.
  *
  * @param mixed $source the source data to map. MUST be a simple type, NO object allowed!
  * @param string $targetType The type of the target; can be either a class name or a simple type.
  * @param PropertyMappingConfigurationInterface $configuration Configuration for the property mapping.
  * @param array &$currentPropertyPath The property path currently being mapped; used for knowing the context in case an exception is thrown.
  * @throws Exception\TypeConverterException
  * @throws Exception\InvalidPropertyMappingConfigurationException
  * @return mixed an instance of $targetType
  */
 protected function doMapping($source, $targetType, PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath)
 {
     if (is_object($source)) {
         $targetType = $this->parseCompositeType($targetType);
         if ($source instanceof $targetType) {
             return $source;
         }
     }
     if ($source === null) {
         $source = '';
     }
     $typeConverter = $this->findTypeConverter($source, $targetType, $configuration);
     $targetType = $typeConverter->getTargetTypeForSource($source, $targetType, $configuration);
     if (!is_object($typeConverter) || !$typeConverter instanceof \TYPO3\CMS\Extbase\Property\TypeConverterInterface) {
         throw new Exception\TypeConverterException('Type converter for "' . $source . '" -> "' . $targetType . '" not found.');
     }
     $convertedChildProperties = array();
     foreach ($typeConverter->getSourceChildPropertiesToBeConverted($source) as $sourcePropertyName => $sourcePropertyValue) {
         $targetPropertyName = $configuration->getTargetPropertyName($sourcePropertyName);
         if ($configuration->shouldSkip($targetPropertyName)) {
             continue;
         }
         if (!$configuration->shouldMap($targetPropertyName)) {
             if ($configuration->shouldSkipUnknownProperties()) {
                 continue;
             }
             throw new Exception\InvalidPropertyMappingConfigurationException('It is not allowed to map property "' . $targetPropertyName . '". You need to use $propertyMappingConfiguration->allowProperties(\'' . $targetPropertyName . '\') to enable mapping of this property.', 1355155913);
         }
         $targetPropertyType = $typeConverter->getTypeOfChildProperty($targetType, $targetPropertyName, $configuration);
         $subConfiguration = $configuration->getConfigurationFor($targetPropertyName);
         $currentPropertyPath[] = $targetPropertyName;
         $targetPropertyValue = $this->doMapping($sourcePropertyValue, $targetPropertyType, $subConfiguration, $currentPropertyPath);
         array_pop($currentPropertyPath);
         if (!$targetPropertyValue instanceof \TYPO3\CMS\Extbase\Error\Error) {
             $convertedChildProperties[$targetPropertyName] = $targetPropertyValue;
         }
     }
     $result = $typeConverter->convertFrom($source, $targetType, $convertedChildProperties, $configuration);
     if ($result instanceof \TYPO3\CMS\Extbase\Error\Error) {
         $this->messages->forProperty(implode('.', $currentPropertyPath))->addError($result);
     }
     return $result;
 }
예제 #12
0
 /**
  * @return boolean TRUE if the argument is valid, FALSE otherwise
  * @api
  */
 public function isValid()
 {
     return !$this->validationResults->hasErrors();
 }
예제 #13
0
 /**
  * Creates a new validation error object and adds it to $this->results
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @param array $arguments Arguments to be replaced in message
  * @param string $title title of the error
  * @return void
  */
 protected function addError($message, $code, array $arguments = array(), $title = '')
 {
     $this->result->addError(new \TYPO3\CMS\Extbase\Validation\Error($message, $code, $arguments, $title));
 }
예제 #14
0
 /**
  * Checks if the specified property of the given object is valid, and adds
  * found errors to the $messages object.
  *
  * @param mixed $value The value to be validated
  * @param array $validatorNames Contains an array with validator names
  * @param \TYPO3\CMS\Extbase\Error\Result $messages the result object to
  *        which the validation errors should be added
  *
  * @return void
  */
 protected function checkProperty($value, $validatorNames, \TYPO3\CMS\Extbase\Error\Result $messages)
 {
     foreach ($validatorNames as $validatorName) {
         $messages->merge($this->getValidator($validatorName)->validate($value));
     }
 }
예제 #15
0
 /**
  * @param \TYPO3\CMS\Extbase\Error\Result $validationResult
  * @return Error
  */
 protected function findFirstError(\TYPO3\CMS\Extbase\Error\Result $validationResult)
 {
     $error = $validationResult->getFirstError();
     if ($error instanceof Error) {
         return $error;
     }
     foreach ($validationResult->getSubResults() as $argumentName => $subValidationResult) {
         /** @var $subValidationResult \TYPO3\CMS\Extbase\Error\Result */
         $error = $this->findFirstError($subValidationResult);
         if ($error instanceof Error) {
             return $error;
         }
     }
 }