‪TYPO3CMS  10.4
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 
20 use Psr\EventDispatcher\EventDispatcherInterface;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
31 class ‪EditDocumentControllerTest extends FunctionalTestCase
32 {
36  protected ‪$subject;
37 
41  protected ‪$request;
42 
46  protected ‪$normalizedParams;
47 
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54 
55  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
56  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/tt_content.xml');
57 
58  $this->setUpBackendUserFromFixture(1);
60 
61  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
62  $this->subject = new ‪EditDocumentController($eventDispatcher->reveal());
63  $this->request = new ‪ServerRequest();
64  $this->normalizedParams = new ‪NormalizedParams([], [], '', '');
65  }
66 
70  public function ‪processedDataTakesOverDefaultValues(): void
71  {
72  $defaultValues = [
73  'colPos' => 123,
74  'CType' => 'bullets'
75  ];
76 
77  $queryParams = $this->‪getQueryParamsWithDefaults($defaultValues);
78  $parsedBody = $this->‪getParsedBody();
79 
80  $this->subject->mainAction(
81  $this->request
82  ->withAttribute('normalizedParams', $this->normalizedParams)
83  ->withQueryParams($queryParams)
84  ->withParsedBody($parsedBody)
85  );
86 
87  $newRecord = ‪BackendUtility::getRecord('tt_content', 2);
88  self::assertEquals(
89  [$newRecord['colPos'], $newRecord['CType']],
90  [$defaultValues['colPos'], $defaultValues['CType']]
91  );
92  }
93 
98  {
99  $defaultValues = [
100  'colPos' => 123,
101  'CType' => 'bullets'
102  ];
103 
104  $queryParams = $this->‪getQueryParamsWithDefaults($defaultValues);
105  $parsedBody = $this->‪getParsedBody(['colPos' => 0, 'CType' => 'text']);
106 
107  $this->subject->mainAction(
108  $this->request
109  ->withAttribute('normalizedParams', $this->normalizedParams)
110  ->withQueryParams($queryParams)
111  ->withParsedBody($parsedBody)
112  );
113 
114  $newRecord = ‪BackendUtility::getRecord('tt_content', 2);
115  self::assertEquals(
116  [$newRecord['colPos'], $newRecord['CType']],
117  [0, 'text']
118  );
119  }
120 
121  protected function ‪getParsedBody(array $additionalData = []): array
122  {
123  return [
124  'data' => [
125  'tt_content' => [
126  'NEW123456' => \array_replace_recursive([
127  'sys_language_uid' => 0,
128  'header' => 'Test header',
129  'pid' => -1,
130  ], $additionalData)
131  ]
132  ],
133  'doSave' => true
134  ];
135  }
136 
137  protected function ‪getQueryParamsWithDefaults(array $defaultValues): array
138  {
139  return [
140  'edit' => [
141  'tt_content' => [
142  -1 => 'new'
143  ]
144  ],
145  'defVals' => [
146  'tt_content' => $defaultValues
147  ]
148  ];
149  }
150 }
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\processedDataTakesOverDefaultValues
‪processedDataTakesOverDefaultValues()
Definition: EditDocumentControllerTest.php:67
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest
Definition: EditDocumentControllerTest.php:32
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\processedDataDoesNotOverridePostWithDefaultValues
‪processedDataDoesNotOverridePostWithDefaultValues()
Definition: EditDocumentControllerTest.php:94
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\getParsedBody
‪getParsedBody(array $additionalData=[])
Definition: EditDocumentControllerTest.php:118
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Backend\Controller\EditDocumentController
Definition: EditDocumentController.php:67
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\$normalizedParams
‪NormalizedParams $normalizedParams
Definition: EditDocumentControllerTest.php:43
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\$subject
‪EditDocumentController $subject
Definition: EditDocumentControllerTest.php:35
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\getQueryParamsWithDefaults
‪getQueryParamsWithDefaults(array $defaultValues)
Definition: EditDocumentControllerTest.php:134
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\$request
‪ServerRequest $request
Definition: EditDocumentControllerTest.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Controller\EditDocumentControllerTest\setUp
‪setUp()
Definition: EditDocumentControllerTest.php:48
‪TYPO3\CMS\Backend\Tests\Functional\Controller
Definition: EditDocumentControllerTest.php:18
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35