/** * This adds custom validators to the passed $conjunctionValidator. * * A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and * append 'Validator'". If found, it will be added to the $conjunctionValidator. * * In addition canValidate() will be called on all implementations of the ObjectValidatorInterface to find * all validators that could validate the target. The one with the highest priority will be added as well. * If multiple validators have the same priority, which one will be added is not deterministic. * * @param string $targetClassName * @param ConjunctionValidator $conjunctionValidator * @return NULL|Validator\ObjectValidatorInterface */ protected function addCustomValidators($targetClassName, ConjunctionValidator &$conjunctionValidator) { $addedValidatorClassName = NULL; // @todo: get rid of ClassNamingUtility usage once we dropped underscored class name support $possibleValidatorClassName = ClassNamingUtility::translateModelNameToValidatorName($targetClassName); $customValidator = $this->createValidator($possibleValidatorClassName); if ($customValidator !== NULL) { $conjunctionValidator->addValidator($customValidator); $addedValidatorClassName = get_class($customValidator); } // @todo: find polytype validator for class }
/** * @dataProvider repositoryAndModelClassNames * @param string $repositoryName * @param string $modelName * @param string $expectedValidatorName * @test */ public function translateModelNameToValidatorName($repositoryName, $modelName, $expectedValidatorName) { $translatedModelName = \TYPO3\CMS\Core\Utility\ClassNamingUtility::translateModelNameToValidatorName($modelName); $this->assertSame($expectedValidatorName, $translatedModelName); }