‪TYPO3CMS  ‪main
FormTestService.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 
27 
32 {
36  public function ‪createNewRecordForm(string $table, array $defaults = []): array
37  {
38  $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class);
39  $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
40 
41  $request = new ‪ServerRequest();
42  $request = $request->withAttribute('route', new ‪Route('path', ['packageName' => 'typo3/cms-backend']));
43  $request = $request->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
44  $formDataCompilerInput = [
45  'request' => $request,
46  'tableName' => $table,
47  'vanillaUid' => 0,
48  'command' => 'new',
49  'databaseRow' => $defaults,
50  ];
51  $formData = $formDataCompiler->compile($formDataCompilerInput, GeneralUtility::makeInstance(TcaDatabaseRecord::class));
52 
53  $formData['renderType'] = 'outerWrapContainer';
54  return $nodeFactory->create($formData)->render();
55  }
56 
60  public function ‪formHtmlContainsField(string $fieldName, string $formHtml): bool
61  {
62  return (bool)strpos($formHtml, '[' . $fieldName . ']');
63  }
64 }
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService\createNewRecordForm
‪createNewRecordForm(string $table, array $defaults=[])
Definition: FormTestService.php:36
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService\formHtmlContainsField
‪formHtmlContainsField(string $fieldName, string $formHtml)
Definition: FormTestService.php:60
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:40
‪TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService
Definition: FormTestService.php:32
‪TYPO3\CMS\Backend\Tests\Functional\Form
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:26
‪TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord
Definition: TcaDatabaseRecord.php:25