‪TYPO3CMS  10.4
LocalizationControllerTest.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 
24 
29 {
33  protected ‪$assertionDataSetDirectory = 'typo3/sysext/backend/Tests/Functional/Controller/Page/Localization/CSV/DataSet/';
34 
38  protected ‪$subject;
39 
43  protected ‪$backendUser;
44 
49  protected ‪$assertCleanReferenceIndex = false;
50 
54  protected ‪$coreExtensionsToLoad = ['workspaces'];
55 
59  protected function ‪setUp(): void
60  {
61  parent::setUp();
62 
63  $this->importDataSet(__DIR__ . '/Fixtures/pages.xml');
64  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_language.xml');
65  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-default-language.xml');
66  $this->setUpFrontendRootPage(1);
67  $this->‪setUpFrontendSite(1, $this->siteLanguageConfiguration);
68 
69  $this->subject = $this->getAccessibleMock(LocalizationController::class, ['getPageColumns']);
70  }
71 
76  public function ‪recordsGetTranslatedFromDefaultLanguage(): void
77  {
78  $params = [
79  'pageId' => 1,
80  'srcLanguageId' => 0,
81  'destLanguageId' => 1,
82  'uidList' => [1, 2, 3],
84  ];
85  $this->subject->_call('process', $params);
86  $this->‪assertAssertionDataSet('TranslatedFromDefault');
87  }
88 
93  {
94  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
95 
96  $params = [
97  'pageId' => 1,
98  'srcLanguageId' => 1,
99  'destLanguageId' => 2,
100  'uidList' => [4, 5, 6], // uids of tt_content-danish-language
102  ];
103  $this->subject->_call('process', $params);
104  $this->‪assertAssertionDataSet('TranslatedFromTranslation');
105  }
106 
110  public function ‪recordsGetCopiedFromDefaultLanguage(): void
111  {
112  $params = [
113  'pageId' => 1,
114  'srcLanguageId' => 0,
115  'destLanguageId' => 2,
116  'uidList' => [1, 2, 3],
118  ];
119  $this->subject->_call('process', $params);
120  $this->‪assertAssertionDataSet('CopiedFromDefault');
121  }
122 
126  public function ‪recordsGetCopiedFromAnotherLanguage(): void
127  {
128  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
129 
130  $params = [
131  'pageId' => 1,
132  'srcLanguageId' => 1,
133  'destLanguageId' => 2,
134  'uidList' => [4, 5, 6], // uids of tt_content-danish-language
136  ];
137  $this->subject->_call('process', $params);
138  $this->‪assertAssertionDataSet('CopiedFromTranslation');
139  }
140 
154  {
155  $params = [
156  'pageId' => 1,
157  'srcLanguageId' => 0,
158  'destLanguageId' => 1,
159  'uidList' => [1, 2, 3],
161  ];
162  $this->subject->_call('process', $params);
163 
164  // Create another content element in default language
165  $data = [
166  'tt_content' => [
167  'NEW123456' => [
168  'sys_language_uid' => 0,
169  'header' => 'Test content 2.5',
170  'pid' => -2,
171  'colPos' => 0,
172  ],
173  ],
174  ];
175  $dataHandler = new DataHandler();
176  $dataHandler->start($data, []);
177  $dataHandler->process_datamap();
178  $dataHandler->process_cmdmap();
179  $newContentElementUid = $dataHandler->substNEWwithIDs['NEW123456'];
180 
181  // Copy the new content element
182  $params = [
183  'pageId' => 1,
184  'srcLanguageId' => 0,
185  'destLanguageId' => 1,
186  'uidList' => [$newContentElementUid],
188  ];
189  $this->subject->_call('process', $params);
190  $this->‪assertAssertionDataSet('CreatedElementOrdering');
191  }
192 
196  public function ‪defaultLanguageIsFoundAsOriginLanguage(): void
197  {
198  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
199 
200  // Create another content element in default language
201  $data = [
202  'tt_content' => [
203  'NEW123456' => [
204  'sys_language_uid' => 0,
205  'header' => 'New content element',
206  'pid' => 1,
207  'colPos' => 0,
208  ],
209  ],
210  ];
211  $dataHandler = new ‪DataHandler();
212  $dataHandler->start($data, []);
213  $dataHandler->process_datamap();
214  $dataHandler->process_cmdmap();
215 
216  $request = (new ‪ServerRequest())->withQueryParams([
217  'pageId' => 1, // page uid, the records are stored on
218  'languageId' => 1 // current language id
219  ]);
220 
221  $usedLanguages = (string)$this->subject->getUsedLanguagesInPage($request)->getBody();
222  self::assertThat($usedLanguages, self::stringContains('"uid":0'));
223  }
224 
229  {
230  // Delete record 2 within workspace 1
231  $this->backendUser->workspace = 1;
232  $this->actionService->deleteRecord('tt_content', 2);
233 
234  $expectedRecords = [
235  '0' => [
236  ['uid' => 1],
237  ],
238  '1' => [
239  ['uid' => 3],
240  ],
241  ];
242 
243  $localizeSummary = $this->‪getReducedRecordLocalizeSummary();
244 
245  self::assertEquals($expectedRecords, $localizeSummary);
246  }
247 
252  {
253  // Move record 2 to page 2 within workspace 1
254  $this->backendUser->workspace = 1;
255  $this->actionService->moveRecord('tt_content', 2, 2);
256 
257  $expectedRecords = [
258  '0' => [
259  ['uid' => 1],
260  ],
261  '1' => [
262  ['uid' => 3],
263  ],
264  ];
265 
266  $localizeSummary = $this->‪getReducedRecordLocalizeSummary();
267 
268  self::assertEquals($expectedRecords, $localizeSummary);
269  }
270 
276  protected function ‪getReducedRecordLocalizeSummary(): array
277  {
278  $request = (new ‪ServerRequest())->withQueryParams([
279  'pageId' => 1, // page uid, the records are stored on
280  'destLanguageId' => 1, // destination language uid
281  'languageId' => 0 // source language uid
282  ]);
283 
284  $this->subject->method('getPageColumns')->willReturn([
285  0 => 'Column 0',
286  1 => 'Column 1',
287  ]);
288 
289  $recordLocalizeSummaryResponse = $this->subject->getRecordLocalizeSummary($request);
290 
291  // Reduce the fetched record summary to list of uids
292  if ($recordLocalizeSummary = json_decode((string)$recordLocalizeSummaryResponse->getBody(), true)) {
293  foreach ($recordLocalizeSummary['records'] as $colPos => $records) {
294  foreach ($records as $key => $record) {
295  $recordLocalizeSummary['records'][$colPos][$key] = array_intersect_key($record, ['uid' => '']);
296  }
297  }
298  }
299 
300  return $recordLocalizeSummary['records'];
301  }
302 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\setUpFrontendSite
‪setUpFrontendSite(int $pageId, array $additionalLanguages=[])
Definition: AbstractDataHandlerActionTestCase.php:143
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\setUp
‪setUp()
Definition: LocalizationControllerTest.php:54
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: LocalizationControllerTest.php:49
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering
‪copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering()
Definition: LocalizationControllerTest.php:148
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$backendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication $backendUser
Definition: LocalizationControllerTest.php:40
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$assertCleanReferenceIndex
‪bool $assertCleanReferenceIndex
Definition: LocalizationControllerTest.php:45
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
Definition: AbstractDataHandlerActionTestCase.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordLocalizeSummaryRespectsWorkspaceEncapsulationForDeletedRecords
‪recordLocalizeSummaryRespectsWorkspaceEncapsulationForDeletedRecords()
Definition: LocalizationControllerTest.php:223
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\defaultLanguageIsFoundAsOriginLanguage
‪defaultLanguageIsFoundAsOriginLanguage()
Definition: LocalizationControllerTest.php:191
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$assertionDataSetDirectory
‪string $assertionDataSetDirectory
Definition: LocalizationControllerTest.php:32
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest
Definition: LocalizationControllerTest.php:29
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController
Definition: LocalizationController.php:42
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$subject
‪LocalizationController PHPUnit Framework MockObject MockObject $subject
Definition: LocalizationControllerTest.php:36
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController\ACTION_LOCALIZE
‪const ACTION_LOCALIZE
Definition: LocalizationController.php:51
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\assertAssertionDataSet
‪assertAssertionDataSet($dataSetName)
Definition: AbstractDataHandlerActionTestCase.php:208
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetTranslatedFromDifferentTranslation
‪recordsGetTranslatedFromDifferentTranslation()
Definition: LocalizationControllerTest.php:87
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController\ACTION_COPY
‪const ACTION_COPY
Definition: LocalizationController.php:46
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetCopiedFromAnotherLanguage
‪recordsGetCopiedFromAnotherLanguage()
Definition: LocalizationControllerTest.php:121
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetCopiedFromDefaultLanguage
‪recordsGetCopiedFromDefaultLanguage()
Definition: LocalizationControllerTest.php:105
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page
Definition: LocalizationControllerTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\getReducedRecordLocalizeSummary
‪array getReducedRecordLocalizeSummary()
Definition: LocalizationControllerTest.php:271
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetTranslatedFromDefaultLanguage
‪recordsGetTranslatedFromDefaultLanguage()
Definition: LocalizationControllerTest.php:71
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordLocalizeSummaryRespectsWorkspaceEncapsulationForMovedRecords
‪recordLocalizeSummaryRespectsWorkspaceEncapsulationForMovedRecords()
Definition: LocalizationControllerTest.php:246