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