TYPO3  7.6
DatabaseLanguageRowsTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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;
18 use TYPO3\CMS\Backend\Form\Exception\DatabaseDefaultLanguageException;
22 use TYPO3\CMS\Core\Tests\UnitTestCase;
24 
28 class DatabaseLanguageRowsTest extends UnitTestCase
29 {
33  protected $subject;
34 
38  protected $dbProphecy;
39 
40  protected function setUp()
41  {
42  $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
43  $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
44 
45  $this->subject = new DatabaseLanguageRows();
46  }
47 
52  {
53  $input = [
54  'tableName' => 'tt_content',
55  'databaseRow' => [
56  'uid' => 42,
57  'text' => 'bar',
58  ],
59  'processedTca' => [
60  'ctrl' => array(),
61  'columns' => array(),
62  ],
63  ];
64  $this->assertEquals($input, $this->subject->addData($input));
65  }
66 
71  {
72  $input = [
73  'tableName' => 'tt_content',
74  'databaseRow' => [
75  'uid' => 42,
76  'text' => 'localized text',
77  'sys_language_uid' => 2,
78  'l10n_parent' => 23,
79  ],
80  'processedTca' => [
81  'ctrl' => array(
82  'languageField' => 'sys_language_uid',
83  'transOrigPointerField' => 'l10n_parent',
84  ),
85  ],
86  ];
87 
88  // Needed for BackendUtility::getRecord
89  $GLOBALS['TCA']['tt_content'] = array('foo');
90  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn(null);
91 
92  $this->setExpectedException(DatabaseDefaultLanguageException::class, $this->anything(), 1438249426);
93 
94  $this->subject->addData($input);
95  }
96 
101  {
102  $input = [
103  'tableName' => 'tt_content',
104  'databaseRow' => [
105  'uid' => 42,
106  'text' => 'localized text',
107  'sys_language_uid' => 2,
108  'l10n_parent' => 23,
109  ],
110  'processedTca' => [
111  'ctrl' => array(
112  'languageField' => 'sys_language_uid',
113  'transOrigPointerField' => 'l10n_parent',
114  ),
115  ],
116  ];
117 
118  $defaultLanguageRow = [
119  'uid' => 23,
120  'text' => 'default language text',
121  'sys_language_uid' => 0,
122  ];
123  // Needed for BackendUtility::getRecord
124  $GLOBALS['TCA']['tt_content'] = array('foo');
125  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
126 
127  $expected = $input;
128  $expected['defaultLanguageRow'] = $defaultLanguageRow;
129 
130  $this->assertEquals($expected, $this->subject->addData($input));
131  }
132 
137  {
138  $diffSource = [
139  'uid' => 42,
140  'text' => 'field content of default lang record when lang overlay was created',
141  ];
142 
143  $input = [
144  'tableName' => 'tt_content',
145  'databaseRow' => [
146  'uid' => 42,
147  'text' => 'localized text',
148  'sys_language_uid' => 2,
149  'l10n_parent' => 23,
150  'l10n_diffsource' => serialize($diffSource),
151  ],
152  'processedTca' => [
153  'ctrl' => [
154  'languageField' => 'sys_language_uid',
155  'transOrigPointerField' => 'l10n_parent',
156  'transOrigDiffSourceField' => 'l10n_diffsource',
157  ],
158  ],
159  'defaultLanguageRow' => null,
160  ];
161 
162  $defaultLanguageRow = [
163  'uid' => 23,
164  'text' => 'default language text',
165  'sys_language_uid' => 0,
166  ];
167  // Needed for BackendUtility::getRecord
168  $GLOBALS['TCA']['tt_content'] = array('foo');
169  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
170 
171  $expected = $input;
172  $expected['defaultLanguageRow'] = $defaultLanguageRow;
173  $expected['defaultLanguageDiffRow'] = $diffSource;
174 
175  $this->assertEquals($expected, $this->subject->addData($input));
176  }
177 
181  public function addDataSetsAdditionalLanguageRowsIfRequestedInUserTypoScript()
182  {
183  $input = [
184  'tableName' => 'tt_content',
185  'databaseRow' => [
186  'uid' => 42,
187  'text' => 'localized text',
188  'sys_language_uid' => 2,
189  'l10n_parent' => 23,
190  ],
191  'processedTca' => [
192  'ctrl' => [
193  'languageField' => 'sys_language_uid',
194  'transOrigPointerField' => 'l10n_parent',
195  ],
196  ],
197  'userTsConfig' => [
198  'options.' => [
199  'additionalPreviewLanguages' => '3',
200  ],
201  ],
202  'systemLanguageRows' => [
203  0 => [
204  'uid' => 0,
205  'title' => 'Default Language',
206  'iso' => 'DEV',
207  ],
208  3 => [
209  'uid' => 3,
210  'title' => 'french',
211  'iso' => 'fr',
212  ],
213  ],
214  'defaultLanguageRow' => null,
215  'additionalLanguageRows' => [],
216  ];
217 
218  $translationResult = [
219  'translations' => [
220  3 => [
221  'uid' => 43,
222  ],
223  ],
224  ];
225  // For BackendUtility::getRecord()
226  $GLOBALS['TCA']['tt_content'] = array('foo');
227  $recordWsolResult = [
228  'uid' => 43,
229  'text' => 'localized text in french',
230  ];
231 
232  $defaultLanguageRow = [
233  'uid' => 23,
234  'text' => 'default language text',
235  'sys_language_uid' => 0,
236  ];
237  // Needed for BackendUtility::getRecord
238  $GLOBALS['TCA']['tt_content'] = array('foo');
239  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
240 
242  $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
243  GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
244  $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
245 
246  // This is the real check: The "additional overlay" should be fetched
247  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
248 
249  $expected = $input;
250  $expected['defaultLanguageRow'] = $defaultLanguageRow;
251  $expected['additionalLanguageRows'] = [
252  3 => [
253  'uid' => 43,
254  'text' => 'localized text in french',
255  ],
256  ];
257 
258  $this->assertEquals($expected, $this->subject->addData($input));
259  }
260 
264  public function addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows()
265  {
266  $input = [
267  'tableName' => 'tt_content',
268  'databaseRow' => [
269  'uid' => 42,
270  'text' => 'localized text',
271  'sys_language_uid' => 2,
272  'l10n_parent' => 23,
273  ],
274  'processedTca' => [
275  'ctrl' => [
276  'languageField' => 'sys_language_uid',
277  'transOrigPointerField' => 'l10n_parent',
278  ],
279  ],
280  'userTsConfig' => [
281  'options.' => [
282  'additionalPreviewLanguages' => '2,3',
283  ],
284  ],
285  'systemLanguageRows' => [
286  0 => [
287  'uid' => 0,
288  'title' => 'Default Language',
289  'iso' => 'DEV',
290  ],
291  2 => [
292  'uid' => 2,
293  'title' => 'dansk',
294  'iso' => 'dk,'
295  ],
296  3 => [
297  'uid' => 3,
298  'title' => 'french',
299  'iso' => 'fr',
300  ],
301  ],
302  'defaultLanguageRow' => null,
303  'additionalLanguageRows' => [],
304  ];
305 
306  $translationResult = [
307  'translations' => [
308  3 => [
309  'uid' => 43,
310  ],
311  ],
312  ];
313  // For BackendUtility::getRecord()
314  $GLOBALS['TCA']['tt_content'] = array('foo');
315  $recordWsolResult = [
316  'uid' => 43,
317  'text' => 'localized text in french',
318  ];
319 
320  $defaultLanguageRow = [
321  'uid' => 23,
322  'text' => 'default language text',
323  'sys_language_uid' => 0,
324  ];
325  // Needed for BackendUtility::getRecord
326  $GLOBALS['TCA']['tt_content'] = array('foo');
327  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
328 
330  $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
331  GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
332  $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
333  $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
334 
335  // This is the real check: The "additional overlay" should be fetched
336  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
337 
338  $expected = $input;
339  $expected['defaultLanguageRow'] = $defaultLanguageRow;
340  $expected['additionalLanguageRows'] = [
341  3 => [
342  'uid' => 43,
343  'text' => 'localized text in french',
344  ],
345  ];
346 
347  $this->assertEquals($expected, $this->subject->addData($input));
348  }
349 }