‪TYPO3CMS  11.5
DatabaseLanguageRowsTest.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;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Prophecy\Prophecy\ObjectProphecy;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪DatabaseLanguageRowsTest extends UnitTestCase
34 {
35  use ProphecyTrait;
36 
40  protected MockObject ‪$subject;
41 
43  protected ObjectProphecy ‪$beUserProphecy;
44 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48  $this->beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
50 
51  $this->subject = $this->getMockBuilder(DatabaseLanguageRows::class)
52  ->onlyMethods(['getRecordWorkspaceOverlay'])
53  ->getMock();
54  }
55 
60  {
61  $input = [
62  'tableName' => 'tt_content',
63  'databaseRow' => [
64  'uid' => 42,
65  'text' => 'bar',
66  ],
67  'processedTca' => [
68  'ctrl' => [],
69  'columns' => [],
70  ],
71  ];
72  self::assertEquals($input, $this->subject->addData($input));
73  }
74 
79  {
80  $input = [
81  'tableName' => 'tt_content',
82  'databaseRow' => [
83  'uid' => 42,
84  'text' => 'localized text',
85  'sys_language_uid' => 2,
86  'l10n_parent' => 23,
87  ],
88  'processedTca' => [
89  'ctrl' => [
90  'languageField' => 'sys_language_uid',
91  'transOrigPointerField' => 'l10n_parent',
92  ],
93  ],
94  ];
95 
96  $this->subject->expects(self::once())->method('getRecordWorkspaceOverlay')->willReturn([]);
97 
98  $this->expectException(DatabaseDefaultLanguageException::class);
99  $this->expectExceptionCode(1438249426);
100 
101  $this->subject->addData($input);
102  }
103 
107  public function ‪addDataSetsDefaultLanguageRow(): void
108  {
109  $input = [
110  'tableName' => 'tt_content',
111  'databaseRow' => [
112  'uid' => 42,
113  'text' => 'localized text',
114  'sys_language_uid' => 2,
115  'l10n_parent' => 23,
116  ],
117  'processedTca' => [
118  'ctrl' => [
119  'languageField' => 'sys_language_uid',
120  'transOrigPointerField' => 'l10n_parent',
121  ],
122  ],
123  ];
124 
125  $defaultLanguageRow = [
126  'uid' => 23,
127  'pid' => 123,
128  'text' => 'default language text',
129  'sys_language_uid' => 0,
130  ];
131 
132  $this->subject->expects(self::once())->method('getRecordWorkspaceOverlay')->willReturn($defaultLanguageRow);
133 
134  $expected = $input;
135  $expected['defaultLanguageRow'] = $defaultLanguageRow;
136 
137  self::assertEquals($expected, $this->subject->addData($input));
138  }
139 
143  public function ‪addDataSetsDiffSourceFieldIfGiven(): void
144  {
145  $diffSource = [
146  'uid' => 42,
147  'text' => 'field content of default lang record when lang overlay was created',
148  ];
149 
150  $input = [
151  'tableName' => 'tt_content',
152  'databaseRow' => [
153  'uid' => 42,
154  'text' => 'localized text',
155  'sys_language_uid' => 2,
156  'l10n_parent' => 23,
157  'l10n_diffsource' => json_encode($diffSource),
158  ],
159  'processedTca' => [
160  'ctrl' => [
161  'languageField' => 'sys_language_uid',
162  'transOrigPointerField' => 'l10n_parent',
163  'transOrigDiffSourceField' => 'l10n_diffsource',
164  ],
165  ],
166  'defaultLanguageRow' => null,
167  ];
168 
169  $defaultLanguageRow = [
170  'uid' => 23,
171  'pid' => 123,
172  'text' => 'default language text',
173  'sys_language_uid' => 0,
174  ];
175 
176  $this->subject->expects(self::once())->method('getRecordWorkspaceOverlay')->willReturn($defaultLanguageRow);
177 
178  $expected = $input;
179  $expected['defaultLanguageRow'] = $defaultLanguageRow;
180  $expected['defaultLanguageDiffRow']['tt_content:42'] = $diffSource;
181 
182  self::assertEquals($expected, $this->subject->addData($input));
183  }
184 
189  {
190  $input = [
191  'tableName' => 'tt_content',
192  'databaseRow' => [
193  'uid' => 42,
194  'text' => 'localized text',
195  'sys_language_uid' => 2,
196  'l10n_parent' => 23,
197  ],
198  'processedTca' => [
199  'ctrl' => [
200  'languageField' => 'sys_language_uid',
201  'transOrigPointerField' => 'l10n_parent',
202  ],
203  ],
204  'userTsConfig' => [
205  'options.' => [
206  'additionalPreviewLanguages' => '3',
207  ],
208  ],
209  'systemLanguageRows' => [
210  0 => [
211  'uid' => 0,
212  'title' => 'Default Language',
213  'iso' => 'DEV',
214  ],
215  3 => [
216  'uid' => 3,
217  'title' => 'french',
218  'iso' => 'fr',
219  ],
220  ],
221  'defaultLanguageRow' => null,
222  'additionalLanguageRows' => [],
223  ];
224 
225  $translationResult = [
226  'translations' => [
227  3 => [
228  'uid' => 43,
229  'pid' => 32,
230  ],
231  ],
232  ];
233  // For BackendUtility::getRecord()
234  ‪$GLOBALS['TCA']['tt_content'] = ['foo'];
235  $recordWsolResult = [
236  'uid' => 43,
237  'pid' => 32,
238  'text' => 'localized text in french',
239  ];
240 
241  $defaultLanguageRow = [
242  'uid' => 23,
243  'pid' => 32,
244  'text' => 'default language text',
245  'sys_language_uid' => 0,
246  ];
247 
248  $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
249  GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
250  $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
251 
252  // The second call is the real check: The "additional overlay" should be fetched
253  $this->subject->expects(self::exactly(2))
254  ->method('getRecordWorkspaceOverlay')
255  ->withConsecutive(['tt_content', 23], ['tt_content', 43])
256  ->willReturnOnConsecutiveCalls($defaultLanguageRow, $recordWsolResult);
257 
258  $expected = $input;
259  $expected['defaultLanguageRow'] = $defaultLanguageRow;
260  $expected['additionalLanguageRows'] = [
261  3 => [
262  'uid' => 43,
263  'pid' => 32,
264  'text' => 'localized text in french',
265  ],
266  ];
267 
268  self::assertEquals($expected, $this->subject->addData($input));
269  }
270 
275  {
276  $input = [
277  'tableName' => 'tt_content',
278  'databaseRow' => [
279  'uid' => 42,
280  'text' => 'localized text',
281  'sys_language_uid' => 2,
282  'l10n_parent' => 23,
283  ],
284  'processedTca' => [
285  'ctrl' => [
286  'languageField' => 'sys_language_uid',
287  'transOrigPointerField' => 'l10n_parent',
288  ],
289  ],
290  'userTsConfig' => [
291  'options.' => [
292  'additionalPreviewLanguages' => '2,3',
293  ],
294  ],
295  'systemLanguageRows' => [
296  0 => [
297  'uid' => 0,
298  'title' => 'Default Language',
299  'iso' => 'DEV',
300  ],
301  2 => [
302  'uid' => 2,
303  'title' => 'dansk',
304  'iso' => 'dk,',
305  ],
306  3 => [
307  'uid' => 3,
308  'title' => 'french',
309  'iso' => 'fr',
310  ],
311  ],
312  'defaultLanguageRow' => null,
313  'additionalLanguageRows' => [],
314  ];
315 
316  $translationResult = [
317  'translations' => [
318  3 => [
319  'uid' => 43,
320  ],
321  ],
322  ];
323  // For BackendUtility::getRecord()
324  ‪$GLOBALS['TCA']['tt_content'] = ['foo'];
325  $recordWsolResult = [
326  'uid' => 43,
327  'pid' => 32,
328  'text' => 'localized text in french',
329  ];
330 
331  $defaultLanguageRow = [
332  'uid' => 23,
333  'pid' => 32,
334  'text' => 'default language text',
335  'sys_language_uid' => 0,
336  ];
337 
338  $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
339  GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
340  $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
341  $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
342 
343  // The second call is the real check: The "additional overlay" should be fetched
344  $this->subject->expects(self::exactly(2))
345  ->method('getRecordWorkspaceOverlay')
346  ->withConsecutive(['tt_content', 23], ['tt_content', 43])
347  ->willReturnOnConsecutiveCalls($defaultLanguageRow, $recordWsolResult);
348 
349  $expected = $input;
350  $expected['defaultLanguageRow'] = $defaultLanguageRow;
351  $expected['additionalLanguageRows'] = [
352  3 => [
353  'uid' => 43,
354  'pid' => 32,
355  'text' => 'localized text in french',
356  ],
357  ];
358 
359  self::assertEquals($expected, $this->subject->addData($input));
360  }
361 
365  public function ‪addDataSetsSourceLanguageRow(): void
366  {
367  $input = [
368  'tableName' => 'tt_content',
369  'databaseRow' => [
370  'uid' => 42,
371  'text' => 'localized text',
372  'sys_language_uid' => 3,
373  'l10n_parent' => 23,
374  'l10n_source' => 24,
375  ],
376  'processedTca' => [
377  'ctrl' => [
378  'languageField' => 'sys_language_uid',
379  'transOrigPointerField' => 'l10n_parent',
380  'translationSource' => 'l10n_source',
381  ],
382  ],
383  'systemLanguageRows' => [
384  0 => [
385  'uid' => 0,
386  'title' => 'Default Language',
387  'iso' => 'DEV',
388  ],
389  2 => [
390  'uid' => 2,
391  'title' => 'dansk',
392  'iso' => 'dk,',
393  ],
394  3 => [
395  'uid' => 3,
396  'title' => 'french',
397  'iso' => 'fr',
398  ],
399  ],
400  'defaultLanguageRow' => null,
401  'sourceLanguageRow' => null,
402  'additionalLanguageRows' => [],
403  ];
404 
405  // For BackendUtility::getRecord()
406  ‪$GLOBALS['TCA']['tt_content'] = ['foo'];
407  $sourceLanguageRow = [
408  'uid' => 24,
409  'pid' => 32,
410  'text' => 'localized text in dank',
411  'sys_language_uid' => 2,
412  ];
413  $defaultLanguageRow = [
414  'uid' => 23,
415  'pid' => 32,
416  'text' => 'default language text',
417  'sys_language_uid' => 0,
418  ];
419  $this->subject->expects(self::exactly(2))
420  ->method('getRecordWorkspaceOverlay')
421  ->withConsecutive(['tt_content', 23], ['tt_content', 24])
422  ->willReturn($defaultLanguageRow, $sourceLanguageRow);
423 
424  $expected = $input;
425  $expected['defaultLanguageRow'] = $defaultLanguageRow;
426  $expected['sourceLanguageRow'] = $sourceLanguageRow;
427 
428  self::assertEquals($expected, $this->subject->addData($input));
429  }
430 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataSetsDefaultLanguageRow
‪addDataSetsDefaultLanguageRow()
Definition: DatabaseLanguageRowsTest.php:106
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataThrowsExceptionIfDefaultOfLocalizedRecordIsNotFound
‪addDataThrowsExceptionIfDefaultOfLocalizedRecordIsNotFound()
Definition: DatabaseLanguageRowsTest.php:77
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\$beUserProphecy
‪ObjectProphecy $beUserProphecy
Definition: DatabaseLanguageRowsTest.php:42
‪TYPO3\CMS\Backend\Form\Exception\DatabaseDefaultLanguageException
Definition: DatabaseDefaultLanguageException.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataSetsDiffSourceFieldIfGiven
‪addDataSetsDiffSourceFieldIfGiven()
Definition: DatabaseLanguageRowsTest.php:142
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\setUp
‪setUp()
Definition: DatabaseLanguageRowsTest.php:44
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest
Definition: DatabaseLanguageRowsTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataSetsSourceLanguageRow
‪addDataSetsSourceLanguageRow()
Definition: DatabaseLanguageRowsTest.php:364
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows
‪addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows()
Definition: DatabaseLanguageRowsTest.php:273
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:37
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseLanguageRows
Definition: DatabaseLanguageRows.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataSetsAdditionalLanguageRowsIfRequestedInUserTypoScript
‪addDataSetsAdditionalLanguageRowsIfRequestedInUserTypoScript()
Definition: DatabaseLanguageRowsTest.php:187
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\addDataReturnsUnchangedResultIfTableProvidesNoTranslations
‪addDataReturnsUnchangedResultIfTableProvidesNoTranslations()
Definition: DatabaseLanguageRowsTest.php:58
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseLanguageRowsTest\$subject
‪MockObject $subject
Definition: DatabaseLanguageRowsTest.php:39