TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ProcessingRuleTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration;
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 
25 
30 {
31 
35  protected $singletonInstances = [];
36 
40  public function setUp()
41  {
42  $this->singletonInstances = GeneralUtility::getSingletonInstances();
43  }
44 
48  public function tearDown()
49  {
50  GeneralUtility::resetSingletonInstances($this->singletonInstances);
51  parent::tearDown();
52  }
53 
57  public function addValidatorAddValidator()
58  {
59  $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
60  'dummy'
61  ], [], '', false);
62 
63  $mockProcessingRule->_set('validator', new ConjunctionValidator([]));
64  $mockProcessingRule->addValidator(new TestValidator());
65  $validators = $mockProcessingRule->_get('validator')->getValidators();
66  $validators->rewind();
67  $this->assertInstanceOf(AbstractValidator::class, $validators->current());
68  }
69 
74  {
75  $objectMangerProphecy = $this->prophesize(ObjectManager::class);
76  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
77  $resultProphecy = $this->prophesize(Result::class);
78 
79  $objectMangerProphecy
80  ->get(Result::class)
81  ->willReturn($resultProphecy->reveal());
82 
83  $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
84  'dummy'
85  ], [], '', false);
86 
87  $mockProcessingRule->_set('dataType', null);
88  $mockProcessingRule->_set('processingMessages', $resultProphecy->reveal());
89  $mockProcessingRule->_set('validator', new ConjunctionValidator([]));
90 
91  $input = 'someValue';
92  $this->assertSame($input, $mockProcessingRule->_call('process', $input));
93  }
94 
99  {
100  $objectMangerProphecy = $this->prophesize(ObjectManager::class);
101  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
102 
103  $objectMangerProphecy
104  ->get(Result::class)
105  ->willReturn(new Result);
106 
107  $mockProcessingRule = $this->getAccessibleMock(ProcessingRule::class, [
108  'dummy'
109  ], [], '', true);
110 
111  $mockProcessingRule->_set('dataType', null);
112  $mockProcessingRule->_set('validator', new ConjunctionValidator([]));
113  $mockProcessingRule->addValidator(new TestValidator());
114 
115  $input = 'addError';
116  $mockProcessingRule->_call('process', $input);
117 
118  $this->assertTrue($mockProcessingRule->_get('processingMessages')->hasErrors());
119  }
120 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)