‪TYPO3CMS  9.5
ValidatorResolverTest.php
Go to the documentation of this file.
1 <?php
2 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 
28 
32 class ‪ValidatorResolverTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
33 {
37  private ‪$validatorResolver;
38 
39  protected function ‪setUp()
40  {
41  parent::setUp();
42 
43  $this->validatorResolver = $this->getAccessibleMock(
44  ValidatorResolver::class,
45  ['dummy']
46  );
47  $this->validatorResolver->injectObjectManager(GeneralUtility::makeInstance(ObjectManager::class));
48  $this->validatorResolver->injectReflectionService(GeneralUtility::makeInstance(ReflectionService::class));
49  }
50 
55  {
56  return [
57  'TYPO3.CMS.Extbase:NotEmpty' => [
58  'TYPO3.CMS.Extbase:NotEmpty',
59  NotEmptyValidator::class
60  ],
61  'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:Custom' => [
62  'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:Custom',
63  Fixture\Validation\Validator\CustomValidator::class
64  ]
65  ];
66  }
67 
75  public function ‪resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExists(string $validatorName, string $expectedClassName)
76  {
77  static::assertEquals(
78  $expectedClassName,
79  $this->validatorResolver->_call('resolveValidatorObjectName', $validatorName)
80  );
81  }
82 
87  {
88  $this->expectException(NoSuchValidatorException::class);
89  $this->expectExceptionCode(1365799920);
90 
91  $validatorName = 'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:NonExistentValidator';
92  $this->validatorResolver->_call('resolveValidatorObjectName', $validatorName);
93  }
94 
99  {
100  $this->expectException(NoSuchValidatorException::class);
101  $this->expectExceptionCode(1365776838);
102 
103  $validatorName = 'TYPO3.CMS.Extbase.Tests.Functional.Validation.Fixture:CustomValidatorThatDoesNotImplementValidatorInterface';
104  $this->validatorResolver->_call('resolveValidatorObjectName', $validatorName);
105  }
106 
111  {
112  $validatorName = Fixture\Validation\Validator\CustomValidator::class;
113  $className = Fixture\Validation\Validator\CustomValidator::class;
114 
115  static::assertEquals(
116  $className,
117  $this->validatorResolver->_call('resolveValidatorObjectName', $validatorName)
118  );
119  }
120 
125  {
126  $validatorName = '\\' . Fixture\Validation\Validator\CustomValidator::class;
127  $className = Fixture\Validation\Validator\CustomValidator::class;
128 
129  static::assertEquals(
130  $className,
131  $this->validatorResolver->_call('resolveValidatorObjectName', $validatorName)
132  );
133  }
134 
139  {
140  $className = $this->getUniqueId('Foo\\Bar');
141  $this->expectException(NoSuchValidatorException::class);
142  $this->expectExceptionCode(1365799920);
143  $this->validatorResolver->_call('resolveValidatorObjectName', $className);
144  }
145 
150  {
151  $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(Fixture\Controller\TestController::class);
152  $result = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions(
153  $controller,
154  'noParamsAction'
155  );
156 
157  static::assertSame([], $result);
158  }
159 
164  {
165  $this->validatorResolver->_call(
166  'buildBaseValidatorConjunction',
167  \‪TYPO3\CMS\‪Extbase\Tests\Functional\Validation\Fixture\Domain\Model\Model::class,
168  \‪TYPO3\CMS\‪Extbase\Tests\Functional\Validation\Fixture\Domain\Model\Model::class
169  );
170 
172  $baseValidatorConjunctions = $this->validatorResolver->_get('baseValidatorConjunctions');
173  static::assertTrue(is_array($baseValidatorConjunctions));
174  static::assertCount(2, $baseValidatorConjunctions);
175  static::assertArrayHasKey(\‪TYPO3\CMS\‪Extbase\Tests\Functional\Validation\Fixture\Domain\Model\Model::class, $baseValidatorConjunctions);
176  static::assertArrayHasKey(\‪TYPO3\CMS\‪Extbase\Tests\Functional\Validation\Fixture\Domain\Model\AnotherModel::class, $baseValidatorConjunctions);
177 
179  $conjunctionValidator = $baseValidatorConjunctions[\TYPO3\CMS\Extbase\Tests\Functional\Validation\Fixture\Domain\Model\Model::class];
180  static::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
181 
182  $baseValidators = $conjunctionValidator->getValidators();
183  static::assertInstanceOf(\SplObjectStorage::class, $baseValidators);
184  $baseValidators->rewind();
185 
187  ‪$validator = $baseValidators->current();
188  static::assertInstanceOf(GenericObjectValidator::class, ‪$validator);
189 
190  $propertyValidators = ‪$validator->getPropertyValidators();
191  static::assertCount(4, $propertyValidators);
192  static::assertArrayHasKey('foo', $propertyValidators);
193  static::assertArrayHasKey('bar', $propertyValidators);
194  static::assertArrayHasKey('baz', $propertyValidators);
195  static::assertArrayHasKey('qux', $propertyValidators);
196 
198  $fooPropertyValidators = $propertyValidators['foo'];
199  static::assertInstanceOf(\SplObjectStorage::class, $fooPropertyValidators);
200  static::assertCount(3, $fooPropertyValidators);
201 
202  $fooPropertyValidators->rewind();
204  $propertyValidator = $fooPropertyValidators->current();
205  static::assertInstanceOf(StringLengthValidator::class, $propertyValidator);
206  static::assertSame(['minimum' => 1, 'maximum' => PHP_INT_MAX], $propertyValidator->getOptions());
207 
208  $fooPropertyValidators->next();
210  $propertyValidator = $fooPropertyValidators->current();
211  static::assertInstanceOf(StringLengthValidator::class, $propertyValidator);
212  static::assertSame(['minimum' => 0, 'maximum' => 10], $propertyValidator->getOptions());
213 
214  $fooPropertyValidators->next();
215  $propertyValidator = $fooPropertyValidators->current();
216  static::assertInstanceOf(NotEmptyValidator::class, $propertyValidator);
217 
219  $barPropertyValidators = $propertyValidators['bar'];
220  static::assertInstanceOf(\SplObjectStorage::class, $barPropertyValidators);
221  static::assertCount(1, $barPropertyValidators);
222 
223  $barPropertyValidators->rewind();
224  $propertyValidator = $barPropertyValidators->current();
225  static::assertInstanceOf(Fixture\Validation\Validator\CustomValidator::class, $propertyValidator);
226 
228  $bazPropertyValidators = $propertyValidators['baz'];
229  static::assertInstanceOf(\SplObjectStorage::class, $bazPropertyValidators);
230  static::assertCount(1, $bazPropertyValidators);
231 
232  $bazPropertyValidators->rewind();
233  $propertyValidator = $bazPropertyValidators->current();
234  static::assertInstanceOf(CollectionValidator::class, $propertyValidator);
235 
237  $quxPropertyValidators = $propertyValidators['qux'];
238  static::assertInstanceOf(\SplObjectStorage::class, $quxPropertyValidators);
239  static::assertCount(1, $quxPropertyValidators);
240 
241  $quxPropertyValidators->rewind();
242  $propertyValidator = $quxPropertyValidators->current();
243  static::assertInstanceOf(ConjunctionValidator::class, $propertyValidator);
244  static::assertSame(
245  $baseValidatorConjunctions[\‪TYPO3\CMS\‪Extbase\Tests\Functional\Validation\Fixture\Domain\Model\AnotherModel::class],
246  $propertyValidator
247  );
248 
249  $baseValidators->next();
250  ‪$validator = $baseValidators->current();
251  static::assertInstanceOf(Fixture\Domain\Validator\ModelValidator::class, ‪$validator);
252  }
253 }
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\setUp
‪setUp()
Definition: ValidatorResolverTest.php:38
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest
Definition: ValidatorResolverTest.php:33
‪TYPO3\CMS\Extbase\Tests\Functional\Validation
‪TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException
Definition: NoSuchValidatorException.php:21
‪TYPO3\CMS\Extbase\Validation\Validator\CollectionValidator
Definition: CollectionValidator.php:21
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\resolveValidatorObjectNameWithShortHandNotationThrowsExceptionIfClassDoesNotExist
‪resolveValidatorObjectNameWithShortHandNotationThrowsExceptionIfClassDoesNotExist()
Definition: ValidatorResolverTest.php:85
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\resolveValidatorObjectNameReturnsValidatorNameForFullQualifiedValidatorNameWithLeadingBackslash
‪resolveValidatorObjectNameReturnsValidatorNameForFullQualifiedValidatorNameWithLeadingBackslash()
Definition: ValidatorResolverTest.php:123
‪TYPO3\CMS\Extbase\Validation\ValidatorResolver
Definition: ValidatorResolver.php:29
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\resolveValidatorObjectNameReturnsValidatorNameForFullQualifiedValidatorName
‪resolveValidatorObjectNameReturnsValidatorNameForFullQualifiedValidatorName()
Definition: ValidatorResolverTest.php:109
‪TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
Definition: StringLengthValidator.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction
‪buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction()
Definition: ValidatorResolverTest.php:162
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:27
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments
‪buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments()
Definition: ValidatorResolverTest.php:148
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExists
‪resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExists(string $validatorName, string $expectedClassName)
Definition: ValidatorResolverTest.php:74
‪TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator
Definition: GenericObjectValidator.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExistsButDoesNotImplementValidatorInterface
‪resolveValidatorObjectNameWithShortHandNotationReturnsValidatorNameIfClassExistsButDoesNotImplementValidatorInterface()
Definition: ValidatorResolverTest.php:97
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\namespacedShorthandValidatorNamesDataProvider
‪array namespacedShorthandValidatorNamesDataProvider()
Definition: ValidatorResolverTest.php:53
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\resolveValidatorObjectNameThrowsNoSuchValidatorExceptionIfClassDoesNotExist
‪resolveValidatorObjectNameThrowsNoSuchValidatorExceptionIfClassDoesNotExist()
Definition: ValidatorResolverTest.php:137
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\$validatorResolver
‪TYPO3 CMS Extbase Validation ValidatorResolver PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $validatorResolver
Definition: ValidatorResolverTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25