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