[BUGFIX] Adapt a couple of broken test file namespaces
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Mvc / ProcessingRuleTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Error\Result;
19 use TYPO3\CMS\Extbase\Object\ObjectManager;
20 use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;
21 use TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator;
22 use TYPO3\CMS\Form\Mvc\ProcessingRule;
23 use TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\Fixtures\TestValidator;
24
25 /**
26 * Test case
27 */
28 class ProcessingRuleTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
30
31 /**
32 * @var array A backup of registered singleton instances
33 */
34 protected $singletonInstances = [];
35
36 /**
37 * Set up
38 */
39 public function setUp()
40 {
41 $this->singletonInstances = GeneralUtility::getSingletonInstances();
42 }
43
44 /**
45 * Tear down
46 */
47 public function tearDown()
48 {
49 GeneralUtility::resetSingletonInstances($this->singletonInstances);
50 parent::tearDown();
51 }
52
53 /**
54 * @test
55 */
56 public function addValidatorAddValidator()
57 {
58 $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
59 'dummy'
60 ], [], '', false);
61
62 $mockProcessingRule->_set('validator', new ConjunctionValidator([]));
63 $mockProcessingRule->addValidator(new TestValidator());
64 $validators = $mockProcessingRule->_get('validator')->getValidators();
65 $validators->rewind();
66 $this->assertInstanceOf(AbstractValidator::class, $validators->current());
67 }
68
69 /**
70 * @test
71 */
72 public function processNoPropertyMappingReturnsNotModifiedValue()
73 {
74 $objectManagerProphecy = $this->prophesize(ObjectManager::class);
75 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
76 $resultProphecy = $this->prophesize(Result::class);
77
78 $objectManagerProphecy
79 ->get(Result::class)
80 ->willReturn($resultProphecy->reveal());
81
82 $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
83 'dummy'
84 ], [], '', false);
85
86 $mockProcessingRule->_set('dataType', null);
87 $mockProcessingRule->_set('processingMessages', $resultProphecy->reveal());
88 $mockProcessingRule->_set('validator', new ConjunctionValidator([]));
89
90 $input = 'someValue';
91 $this->assertSame($input, $mockProcessingRule->_call('process', $input));
92 }
93
94 /**
95 * @test
96 */
97 public function processNoPropertyMappingAndHasErrorsIfValidatorContainsErrors()
98 {
99 $objectManagerProphecy = $this->prophesize(ObjectManager::class);
100 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
101
102 $objectManagerProphecy
103 ->get(Result::class)
104 ->willReturn(new Result);
105
106 $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
107 'dummy'
108 ], [], '', true);
109
110 $mockProcessingRule->_set('dataType', null);
111 $mockProcessingRule->_set('validator', new ConjunctionValidator([]));
112 $mockProcessingRule->addValidator(new TestValidator());
113
114 $input = 'addError';
115 $mockProcessingRule->_call('process', $input);
116
117 $this->assertTrue($mockProcessingRule->_get('processingMessages')->hasErrors());
118 }
119 }