‪TYPO3CMS  10.4
FormRuntimeTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪FormRuntimeTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
41  {
42  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
43  'isAfterLastPage', 'processVariants'
44  ], [], '', false);
45 
46  $mockPage = $this->getMockBuilder(Page::class)->onlyMethods([
47  'getIndex'
48  ])->disableOriginalConstructor()->getMock();
49 
50  $mockFormState = $this->getMockBuilder(FormState::class)->disableOriginalConstructor()->getMock();
51 
52  $mockFormDefinition = $this->getMockBuilder(FormDefinition::class)->onlyMethods([
53  'getRendererClassName',
54  'getIdentifier'
55  ])->disableOriginalConstructor()->getMock();
56 
57  $mockPage
58  ->method('getIndex')
59  ->willReturn(1);
60 
61  $mockFormDefinition
62  ->method('getRendererClassName')
63  ->willReturn('');
64 
65  $mockFormDefinition
66  ->method('getIdentifier')
67  ->willReturn('text-1');
68 
69  $mockFormRuntime
70  ->method('isAfterLastPage')
71  ->willReturn(false);
72 
73  $mockFormRuntime
74  ->method('processVariants')
75  ->willReturn(null);
76 
77  $mockFormRuntime->_set('formState', $mockFormState);
78  $mockFormRuntime->_set('currentPage', $mockPage);
79  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
80 
81  $this->expectException(RenderingException::class);
82  $this->expectExceptionCode(1326095912);
83 
84  $mockFormRuntime->_call('render');
85  }
86 
91  {
92  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
93  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
94 
95  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
96  'isAfterLastPage', 'processVariants'
97  ], [], '', false);
98 
99  $mockPage = $this->getMockBuilder(Page::class)->onlyMethods([
100  'getIndex'
101  ])->disableOriginalConstructor()->getMock();
102 
103  $mockFormState = $this->getMockBuilder(FormState::class)->disableOriginalConstructor()->getMock();
104 
105  $mockFormDefinition = $this->getMockBuilder(FormDefinition::class)->onlyMethods([
106  'getRendererClassName',
107  'getIdentifier'
108  ])->disableOriginalConstructor()->getMock();
109 
110  $mockPage
111  ->method('getIndex')
112  ->willReturn(1);
113 
114  $mockFormDefinition
115  ->method('getRendererClassName')
116  ->willReturn('fooRenderer');
117 
118  $mockFormDefinition
119  ->method('getIdentifier')
120  ->willReturn('text-1');
121 
122  $mockFormRuntime
123  ->method('isAfterLastPage')
124  ->willReturn(false);
125 
126  $mockFormRuntime
127  ->method('processVariants')
128  ->willReturn(null);
129 
130  $objectManagerProphecy
131  ->get('fooRenderer')
132  ->willReturn(new \stdClass());
133 
134  $mockFormRuntime->_set('formState', $mockFormState);
135  $mockFormRuntime->_set('currentPage', $mockPage);
136  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
137  $mockFormRuntime->_set('objectManager', $objectManagerProphecy->reveal());
138 
139  $this->expectException(RenderingException::class);
140  $this->expectExceptionCode(1326096024);
141 
142  $mockFormRuntime->_call('render');
143  }
144 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FormRuntimeTest.php:34
‪TYPO3\CMS\Form\Domain\Runtime\FormState
Definition: FormState.php:36
‪TYPO3\CMS\Form\Domain\Model\FormElements\Page
Definition: Page.php:44
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime
Definition: FormRuntimeTest.php:16
‪TYPO3\CMS\Form\Domain\Model\FormDefinition
Definition: FormDefinition.php:223
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName
‪renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName()
Definition: FormRuntimeTest.php:39
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest
Definition: FormRuntimeTest.php:31
‪TYPO3\CMS\Form\Domain\Exception\RenderingException
Definition: RenderingException.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface
‪renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface()
Definition: FormRuntimeTest.php:89
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28