TYPO3 CMS  TYPO3_8-7
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 
28 class ProcessingRuleTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
30 
34  protected $singletonInstances = [];
35 
39  public function setUp()
40  {
41  $this->singletonInstances = GeneralUtility::getSingletonInstances();
42  }
43 
47  public function tearDown()
48  {
49  GeneralUtility::resetSingletonInstances($this->singletonInstances);
50  parent::tearDown();
51  }
52 
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 
73  {
74  $objectMangerProphecy = $this->prophesize(ObjectManager::class);
75  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
76  $resultProphecy = $this->prophesize(Result::class);
77 
78  $objectMangerProphecy
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 
98  {
99  $objectMangerProphecy = $this->prophesize(ObjectManager::class);
100  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
101 
102  $objectMangerProphecy
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 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)