/** * Validate Field * * @return bool */ public function validateField() { $validationSettings = GeneralUtility::trimExplode(',', $this->validationSettingsString, 1); $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(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMin'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'max('): if ($this->getValue() && !$this->validateMax($this->getValue(), Div::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(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMustInclude'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'mustNotInclude('): if ($this->getValue() && !$this->validateMustNotInclude($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMustNotInclude'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'inList('): if (!$this->validateInList($this->getValue(), Div::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', 'femanager'))) { $this->addMessage('validationErrorDate'); $this->isValid = FALSE; } break; default: // e.g. search for method validateCustom() if (method_exists($this, 'validate' . ucfirst(Div::getValuesBeforeBrackets($validationSetting)))) { if (!$this->{'validate' . ucfirst(Div::getValuesBeforeBrackets($validationSetting))}($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationError' . ucfirst(Div::getValuesBeforeBrackets($validationSetting))); $this->isValid = FALSE; } } } } return $this->isValid; }
/** * Test for getValuesBeforeBrackets() * * @param \string $start * @param \string $expectedResult * @return void * @dataProvider getValuesBeforeBracketsDataProvider * @test */ public function getValuesBeforeBracketsReturnsString($start, $expectedResult) { $result = \In2\Femanager\Utility\Div::getValuesBeforeBrackets($start); $this->assertEquals($result, $expectedResult); }