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