‪TYPO3CMS  10.4
ValidatorClassNameResolverTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪ValidatorClassNameResolverTest extends UnitTestCase
36 {
41  {
42  $validatorIdentifier = IntegerValidator::class;
43  self::assertSame($validatorIdentifier, ‪ValidatorClassNameResolver::resolve($validatorIdentifier));
44  }
45 
50  {
51  self::assertSame(IntegerValidator::class, ‪ValidatorClassNameResolver::resolve('int'));
52  self::assertSame(BooleanValidator::class, ‪ValidatorClassNameResolver::resolve('bool'));
53  self::assertSame(FloatValidator::class, ‪ValidatorClassNameResolver::resolve('double'));
54  self::assertSame(NumberValidator::class, ‪ValidatorClassNameResolver::resolve('numeric'));
55  self::assertSame(FloatValidator::class, ‪ValidatorClassNameResolver::resolve('float'));
56  }
57 
62  {
63  self::assertSame(IntegerValidator::class, ‪ValidatorClassNameResolver::resolve('TYPO3.CMS.Extbase:Integer'));
64  }
65 
70  {
71  $this->expectExceptionCode(1365799920);
72  $this->expectExceptionMessage('Validator class TYPO3\CMS\Extbase\Validation\Validator\NonExistingValidator does not exist');
73 
74  self::assertSame(IntegerValidator::class, ‪ValidatorClassNameResolver::resolve('NonExisting'));
75  }
76 
81  {
82  $this->expectExceptionCode(1365776838);
83  $this->expectExceptionMessage(sprintf(
84  'Validator class %s must implement %s',
85  ValidatorThatDoesNotImplementValidatorInterfaceValidator::class,
86  ValidatorInterface::class
87  ));
88 
89  self::assertSame(
90  IntegerValidator::class,
91  ‪ValidatorClassNameResolver::resolve(ValidatorThatDoesNotImplementValidatorInterfaceValidator::class)
92  );
93  }
94 
99  {
100  return [
101  'TYPO3.CMS.Extbase:NotEmpty' => [
102  'TYPO3.CMS.Extbase:NotEmpty',
103  NotEmptyValidator::class
104  ],
105  'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:Custom' => [
106  'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:Custom',
107  CustomValidator::class
108  ]
109  ];
110  }
111 
119  public function ‪resolveWithShortHandNotationReturnsValidatorNameIfClassExists(string $validatorName, string $expectedClassName): void
120  {
121  self::assertSame(
122  $expectedClassName,
124  );
125  }
126 
131  {
132  $this->expectException(NoSuchValidatorException::class);
133  $this->expectExceptionCode(1365799920);
134 
135  $validatorName = 'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:NonExistentValidator';
137  }
138 
143  {
144  $this->expectException(NoSuchValidatorException::class);
145  $this->expectExceptionCode(1365776838);
146 
147  $validatorName = 'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:CustomValidatorThatDoesNotImplementValidatorInterface';
149  }
150 
155  {
156  $validatorName = CustomValidator::class;
157  $className = CustomValidator::class;
158 
159  self::assertSame(
160  $className,
162  );
163  }
164 
169  {
170  $validatorName = '\\' . CustomValidator::class;
171  $className = CustomValidator::class;
172 
173  self::assertSame(
174  $className,
176  );
177  }
178 }
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveThrowsExceptionWithValidatorThatDoesNotImplementValidatorInterface
‪resolveThrowsExceptionWithValidatorThatDoesNotImplementValidatorInterface()
Definition: ValidatorClassNameResolverTest.php:142
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\namespacedShorthandValidatorNamesDataProvider
‪array namespacedShorthandValidatorNamesDataProvider()
Definition: ValidatorClassNameResolverTest.php:98
‪TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException
Definition: NoSuchValidatorException.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Fixture\Validation\Validator\CustomValidator
Definition: CustomValidator.php:26
‪TYPO3\CMS\Extbase\Validation\ValidatorClassNameResolver\resolve
‪static string resolve(string $validatorIdentifier)
Definition: ValidatorClassNameResolver.php:46
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest
Definition: ValidatorClassNameResolverTest.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveReturnsValidatorNameForFullQualifiedValidatorNameWithLeadingBackslash
‪resolveReturnsValidatorNameForFullQualifiedValidatorNameWithLeadingBackslash()
Definition: ValidatorClassNameResolverTest.php:168
‪TYPO3\CMS\Extbase\Tests\Unit\Validation
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveResolvesExtensionShorthandIdentifiers
‪resolveResolvesExtensionShorthandIdentifiers()
Definition: ValidatorClassNameResolverTest.php:61
‪TYPO3\CMS\Extbase\Tests\Fixture\ValidatorThatDoesNotImplementValidatorInterfaceValidator
Definition: ValidatorThatDoesNotImplementValidatorInterfaceValidator.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveWithShortHandNotationReturnsValidatorNameIfClassExists
‪resolveWithShortHandNotationReturnsValidatorNameIfClassExists(string $validatorName, string $expectedClassName)
Definition: ValidatorClassNameResolverTest.php:119
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveResolvesFullyQualifiedClassNames
‪resolveResolvesFullyQualifiedClassNames()
Definition: ValidatorClassNameResolverTest.php:40
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveResolvesCoreShorthandIdentifiers
‪resolveResolvesCoreShorthandIdentifiers()
Definition: ValidatorClassNameResolverTest.php:49
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveWithShortHandNotationThrowsExceptionIfClassDoesNotExist
‪resolveWithShortHandNotationThrowsExceptionIfClassDoesNotExist()
Definition: ValidatorClassNameResolverTest.php:130
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveThrowsNoSuchValidatorExceptionDueToClassInheritance
‪resolveThrowsNoSuchValidatorExceptionDueToClassInheritance()
Definition: ValidatorClassNameResolverTest.php:80
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveReturnsValidatorNameForFullQualifiedValidatorName
‪resolveReturnsValidatorNameForFullQualifiedValidatorName()
Definition: ValidatorClassNameResolverTest.php:154
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\FloatValidator
Definition: FloatValidator.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator
Definition: BooleanValidator.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\NumberValidator
Definition: NumberValidator.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator
Definition: IntegerValidator.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\ValidatorClassNameResolverTest\resolveThrowsNoSuchValidatorExceptionDueToMissingClass
‪resolveThrowsNoSuchValidatorExceptionDueToMissingClass()
Definition: ValidatorClassNameResolverTest.php:69
‪TYPO3\CMS\Extbase\Validation\ValidatorClassNameResolver
Definition: ValidatorClassNameResolver.php:28