‪TYPO3CMS  11.5
EditDocumentControllerTest.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 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
32 class ‪EditDocumentControllerTest extends FunctionalTestCase
33 {
35 
37 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44 
45  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
46  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/tt_content.xml');
47 
48  $this->setUpBackendUserFromFixture(1);
50 
51  $this->subject = GeneralUtility::makeInstance(EditDocumentController::class);
52  $this->normalizedParams = new ‪NormalizedParams([], [], '', '');
53  }
54 
59  {
60  $request = (new ‪ServerRequest('https://www.example.com/', 'POST'))
61  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
62  $defaultValues = [
63  'colPos' => 123,
64  'CType' => 'bullets',
65  ];
66 
67  $queryParams = $this->‪getQueryParamsWithDefaults($defaultValues);
68  $parsedBody = $this->‪getParsedBody();
69 
70  $response = $this->subject->mainAction(
71  $request
72  ->withAttribute('normalizedParams', $this->normalizedParams)
73  ->withQueryParams($queryParams)
74  ->withParsedBody($parsedBody)
75  );
76 
77  $newRecord = BackendUtility::getRecord('tt_content', 2);
78  self::assertEquals(
79  [$defaultValues['colPos'], $defaultValues['CType']],
80  [$newRecord['colPos'], $newRecord['CType']]
81  );
82  // Redirect to GET is applied after processing
83  self::assertEquals(302, $response->getStatusCode());
84  }
85 
90  {
91  $request = (new ‪ServerRequest('https://www.example.com/', 'POST'))
92  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
93  $defaultValues = [
94  'colPos' => 123,
95  'CType' => 'bullets',
96  ];
97 
98  $queryParams = $this->‪getQueryParamsWithDefaults($defaultValues);
99  $parsedBody = $this->‪getParsedBody(['colPos' => 0, 'CType' => 'text']);
100 
101  $response = $this->subject->mainAction(
102  $request
103  ->withAttribute('normalizedParams', $this->normalizedParams)
104  ->withQueryParams($queryParams)
105  ->withParsedBody($parsedBody)
106  );
107 
108  $newRecord = BackendUtility::getRecord('tt_content', 2);
109  self::assertEquals(
110  [0, 'text'],
111  [$newRecord['colPos'], $newRecord['CType']],
112  );
113  // Redirect to GET is applied after processing
114  self::assertEquals(302, $response->getStatusCode());
115  }
116 
117  protected function ‪getParsedBody(array $additionalData = []): array
118  {
119  return [
120  'data' => [
121  'tt_content' => [
122  'NEW123456' => array_replace_recursive([
123  'sys_language_uid' => 0,
124  'header' => 'Test header',
125  'pid' => -1,
126  ], $additionalData),
127  ],
128  ],
129  'doSave' => true,
130  ];
131  }
132 
133  protected function ‪getQueryParamsWithDefaults(array $defaultValues): array
134  {
135  return [
136  'edit' => [
137  'tt_content' => [
138  -1 => 'new',
139  ],
140  ],
141  'defVals' => [
142  'tt_content' => $defaultValues,
143  ],
144  ];
145  }
146 }
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\processedDataTakesOverDefaultValues
‪processedDataTakesOverDefaultValues()
Definition: EditDocumentControllerTest.php:58
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest
Definition: EditDocumentControllerTest.php:33
‪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\Tests\Functional\Controller\EditDocumentControllerTest\processedDataDoesNotOverridePostWithDefaultValues
‪processedDataDoesNotOverridePostWithDefaultValues()
Definition: EditDocumentControllerTest.php:89
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\getParsedBody
‪getParsedBody(array $additionalData=[])
Definition: EditDocumentControllerTest.php:117
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Backend\Controller\EditDocumentController
Definition: EditDocumentController.php:75
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\$normalizedParams
‪NormalizedParams $normalizedParams
Definition: EditDocumentControllerTest.php:36
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\$subject
‪EditDocumentController $subject
Definition: EditDocumentControllerTest.php:34
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\getQueryParamsWithDefaults
‪getQueryParamsWithDefaults(array $defaultValues)
Definition: EditDocumentControllerTest.php:133
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\setUp
‪setUp()
Definition: EditDocumentControllerTest.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Functional\Controller
Definition: EditDocumentControllerTest.php:18
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35