‪TYPO3CMS  9.5
ProcessingRuleTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪ProcessingRuleTest extends UnitTestCase
30 {
34  protected ‪$resetSingletonInstances = true;
35 
39  public function ‪addValidatorAddValidator()
40  {
41  $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
42  'dummy'
43  ], [], '', false);
44 
45  $mockProcessingRule->_set('validator', new ‪ConjunctionValidator([]));
46  $mockProcessingRule->addValidator(new ‪TestValidator());
47  $validators = $mockProcessingRule->_get('validator')->getValidators();
48  $validators->rewind();
49  $this->assertInstanceOf(AbstractValidator::class, $validators->current());
50  }
51 
56  {
57  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
58  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
59  $resultProphecy = $this->prophesize(Result::class);
60 
61  $objectManagerProphecy
62  ->get(Result::class)
63  ->willReturn($resultProphecy->reveal());
64 
65  $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
66  'dummy'
67  ], [], '', false);
68 
69  $mockProcessingRule->_set('dataType', null);
70  $mockProcessingRule->_set('processingMessages', $resultProphecy->reveal());
71  $mockProcessingRule->_set('validator', new ‪ConjunctionValidator([]));
72 
73  $input = 'someValue';
74  $this->assertSame($input, $mockProcessingRule->_call('process', $input));
75  }
76 
81  {
82  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
83  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
84 
85  $objectManagerProphecy
86  ->get(Result::class)
87  ->willReturn(new ‪Result);
88 
89  $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
90  'dummy'
91  ], [], '', true);
92 
93  $mockProcessingRule->_set('dataType', null);
94  $mockProcessingRule->_set('validator', new ‪ConjunctionValidator([]));
95  $mockProcessingRule->addValidator(new ‪TestValidator());
96 
97  $input = 'addError';
98  $mockProcessingRule->_call('process', $input);
99 
100  $this->assertTrue($mockProcessingRule->_get('processingMessages')->hasErrors());
101  }
102 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\Fixtures\TestValidator
Definition: TestValidator.php:23
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
Definition: AbstractValidator.php:23
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:23
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ProcessingRuleTest.php:33
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\processNoPropertyMappingAndHasErrorsIfValidatorContainsErrors
‪processNoPropertyMappingAndHasErrorsIfValidatorContainsErrors()
Definition: ProcessingRuleTest.php:79
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest
Definition: ProcessingRuleTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Mvc
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\processNoPropertyMappingReturnsNotModifiedValue
‪processNoPropertyMappingReturnsNotModifiedValue()
Definition: ProcessingRuleTest.php:54
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:20
‪TYPO3\CMS\Form\Tests\Unit\Mvc\ProcessingRuleTest\addValidatorAddValidator
‪addValidatorAddValidator()
Definition: ProcessingRuleTest.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Form\Mvc\ProcessingRule
Definition: ProcessingRule.php:32