‪TYPO3CMS  11.5
ProcessingRuleTest.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 
20 use Prophecy\PhpUnit\ProphecyTrait;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪ProcessingRuleTest extends UnitTestCase
34 {
35  use ProphecyTrait;
36 
40  public function ‪addValidatorAddsValidator(): void
41  {
42  GeneralUtility::addInstance(ConjunctionValidator::class, new ‪ConjunctionValidator([]));
43  $subject = new ‪ProcessingRule($this->prophesize(PropertyMapper::class)->reveal());
44  $subject->addValidator(new ‪TestValidator());
45  $validators = $subject->getValidators();
46  $validators->rewind();
47  self::assertInstanceOf(AbstractValidator::class, $validators->current());
48  }
49 
53  public function ‪removeAllRemovesAllValidators(): void
54  {
55  $subject = new ‪ProcessingRule($this->prophesize(PropertyMapper::class)->reveal());
56  $subject->addValidator(new ‪TestValidator());
57  $subject->addValidator(new ‪AnotherTestValidator());
58  $subject->addValidator(new ‪TestValidator());
59  $subject->removeAllValidators();
60  self::assertCount(0, $subject->getValidators());
61  }
62 
67  {
68  $subject = new ‪ProcessingRule($this->prophesize(PropertyMapper::class)->reveal());
69  $subject->addValidator(new ‪TestValidator());
70  $subject->addValidator(new ‪AnotherTestValidator());
71  $subject->addValidator(new ‪TestValidator());
72  $subject->filterValidators(static function (‪$validator) {
73  return ‪$validator instanceof ‪AnotherTestValidator;
74  });
75  $validators = $subject->getValidators();
76  self::assertCount(1, $validators);
77  self::assertInstanceOf(AnotherTestValidator::class, $validators->current());
78  }
79 
84  {
85  GeneralUtility::addInstance(ConjunctionValidator::class, new ‪ConjunctionValidator([]));
86  $processingRule = new ‪ProcessingRule($this->prophesize(PropertyMapper::class)->reveal());
87  $input = 'someValue';
88  self::assertSame($input, $processingRule->process($input));
89  }
90 
95  {
96  GeneralUtility::addInstance(ConjunctionValidator::class, new ‪ConjunctionValidator([]));
97  $processingRule = new ‪ProcessingRule($this->prophesize(PropertyMapper::class)->reveal());
98  $processingRule->addValidator(new ‪TestValidator());
99  $input = 'addError';
100  $processingRule->process($input);
101  self::assertTrue($processingRule->getProcessingMessages()->hasErrors());
102  }
103 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\Fixtures\TestValidator
Definition: TestValidator.php:26
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
Definition: AbstractValidator.php:27
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:24
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\processNoPropertyMappingAndHasErrorsIfValidatorContainsErrors
‪processNoPropertyMappingAndHasErrorsIfValidatorContainsErrors()
Definition: ProcessingRuleTest.php:93
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest
Definition: ProcessingRuleTest.php:34
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\addValidatorAddsValidator
‪addValidatorAddsValidator()
Definition: ProcessingRuleTest.php:39
‪TYPO3\CMS\Form\Tests\Unit\Mvc
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\processNoPropertyMappingReturnsNotModifiedValue
‪processNoPropertyMappingReturnsNotModifiedValue()
Definition: ProcessingRuleTest.php:82
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\removeAllRemovesAllValidators
‪removeAllRemovesAllValidators()
Definition: ProcessingRuleTest.php:52
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\filterValidatorRemovesValidatorsDependingOnClosure
‪filterValidatorRemovesValidatorsDependingOnClosure()
Definition: ProcessingRuleTest.php:65
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Property\PropertyMapper
Definition: PropertyMapper.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Form\Mvc\ProcessingRule
Definition: ProcessingRule.php:35
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Fixtures\AnotherTestValidator
Definition: AnotherTestValidator.php:26