‪TYPO3CMS  10.4
ValidatorResolverTest.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 
32 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
33 
37 class ‪ValidatorResolverTest extends FunctionalTestCase
38 {
42  private ‪$validatorResolver;
43 
44  protected function ‪setUp(): void
45  {
46  parent::setUp();
47 
48  $this->validatorResolver = $this->getAccessibleMock(
49  ValidatorResolver::class,
50  ['dummy']
51  );
52  $this->validatorResolver->injectObjectManager(GeneralUtility::makeInstance(ObjectManager::class));
53  $this->validatorResolver->injectReflectionService(GeneralUtility::makeInstance(ReflectionService::class));
54  }
55 
60  {
61  $this->validatorResolver->_call(
62  'buildBaseValidatorConjunction',
63  Model::class,
64  Model::class
65  );
66 
68  $baseValidatorConjunctions = $this->validatorResolver->_get('baseValidatorConjunctions');
69  self::assertTrue(is_array($baseValidatorConjunctions));
70  self::assertCount(2, $baseValidatorConjunctions);
71  self::assertArrayHasKey(Model::class, $baseValidatorConjunctions);
72  self::assertArrayHasKey(AnotherModel::class, $baseValidatorConjunctions);
73 
75  $conjunctionValidator = $baseValidatorConjunctions[Model::class];
76  self::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
77 
78  $baseValidators = $conjunctionValidator->getValidators();
79  self::assertInstanceOf(\SplObjectStorage::class, $baseValidators);
80  $baseValidators->rewind();
81 
83  ‪$validator = $baseValidators->current();
84  self::assertInstanceOf(GenericObjectValidator::class, ‪$validator);
85 
86  $propertyValidators = ‪$validator->getPropertyValidators();
87  self::assertCount(4, $propertyValidators);
88  self::assertArrayHasKey('foo', $propertyValidators);
89  self::assertArrayHasKey('bar', $propertyValidators);
90  self::assertArrayHasKey('baz', $propertyValidators);
91  self::assertArrayHasKey('qux', $propertyValidators);
92 
94  $fooPropertyValidators = $propertyValidators['foo'];
95  self::assertInstanceOf(\SplObjectStorage::class, $fooPropertyValidators);
96  self::assertCount(3, $fooPropertyValidators);
97 
98  $fooPropertyValidators->rewind();
100  $propertyValidator = $fooPropertyValidators->current();
101  self::assertInstanceOf(StringLengthValidator::class, $propertyValidator);
102  self::assertSame(['minimum' => 1, 'maximum' => PHP_INT_MAX], $propertyValidator->getOptions());
103 
104  $fooPropertyValidators->next();
106  $propertyValidator = $fooPropertyValidators->current();
107  self::assertInstanceOf(StringLengthValidator::class, $propertyValidator);
108  self::assertSame(['minimum' => 0, 'maximum' => 10], $propertyValidator->getOptions());
109 
110  $fooPropertyValidators->next();
111  $propertyValidator = $fooPropertyValidators->current();
112  self::assertInstanceOf(NotEmptyValidator::class, $propertyValidator);
113 
115  $barPropertyValidators = $propertyValidators['bar'];
116  self::assertInstanceOf(\SplObjectStorage::class, $barPropertyValidators);
117  self::assertCount(1, $barPropertyValidators);
118 
119  $barPropertyValidators->rewind();
120  $propertyValidator = $barPropertyValidators->current();
121  self::assertInstanceOf(CustomValidator::class, $propertyValidator);
122 
124  $bazPropertyValidators = $propertyValidators['baz'];
125  self::assertInstanceOf(\SplObjectStorage::class, $bazPropertyValidators);
126  self::assertCount(1, $bazPropertyValidators);
127 
128  $bazPropertyValidators->rewind();
129  $propertyValidator = $bazPropertyValidators->current();
130  self::assertInstanceOf(CollectionValidator::class, $propertyValidator);
131 
133  $quxPropertyValidators = $propertyValidators['qux'];
134  self::assertInstanceOf(\SplObjectStorage::class, $quxPropertyValidators);
135  self::assertCount(1, $quxPropertyValidators);
136 
137  $quxPropertyValidators->rewind();
138  $propertyValidator = $quxPropertyValidators->current();
139  self::assertInstanceOf(ConjunctionValidator::class, $propertyValidator);
140  self::assertSame(
141  $baseValidatorConjunctions[AnotherModel::class],
142  $propertyValidator
143  );
144  }
145 }
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\setUp
‪setUp()
Definition: ValidatorResolverTest.php:43
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest
Definition: ValidatorResolverTest.php:38
‪TYPO3\CMS\Extbase\Tests\Functional\Validation
‪TYPO3\CMS\Extbase\Validation\Validator\CollectionValidator
Definition: CollectionValidator.php:27
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Fixture\Validation\Validator\CustomValidator
Definition: CustomValidator.php:26
‪TYPO3\CMS\Extbase\Validation\ValidatorResolver
Definition: ValidatorResolver.php:35
‪TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator
Definition: StringLengthValidator.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\ValidatorResolverTest\buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction
‪buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction()
Definition: ValidatorResolverTest.php:58
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:31
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Fixture\Domain\Model\AnotherModel
Definition: AnotherModel.php:27
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator
Definition: GenericObjectValidator.php:25
‪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:41
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Fixture\Domain\Model\Model
Definition: Model.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28