TYPO3 CMS  TYPO3_8-7
FormRuntimeTest.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 FormRuntimeTest 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 
57  {
58  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
59  'isAfterLastPage'
60  ], [], '', false);
61 
62  $mockPage = $this->getAccessibleMock(Page::class, [
63  'getIndex'
64  ], [], '', false);
65 
66  $mockFormState = $this->getAccessibleMock(FormState::class, [
67  'dummy'
68  ], [], '', false);
69 
70  $mockFormDefinition = $this->getAccessibleMock(FormDefinition::class, [
71  'getRendererClassName',
72  'getIdentifier'
73  ], [], '', false);
74 
75  $mockPage
76  ->expects($this->any())
77  ->method('getIndex')
78  ->willReturn(1);
79 
80  $mockFormDefinition
81  ->expects($this->any())
82  ->method('getRendererClassName')
83  ->willReturn('');
84 
85  $mockFormDefinition
86  ->expects($this->any())
87  ->method('getIdentifier')
88  ->willReturn('text-1');
89 
90  $mockFormRuntime
91  ->expects($this->any())
92  ->method('isAfterLastPage')
93  ->willReturn(false);
94 
95  $mockFormRuntime->_set('formState', $mockFormState);
96  $mockFormRuntime->_set('currentPage', $mockPage);
97  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
98 
99  $this->expectException(RenderingException::class);
100  $this->expectExceptionCode(1326095912);
101 
102  $mockFormRuntime->_call('render');
103  }
104 
109  {
110  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
111  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
112 
113  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
114  'isAfterLastPage'
115  ], [], '', false);
116 
117  $mockPage = $this->getAccessibleMock(Page::class, [
118  'getIndex'
119  ], [], '', false);
120 
121  $mockFormState = $this->getAccessibleMock(FormState::class, [
122  'dummy'
123  ], [], '', false);
124 
125  $mockFormDefinition = $this->getAccessibleMock(FormDefinition::class, [
126  'getRendererClassName',
127  'getIdentifier'
128  ], [], '', false);
129 
130  $mockPage
131  ->expects($this->any())
132  ->method('getIndex')
133  ->willReturn(1);
134 
135  $mockFormDefinition
136  ->expects($this->any())
137  ->method('getRendererClassName')
138  ->willReturn('fooRenderer');
139 
140  $mockFormDefinition
141  ->expects($this->any())
142  ->method('getIdentifier')
143  ->willReturn('text-1');
144 
145  $mockFormRuntime
146  ->expects($this->any())
147  ->method('isAfterLastPage')
148  ->willReturn(false);
149 
150  $objectManagerProphecy
151  ->get('fooRenderer')
152  ->willReturn(new \stdClass);
153 
154  $mockFormRuntime->_set('formState', $mockFormState);
155  $mockFormRuntime->_set('currentPage', $mockPage);
156  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
157  $mockFormRuntime->_set('objectManager', $objectManagerProphecy->reveal());
158 
159  $this->expectException(RenderingException::class);
160  $this->expectExceptionCode(1326096024);
161 
162  $mockFormRuntime->_call('render');
163  }
164 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)