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