‪TYPO3CMS  ‪main
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 
25 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪LocalizationControllerTest extends FunctionalTestCase
29 {
31 
32  protected array ‪$coreExtensionsToLoad = ['workspaces'];
33 
34  protected const ‪LANGUAGE_PRESETS = [
35  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
36  'DA' => ['id' => 1, 'title' => 'Dansk', 'locale' => 'da_DK.UTF8'],
37  'DE' => ['id' => 2, 'title' => 'Deutsch', 'locale' => 'de_DE.UTF-8'],
38  ];
39 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv');
44  $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
45  $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content-default-language.csv');
47  'test',
48  $this->‪buildSiteConfiguration(1),
49  [
50  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
51  $this->‪buildLanguageConfiguration('DA', '/da/'),
52  $this->‪buildLanguageConfiguration('DE', '/de'),
53  ]
54  );
55  }
56 
60  public function ‪recordsGetTranslatedFromDefaultLanguage(): void
61  {
62  $backendUser = $this->setUpBackendUser(1);
63  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
64  $params = [
65  'pageId' => 1,
66  'srcLanguageId' => 0,
67  'destLanguageId' => 1,
68  'uidList' => [1, 2, 3],
70  ];
71  $subject = $this->getAccessibleMock(LocalizationController::class, null);
72  $subject->_call('process', $params);
73  $this->assertCSVDataSet(__DIR__ . '/Localization/CSV/DataSet/TranslatedFromDefault.csv');
74  }
75 
80  {
81  $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content-danish-language.csv');
82  $backendUser = $this->setUpBackendUser(1);
83  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
84  $params = [
85  'pageId' => 1,
86  'srcLanguageId' => 1,
87  'destLanguageId' => 2,
88  'uidList' => [4, 5, 6], // uids of tt_content-danish-language
90  ];
91  $subject = $this->getAccessibleMock(LocalizationController::class, null);
92  $subject->_call('process', $params);
93  $this->assertCSVDataSet(__DIR__ . '/Localization/CSV/DataSet/TranslatedFromTranslation.csv');
94  }
95 
99  public function ‪recordsGetCopiedFromDefaultLanguage(): void
100  {
101  $backendUser = $this->setUpBackendUser(1);
102  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
103  $params = [
104  'pageId' => 1,
105  'srcLanguageId' => 0,
106  'destLanguageId' => 2,
107  'uidList' => [1, 2, 3],
109  ];
110  $subject = $this->getAccessibleMock(LocalizationController::class, null);
111  $subject->_call('process', $params);
112  $this->assertCSVDataSet(__DIR__ . '/Localization/CSV/DataSet/CopiedFromDefault.csv');
113  }
114 
118  public function ‪recordsGetCopiedFromAnotherLanguage(): void
119  {
120  $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content-danish-language.csv');
121  $backendUser = $this->setUpBackendUser(1);
122  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
123  $params = [
124  'pageId' => 1,
125  'srcLanguageId' => 1,
126  'destLanguageId' => 2,
127  'uidList' => [4, 5, 6], // uids of tt_content-danish-language
129  ];
130  $subject = $this->getAccessibleMock(LocalizationController::class, null);
131  $subject->_call('process', $params);
132  $this->assertCSVDataSet(__DIR__ . '/Localization/CSV/DataSet/CopiedFromTranslation.csv');
133  }
134 
148  {
149  $backendUser = $this->setUpBackendUser(1);
150  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
151  $params = [
152  'pageId' => 1,
153  'srcLanguageId' => 0,
154  'destLanguageId' => 1,
155  'uidList' => [1, 2, 3],
157  ];
158  $subject = $this->getAccessibleMock(LocalizationController::class, null);
159  $subject->_call('process', $params);
160  // Create another content element in default language
161  $data = [
162  'tt_content' => [
163  'NEW123456' => [
164  'sys_language_uid' => 0,
165  'header' => 'Test content 2.5',
166  'pid' => -2,
167  'colPos' => 0,
168  ],
169  ],
170  ];
171  $dataHandler = new DataHandler();
172  $dataHandler->start($data, []);
173  $dataHandler->process_datamap();
174  $dataHandler->process_cmdmap();
175  $newContentElementUid = $dataHandler->substNEWwithIDs['NEW123456'];
176  // Copy the new content element
177  $params = [
178  'pageId' => 1,
179  'srcLanguageId' => 0,
180  'destLanguageId' => 1,
181  'uidList' => [$newContentElementUid],
183  ];
184  $subject->_call('process', $params);
185  $this->assertCSVDataSet(__DIR__ . '/Localization/CSV/DataSet/CreatedElementOrdering.csv');
186  }
187 
191  public function ‪defaultLanguageIsFoundAsOriginLanguage(): void
192  {
193  $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content-danish-language.csv');
194  $backendUser = $this->setUpBackendUser(1);
195  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
196  // Create another content element in default language
197  $data = [
198  'tt_content' => [
199  'NEW123456' => [
200  'sys_language_uid' => 0,
201  'header' => 'New content element',
202  'pid' => 1,
203  'colPos' => 0,
204  ],
205  ],
206  ];
207  $dataHandler = new DataHandler();
208  $dataHandler->start($data, []);
209  $dataHandler->process_datamap();
210  $dataHandler->process_cmdmap();
211  $request = (new ServerRequest())->withQueryParams([
212  'pageId' => 1, // page uid, the records are stored on
213  'languageId' => 1, // current language id
214  ]);
215  $subject = $this->getAccessibleMock(LocalizationController::class, null);
216  $usedLanguages = (string)$subject->getUsedLanguagesInPage($request)->getBody();
217  self::assertThat($usedLanguages, self::stringContains('"uid":0'));
218  }
223  {
224  $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content-default-language-deleted-element.csv');
225  $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content-danish-language-deleted-source.csv');
226  $backendUser = $this->setUpBackendUser(1);
227  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
228  $request = (new ServerRequest())->withQueryParams([
229  'pageId' => 2, // page uid, the records are stored on
230  'languageId' => 1, // current language id
231  ]);
232  $subject = $this->getAccessibleMock(LocalizationController::class, null);
233  $usedLanguages = (string)$subject->getUsedLanguagesInPage($request)->getBody();
234  self::assertThat($usedLanguages, self::stringContains('"uid":0'));
235  }
236 
241  {
242  // Delete record 2 within workspace 1
243  $backendUser = $this->setUpBackendUser(1);
244  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
245  $backendUser->workspace = 1;
246  $actionService = new ActionService();
247  $actionService->deleteRecord('tt_content', 2);
248  $expectedRecords = [
249  '0' => [
250  ['uid' => 1],
251  ],
252  '1' => [
253  ['uid' => 3],
254  ],
255  ];
256  $request = (new ServerRequest())->withQueryParams([
257  'pageId' => 1, // page uid, the records are stored on
258  'destLanguageId' => 1, // destination language uid
259  'languageId' => 0, // source language uid
260  ]);
261  $subject = $this->getAccessibleMock(LocalizationController::class, ['getPageColumns']);
262  $subject->method('getPageColumns')->willReturn([
263  0 => 'Column 0',
264  1 => 'Column 1',
265  ]);
266  $recordLocalizeSummaryResponse = $subject->getRecordLocalizeSummary($request);
267  // Reduce the fetched record summary to list of uids
268  if ($recordLocalizeSummary = json_decode((string)$recordLocalizeSummaryResponse->getBody(), true)) {
269  foreach ($recordLocalizeSummary['records'] as $colPos => $records) {
270  foreach ($records as $key => ‪$record) {
271  $recordLocalizeSummary['records'][$colPos][$key] = array_intersect_key(‪$record, ['uid' => '']);
272  }
273  }
274  }
275  $localizeSummary = $recordLocalizeSummary['records'];
276  self::assertEquals($expectedRecords, $localizeSummary);
277  }
278 
283  {
284  // Move record 2 to page 2 within workspace 1
285  $backendUser = $this->setUpBackendUser(1);
286  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
287  $backendUser->workspace = 1;
288  $actionService = new ActionService();
289  $actionService->moveRecord('tt_content', 2, 2);
290  $expectedRecords = [
291  '0' => [
292  ['uid' => 1],
293  ],
294  '1' => [
295  ['uid' => 3],
296  ],
297  ];
298  $request = (new ServerRequest())->withQueryParams([
299  'pageId' => 1, // page uid, the records are stored on
300  'destLanguageId' => 1, // destination language uid
301  'languageId' => 0, // source language uid
302  ]);
303  $subject = $this->getAccessibleMock(LocalizationController::class, ['getPageColumns']);
304  $subject->method('getPageColumns')->willReturn([
305  0 => 'Column 0',
306  1 => 'Column 1',
307  ]);
308  $recordLocalizeSummaryResponse = $subject->getRecordLocalizeSummary($request);
309  // Reduce the fetched record summary to list of uids
310  if ($recordLocalizeSummary = json_decode((string)$recordLocalizeSummaryResponse->getBody(), true)) {
311  foreach ($recordLocalizeSummary['records'] as $colPos => $records) {
312  foreach ($records as $key => ‪$record) {
313  $recordLocalizeSummary['records'][$colPos][$key] = array_intersect_key(‪$record, ['uid' => '']);
314  }
315  }
316  }
317  $localizeSummary = $recordLocalizeSummary['records'];
318  self::assertEquals($expectedRecords, $localizeSummary);
319  }
320 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:94
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:116
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\setUp
‪setUp()
Definition: LocalizationControllerTest.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: LocalizationControllerTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:96
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering
‪copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering()
Definition: LocalizationControllerTest.php:146
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordLocalizeSummaryRespectsWorkspaceEncapsulationForDeletedRecords
‪recordLocalizeSummaryRespectsWorkspaceEncapsulationForDeletedRecords()
Definition: LocalizationControllerTest.php:239
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\defaultLanguageIsFoundAsOriginLanguage
‪defaultLanguageIsFoundAsOriginLanguage()
Definition: LocalizationControllerTest.php:190
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest
Definition: LocalizationControllerTest.php:29
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController
Definition: LocalizationController.php:43
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\deletedDefaultLanguageItemIsHandledAsIfNoRecordsExistAndReturnsAllOriginLanguages
‪deletedDefaultLanguageItemIsHandledAsIfNoRecordsExistAndReturnsAllOriginLanguages()
Definition: LocalizationControllerTest.php:221
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController\ACTION_LOCALIZE
‪const ACTION_LOCALIZE
Definition: LocalizationController.php:52
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: LocalizationControllerTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:106
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetTranslatedFromDifferentTranslation
‪recordsGetTranslatedFromDifferentTranslation()
Definition: LocalizationControllerTest.php:78
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController\ACTION_COPY
‪const ACTION_COPY
Definition: LocalizationController.php:47
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetCopiedFromAnotherLanguage
‪recordsGetCopiedFromAnotherLanguage()
Definition: LocalizationControllerTest.php:117
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetCopiedFromDefaultLanguage
‪recordsGetCopiedFromDefaultLanguage()
Definition: LocalizationControllerTest.php:98
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page
Definition: LocalizationControllerTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetTranslatedFromDefaultLanguage
‪recordsGetTranslatedFromDefaultLanguage()
Definition: LocalizationControllerTest.php:59
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordLocalizeSummaryRespectsWorkspaceEncapsulationForMovedRecords
‪recordLocalizeSummaryRespectsWorkspaceEncapsulationForMovedRecords()
Definition: LocalizationControllerTest.php:281