‪TYPO3CMS  11.5
FormRuntimeTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪FormRuntimeTest extends UnitTestCase
32 {
33  use \Prophecy\PhpUnit\ProphecyTrait;
37  protected ‪$resetSingletonInstances = true;
38 
43  {
44  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
45  'isAfterLastPage', 'processVariants',
46  ], [], '', false);
47 
48  $mockPage = $this->getMockBuilder(Page::class)->onlyMethods([
49  'getIndex',
50  ])->disableOriginalConstructor()->getMock();
51 
52  $mockFormState = $this->getMockBuilder(FormState::class)->disableOriginalConstructor()->getMock();
53 
54  $mockFormDefinition = $this->getMockBuilder(FormDefinition::class)->onlyMethods([
55  'getRendererClassName',
56  'getIdentifier',
57  ])->disableOriginalConstructor()->getMock();
58 
59  $mockPage
60  ->method('getIndex')
61  ->willReturn(1);
62 
63  $mockFormDefinition
64  ->method('getRendererClassName')
65  ->willReturn('');
66 
67  $mockFormDefinition
68  ->method('getIdentifier')
69  ->willReturn('text-1');
70 
71  $mockFormRuntime
72  ->method('isAfterLastPage')
73  ->willReturn(false);
74 
75  $mockFormRuntime
76  ->method('processVariants')
77  ->willReturn(null);
78 
79  $mockFormRuntime->_set('formState', $mockFormState);
80  $mockFormRuntime->_set('currentPage', $mockPage);
81  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
82 
83  $this->expectException(RenderingException::class);
84  $this->expectExceptionCode(1326095912);
85 
86  $mockFormRuntime->_call('render');
87  }
88 
93  {
94  $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, [
95  'isAfterLastPage', 'processVariants',
96  ], [], '', false);
97 
98  $mockPage = $this->getMockBuilder(Page::class)->onlyMethods([
99  'getIndex',
100  ])->disableOriginalConstructor()->getMock();
101 
102  $mockFormState = $this->getMockBuilder(FormState::class)->disableOriginalConstructor()->getMock();
103 
104  $mockFormDefinition = $this->getMockBuilder(FormDefinition::class)->onlyMethods([
105  'getRendererClassName',
106  'getIdentifier',
107  ])->disableOriginalConstructor()->getMock();
108 
109  $mockPage->method('getIndex')->willReturn(1);
110 
111  $mockFormDefinition->method('getRendererClassName')->willReturn('fooRenderer');
112  $mockFormDefinition->method('getIdentifier')->willReturn('text-1');
113 
114  $mockFormRuntime->method('isAfterLastPage')->willReturn(false);
115  $mockFormRuntime->method('processVariants')->willReturn(null);
116 
117  $containerProphecy = $this->prophesize(ContainerInterface::class);
118  $containerProphecy->has('fooRenderer')->willReturn(true)->shouldBeCalled();
119  $containerProphecy->get('fooRenderer')->willReturn(new \stdClass())->shouldBeCalled();
120 
121  $mockFormRuntime->_set('formState', $mockFormState);
122  $mockFormRuntime->_set('currentPage', $mockPage);
123  $mockFormRuntime->_set('formDefinition', $mockFormDefinition);
124  $mockFormRuntime->_set('container', $containerProphecy->reveal());
125 
126  $this->expectException(RenderingException::class);
127  $this->expectExceptionCode(1326096024);
128 
129  $mockFormRuntime->_call('render');
130  }
131 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FormRuntimeTest.php:35
‪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:18
‪TYPO3\CMS\Form\Domain\Model\FormDefinition
Definition: FormDefinition.php:226
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName
‪renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName()
Definition: FormRuntimeTest.php:40
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest
Definition: FormRuntimeTest.php:32
‪TYPO3\CMS\Form\Domain\Exception\RenderingException
Definition: RenderingException.php:29
‪TYPO3\CMS\Form\Tests\Unit\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface
‪renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface()
Definition: FormRuntimeTest.php:90