Example #1
0
 /**
  * Test for getValuesBeforeBrackets()
  *
  * @param string $start
  * @param string $expectedResult
  * @return void
  * @dataProvider getValuesBeforeBracketsDataProvider
  * @test
  */
 public function getValuesBeforeBracketsReturnsString($start, $expectedResult)
 {
     $result = StringUtility::getValuesBeforeBrackets($start);
     $this->assertEquals($result, $expectedResult);
 }
Example #2
0
 /**
  * Validate Field
  *
  * @return bool
  */
 public function validateField()
 {
     $validationSettings = GeneralUtility::trimExplode(',', $this->validationSettingsString, true);
     $validationSettings = str_replace('|', ',', $validationSettings);
     foreach ($validationSettings as $validationSetting) {
         switch ($validationSetting) {
             case 'required':
                 if (!$this->validateRequired($this->getValue())) {
                     $this->addMessage('validationErrorRequired');
                     $this->isValid = false;
                 }
                 break;
             case 'email':
                 if ($this->getValue() && !$this->validateEmail($this->getValue())) {
                     $this->addMessage('validationErrorEmail');
                     $this->isValid = false;
                 }
                 break;
             case stristr($validationSetting, 'min('):
                 if ($this->getValue() && !$this->validateMin($this->getValue(), StringUtility::getValuesInBrackets($validationSetting))) {
                     $this->addMessage('validationErrorMin');
                     $this->isValid = false;
                 }
                 break;
             case stristr($validationSetting, 'max('):
                 if ($this->getValue() && !$this->validateMax($this->getValue(), StringUtility::getValuesInBrackets($validationSetting))) {
                     $this->addMessage('validationErrorMax');
                     $this->isValid = false;
                 }
                 break;
             case 'intOnly':
                 if ($this->getValue() && !$this->validateInt($this->getValue())) {
                     $this->addMessage('validationErrorInt');
                     $this->isValid = false;
                 }
                 break;
             case 'lettersOnly':
                 if ($this->getValue() && !$this->validateLetters($this->getValue())) {
                     $this->addMessage('validationErrorLetters');
                     $this->isValid = false;
                 }
                 break;
             case 'uniqueInPage':
                 if ($this->getValue() && !$this->validateUniquePage($this->getValue(), $this->getFieldName(), $this->getUser())) {
                     $this->addMessage('validationErrorUniquePage');
                     $this->isValid = false;
                 }
                 break;
             case 'uniqueInDb':
                 if ($this->getValue() && !$this->validateUniqueDb($this->getValue(), $this->getFieldName(), $this->getUser())) {
                     $this->addMessage('validationErrorUniqueDb');
                     $this->isValid = false;
                 }
                 break;
             case stristr($validationSetting, 'mustInclude('):
                 if ($this->getValue() && !$this->validateMustInclude($this->getValue(), StringUtility::getValuesInBrackets($validationSetting))) {
                     $this->addMessage('validationErrorMustInclude');
                     $this->isValid = false;
                 }
                 break;
             case stristr($validationSetting, 'mustNotInclude('):
                 if ($this->getValue() && !$this->validateMustNotInclude($this->getValue(), StringUtility::getValuesInBrackets($validationSetting))) {
                     $this->addMessage('validationErrorMustNotInclude');
                     $this->isValid = false;
                 }
                 break;
             case stristr($validationSetting, 'inList('):
                 if (!$this->validateInList($this->getValue(), StringUtility::getValuesInBrackets($validationSetting))) {
                     $this->addMessage('validationErrorInList');
                     $this->isValid = false;
                 }
                 break;
             case stristr($validationSetting, 'sameAs('):
                 if (!$this->validateSameAs($this->getValue(), $this->getAdditionalValue())) {
                     $this->addMessage('validationErrorSameAs');
                     $this->isValid = false;
                 }
                 break;
             case 'date':
                 if ($this->getValue() && !$this->validateDate($this->getValue(), LocalizationUtility::translate('tx_femanager_domain_model_user.dateFormat'))) {
                     $this->addMessage('validationErrorDate');
                     $this->isValid = false;
                 }
                 break;
             default:
                 // e.g. search for method validateCustom()
                 $mainSetting = StringUtility::getValuesBeforeBrackets($validationSetting);
                 if (method_exists($this, 'validate' . ucfirst($mainSetting))) {
                     if (!$this->{'validate' . ucfirst($mainSetting)}($this->getValue(), StringUtility::getValuesInBrackets($validationSetting))) {
                         $this->addMessage('validationError' . ucfirst($mainSetting));
                         $this->isValid = false;
                     }
                 }
         }
     }
     return $this->isValid;
 }