‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FormRuntimeTest extends UnitTestCase
30 {
34  protected ‪$resetSingletonInstances = true;
35 
40  {
41  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
42  'isAfterLastPage', 'processVariants'
43  ], [], '', false);
44 
45  $mockPage = $this->getAccessibleMock(Page::class, [
46  'getIndex'
47  ], [], '', false);
48 
49  $mockFormState = $this->getAccessibleMock(FormState::class, [
50  'dummy'
51  ], [], '', false);
52 
53  $mockFormDefinition = $this->getAccessibleMock(FormDefinition::class, [
54  'getRendererClassName',
55  'getIdentifier'
56  ], [], '', false);
57 
58  $mockPage
59  ->expects($this->any())
60  ->method('getIndex')
61  ->willReturn(1);
62 
63  $mockFormDefinition
64  ->expects($this->any())
65  ->method('getRendererClassName')
66  ->willReturn('');
67 
68  $mockFormDefinition
69  ->expects($this->any())
70  ->method('getIdentifier')
71  ->willReturn('text-1');
72 
73  $mockFormRuntime
74  ->expects($this->any())
75  ->method('isAfterLastPage')
76  ->willReturn(false);
77 
78  $mockFormRuntime
79  ->expects($this->any())
80  ->method('processVariants')
81  ->willReturn(null);
82 
83  $mockFormRuntime->_set('formState', $mockFormState);
84  $mockFormRuntime->_set('currentPage', $mockPage);
85  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
86 
87  $this->expectException(RenderingException::class);
88  $this->expectExceptionCode(1326095912);
89 
90  $mockFormRuntime->_call('render');
91  }
92 
97  {
98  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
99  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
100 
101  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
102  'isAfterLastPage', 'processVariants'
103  ], [], '', false);
104 
105  $mockPage = $this->getAccessibleMock(Page::class, [
106  'getIndex'
107  ], [], '', false);
108 
109  $mockFormState = $this->getAccessibleMock(FormState::class, [
110  'dummy'
111  ], [], '', false);
112 
113  $mockFormDefinition = $this->getAccessibleMock(FormDefinition::class, [
114  'getRendererClassName',
115  'getIdentifier'
116  ], [], '', false);
117 
118  $mockPage
119  ->expects($this->any())
120  ->method('getIndex')
121  ->willReturn(1);
122 
123  $mockFormDefinition
124  ->expects($this->any())
125  ->method('getRendererClassName')
126  ->willReturn('fooRenderer');
127 
128  $mockFormDefinition
129  ->expects($this->any())
130  ->method('getIdentifier')
131  ->willReturn('text-1');
132 
133  $mockFormRuntime
134  ->expects($this->any())
135  ->method('isAfterLastPage')
136  ->willReturn(false);
137 
138  $mockFormRuntime
139  ->expects($this->any())
140  ->method('processVariants')
141  ->willReturn(null);
142 
143  $objectManagerProphecy
144  ->get('fooRenderer')
145  ->willReturn(new \stdClass);
146 
147  $mockFormRuntime->_set('formState', $mockFormState);
148  $mockFormRuntime->_set('currentPage', $mockPage);
149  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
150  $mockFormRuntime->_set('objectManager', $objectManagerProphecy->reveal());
151 
152  $this->expectException(RenderingException::class);
153  $this->expectExceptionCode(1326096024);
154 
155  $mockFormRuntime->_call('render');
156  }
157 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FormRuntimeTest.php:33
‪TYPO3\CMS\Form\Domain\Runtime\FormState
Definition: FormState.php:32
‪TYPO3\CMS\Form\Domain\Model\FormElements\Page
Definition: Page.php:40
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime
Definition: FormRuntimeTest.php:2
‪TYPO3\CMS\Form\Domain\Model\FormDefinition
Definition: FormDefinition.php:218
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:3
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName
‪renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName()
Definition: FormRuntimeTest.php:38
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest
Definition: FormRuntimeTest.php:30
‪TYPO3\CMS\Form\Domain\Exception\RenderingException
Definition: RenderingException.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface
‪renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface()
Definition: FormRuntimeTest.php:95
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25