‪TYPO3CMS  9.5
LocalizationControllerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
24 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
25 
29 class ‪LocalizationControllerTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
30 {
34  protected ‪$assertionDataSetDirectory = 'typo3/sysext/backend/Tests/Functional/Controller/Page/Localization/CSV/DataSet/';
35 
39  protected ‪$subject;
40 
44  protected ‪$actionService;
45 
49  protected ‪$backendUser;
50 
54  protected ‪$coreExtensionsToLoad = ['workspaces'];
55 
59  protected function ‪setUp(): void
60  {
61  parent::setUp();
62 
63  $this->backendUser = $this->setUpBackendUserFromFixture(1);
64  $this->backendUser->workspace = 0;
65 
67  $this->actionService = GeneralUtility::makeInstance(ActionService::class);
68 
69  $this->importDataSet(__DIR__ . '/Fixtures/pages.xml');
70  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_language.xml');
71  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-default-language.xml');
72 
73  $this->subject = $this->getMockBuilder(LocalizationController::class)
74  ->setMethods(['getPageColumns'])
75  ->getMock();
76  }
77 
82  public function ‪recordsGetTranslatedFromDefaultLanguage(): void
83  {
84  $params = [
85  'pageId' => 1,
86  'srcLanguageId' => 0,
87  'destLanguageId' => 1,
88  'uidList' => [1, 2, 3],
90  ];
91  $this->callInaccessibleMethod($this->subject, 'process', $params);
92  $this->‪assertAssertionDataSet('TranslatedFromDefault');
93  }
94 
99  {
100  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
101 
102  $params = [
103  'pageId' => 1,
104  'srcLanguageId' => 1,
105  'destLanguageId' => 2,
106  'uidList' => [4, 5, 6], // uids of tt_content-danish-language
108  ];
109  $this->callInaccessibleMethod($this->subject, 'process', $params);
110  $this->‪assertAssertionDataSet('TranslatedFromTranslation');
111  }
112 
116  public function ‪recordsGetCopiedFromDefaultLanguage(): void
117  {
118  $params = [
119  'pageId' => 1,
120  'srcLanguageId' => 0,
121  'destLanguageId' => 2,
122  'uidList' => [1, 2, 3],
124  ];
125  $this->callInaccessibleMethod($this->subject, 'process', $params);
126  $this->‪assertAssertionDataSet('CopiedFromDefault');
127  }
128 
132  public function ‪recordsGetCopiedFromAnotherLanguage(): void
133  {
134  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
135 
136  $params = [
137  'pageId' => 1,
138  'srcLanguageId' => 1,
139  'destLanguageId' => 2,
140  'uidList' => [4, 5, 6], // uids of tt_content-danish-language
142  ];
143  $this->callInaccessibleMethod($this->subject, 'process', $params);
144  $this->‪assertAssertionDataSet('CopiedFromTranslation');
145  }
146 
160  {
161  $params = [
162  'pageId' => 1,
163  'srcLanguageId' => 0,
164  'destLanguageId' => 1,
165  'uidList' => [1, 2, 3],
167  ];
168  $this->callInaccessibleMethod($this->subject, 'process', $params);
169 
170  // Create another content element in default language
171  $data = [
172  'tt_content' => [
173  'NEW123456' => [
174  'sys_language_uid' => 0,
175  'header' => 'Test content 2.5',
176  'pid' => -2,
177  'colPos' => 0,
178  ],
179  ],
180  ];
181  $dataHandler = new DataHandler();
182  $dataHandler->start($data, []);
183  $dataHandler->process_datamap();
184  $dataHandler->process_cmdmap();
185  $newContentElementUid = $dataHandler->substNEWwithIDs['NEW123456'];
186 
187  // Copy the new content element
188  $params = [
189  'pageId' => 1,
190  'srcLanguageId' => 0,
191  'destLanguageId' => 1,
192  'uidList' => [$newContentElementUid],
194  ];
195  $this->callInaccessibleMethod($this->subject, 'process', $params);
196  $this->‪assertAssertionDataSet('CreatedElementOrdering');
197  }
198 
202  public function ‪defaultLanguageIsFoundAsOriginLanguage(): void
203  {
204  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
205 
206  // Create another content element in default language
207  $data = [
208  'tt_content' => [
209  'NEW123456' => [
210  'sys_language_uid' => 0,
211  'header' => 'New content element',
212  'pid' => 1,
213  'colPos' => 0,
214  ],
215  ],
216  ];
217  $dataHandler = new ‪DataHandler();
218  $dataHandler->start($data, []);
219  $dataHandler->process_datamap();
220  $dataHandler->process_cmdmap();
221 
222  $request = (new ‪ServerRequest())->withQueryParams([
223  'pageId' => 1, // page uid, the records are stored on
224  'languageId' => 1 // current language id
225  ]);
226 
227  $usedLanguages = (string)$this->subject->getUsedLanguagesInPage($request)->getBody();
228  $this->assertThat($usedLanguages, $this->stringContains('"uid":0'));
229  }
230 
235  {
236  // Delete record 2 within workspace 1
237  $this->backendUser->workspace = 1;
238  $this->actionService->deleteRecord('tt_content', 2);
239 
240  $expectedRecords = [
241  '0' => [
242  ['uid' => 1],
243  ],
244  '1' => [
245  ['uid' => 3],
246  ],
247  ];
248 
249  $localizeSummary = $this->‪getReducedRecordLocalizeSummary();
250 
251  $this->assertEquals($expectedRecords, $localizeSummary);
252  }
253 
258  {
259  // Move record 2 to page 2 within workspace 1
260  $this->backendUser->workspace = 1;
261  $this->actionService->moveRecord('tt_content', 2, 2);
262 
263  $expectedRecords = [
264  '0' => [
265  ['uid' => 1],
266  ],
267  '1' => [
268  ['uid' => 3],
269  ],
270  ];
271 
272  $localizeSummary = $this->‪getReducedRecordLocalizeSummary();
273 
274  $this->assertEquals($expectedRecords, $localizeSummary);
275  }
276 
282  protected function ‪getReducedRecordLocalizeSummary(): array
283  {
284  $request = (new ‪ServerRequest())->withQueryParams([
285  'pageId' => 1, // page uid, the records are stored on
286  'destLanguageId' => 1, // destination language uid
287  'languageId' => 0 // source language uid
288  ]);
289 
290  $this->subject->method('getPageColumns')->willReturn([
291  0 => 'Column 0',
292  1 => 'Column 1',
293  ]);
294 
295  $recordLocalizeSummaryResponse = $this->subject->getRecordLocalizeSummary($request);
296 
297  // Reduce the fetched record summary to list of uids
298  if ($recordLocalizeSummary = json_decode((string)$recordLocalizeSummaryResponse->getBody(), true)) {
299  foreach ($recordLocalizeSummary['records'] as $colPos => $records) {
300  foreach ($records as $key => $record) {
301  $recordLocalizeSummary['records'][$colPos][$key] = array_intersect_key($record, ['uid' => '']);
302  }
303  }
304  }
305 
306  return $recordLocalizeSummary['records'];
307  }
308 
312  protected function ‪assertAssertionDataSet(string $dataSetName)
313  {
314  $fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
315  $fileName = GeneralUtility::getFileAbsFileName($fileName);
316  $this->assertCSVDataSet($fileName);
317  }
318 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪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\$actionService
‪TYPO3 TestingFramework Core Functional Framework DataHandling ActionService $actionService
Definition: LocalizationControllerTest.php:41
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering
‪copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering()
Definition: LocalizationControllerTest.php:154
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$backendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication $backendUser
Definition: LocalizationControllerTest.php:45
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordLocalizeSummaryRespectsWorkspaceEncapsulationForDeletedRecords
‪recordLocalizeSummaryRespectsWorkspaceEncapsulationForDeletedRecords()
Definition: LocalizationControllerTest.php:229
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\defaultLanguageIsFoundAsOriginLanguage
‪defaultLanguageIsFoundAsOriginLanguage()
Definition: LocalizationControllerTest.php:197
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$assertionDataSetDirectory
‪string $assertionDataSetDirectory
Definition: LocalizationControllerTest.php:33
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest
Definition: LocalizationControllerTest.php:30
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController
Definition: LocalizationController.php:39
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:35
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\assertAssertionDataSet
‪assertAssertionDataSet(string $dataSetName)
Definition: LocalizationControllerTest.php:307
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController\ACTION_LOCALIZE
‪const ACTION_LOCALIZE
Definition: LocalizationController.php:48
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetTranslatedFromDifferentTranslation
‪recordsGetTranslatedFromDifferentTranslation()
Definition: LocalizationControllerTest.php:93
‪TYPO3\CMS\Backend\Controller\Page\LocalizationController\ACTION_COPY
‪const ACTION_COPY
Definition: LocalizationController.php:43
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetCopiedFromAnotherLanguage
‪recordsGetCopiedFromAnotherLanguage()
Definition: LocalizationControllerTest.php:127
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetCopiedFromDefaultLanguage
‪recordsGetCopiedFromDefaultLanguage()
Definition: LocalizationControllerTest.php:111
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page
Definition: LocalizationControllerTest.php:4
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\getReducedRecordLocalizeSummary
‪array getReducedRecordLocalizeSummary()
Definition: LocalizationControllerTest.php:277
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\$subject
‪LocalizationController PHPUnit_Framework_MockObject_MockObject $subject
Definition: LocalizationControllerTest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordsGetTranslatedFromDefaultLanguage
‪recordsGetTranslatedFromDefaultLanguage()
Definition: LocalizationControllerTest.php:77
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\LocalizationControllerTest\recordLocalizeSummaryRespectsWorkspaceEncapsulationForMovedRecords
‪recordLocalizeSummaryRespectsWorkspaceEncapsulationForMovedRecords()
Definition: LocalizationControllerTest.php:252
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986