‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
30 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
31 
32 final class ‪FormRuntimeTest extends FunctionalTestCase
33 {
34  protected array ‪$coreExtensionsToLoad = [
35  'form',
36  ];
37 
40 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
45  $this->formFactory = $this->get(ArrayFormFactory::class);
46  $this->request = $this->‪buildExtbaseRequest();
47  }
48 
49  #[Test]
51  {
52  $formDefinition = $this->‪buildFormDefinition();
53  $formDefinition->setOptions(['rendererClassName' => '']);
54  $formRuntime = $formDefinition->bind($this->request);
55 
56  $this->expectException(RenderingException::class);
57  $this->expectExceptionCode(1326095912);
58 
59  $formRuntime->render();
60  }
61 
62  #[Test]
64  {
65  $formDefinition = $this->‪buildFormDefinition();
66  // This must be a class available in the container without implementing RendererInterface
67  $formDefinition->setOptions(['rendererClassName' => ConfigurationManagerInterface::class]);
68  $formRuntime = $formDefinition->bind($this->request);
69 
70  $this->expectException(RenderingException::class);
71  $this->expectExceptionCode(1326096024);
72 
73  $formRuntime->render();
74  }
75 
76  private function ‪buildExtbaseRequest(): ‪Request
77  {
78  $frontendUser = new ‪FrontendUserAuthentication();
79  $frontendUser->initializeUserSessionManager();
80  $serverRequest = (new ‪ServerRequest())
81  ->withAttribute('extbase', new ‪ExtbaseRequestParameters())
82  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_FE)
83  ->withAttribute('frontend.user', $frontendUser);
84 
85  ‪$GLOBALS['TYPO3_REQUEST'] = $serverRequest;
86 
87  return (new ‪Request($serverRequest))->withPluginName('Formframework');
88  }
89 
91  {
92  return $this->formFactory->build([
93  'type' => 'Form',
94  'identifier' => 'test',
95  'label' => 'test',
96  'prototypeName' => 'standard',
97  'renderables' => [
98  [
99  'type' => 'Page',
100  'identifier' => 'page-1',
101  'label' => 'Page',
102  'renderables' => [
103  [
104  'type' => 'Text',
105  'identifier' => 'text-1',
106  'label' => 'Text',
107  ],
108  ],
109  ],
110  ],
111  ]);
112  }
113 
114  private function ‪loadDefaultYamlConfigurations(): void
115  {
116  $configurationManager = $this->get(ConfigurationManagerInterface::class);
117  $configurationManager->setConfiguration([
118  'plugin.' => [
119  'tx_form.' => [
120  'settings.' => [
121  'yamlConfigurations.' => [
122  '10' => 'EXT:form/Configuration/Yaml/FormSetup.yaml',
123  ],
124  ],
125  ],
126  ],
127  ]);
128  }
129 }
‪TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory
Definition: ArrayFormFactory.php:39
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\$request
‪Request $request
Definition: FormRuntimeTest.php:39
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\setUp
‪setUp()
Definition: FormRuntimeTest.php:41
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime
Definition: FormRuntimeTest.php:18
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: FormRuntimeTest.php:34
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest
Definition: FormRuntimeTest.php:33
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\$formFactory
‪ArrayFormFactory $formFactory
Definition: FormRuntimeTest.php:38
‪TYPO3\CMS\Form\Domain\Model\FormDefinition
Definition: FormDefinition.php:224
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface
‪renderThrowsExceptionIfRendererClassNameInstanceDoesNotImplementRendererInterface()
Definition: FormRuntimeTest.php:63
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\loadDefaultYamlConfigurations
‪loadDefaultYamlConfigurations()
Definition: FormRuntimeTest.php:114
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Form\Domain\Exception\RenderingException
Definition: RenderingException.php:29
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\buildFormDefinition
‪buildFormDefinition()
Definition: FormRuntimeTest.php:90
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:33
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters
Definition: ExtbaseRequestParameters.php:35
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_FE
‪const REQUESTTYPE_FE
Definition: SystemEnvironmentBuilder.php:43
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:35
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName
‪renderThrowsExceptionIfFormDefinitionReturnsNoRendererClassName()
Definition: FormRuntimeTest.php:50
‪TYPO3\CMS\Form\Tests\Functional\Domain\Runtime\FormRuntimeTest\buildExtbaseRequest
‪buildExtbaseRequest()
Definition: FormRuntimeTest.php:76
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:29