099f7defd8a02cc05d4f0d42a29e285184a7765b
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Functional / Controller / Page / LocalizationControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Functional\Controller\Page;
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 TYPO3\CMS\Backend\Controller\Page\LocalizationController;
18 use TYPO3\CMS\Core\Core\Bootstrap;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\DataHandling\DataHandler;
21 use TYPO3\CMS\Core\Tests\FunctionalTestCase;
22
23 /**
24 * Test case for TYPO3\CMS\Backend\Controller\Page\LocalizationController
25 */
26 class LocalizationControllerTest extends FunctionalTestCase
27 {
28 /**
29 * @var LocalizationController
30 */
31 protected $subject;
32
33 /**
34 * Sets up this test case.
35 *
36 * @return void
37 */
38 protected function setUp()
39 {
40 parent::setUp();
41
42 $this->setUpBackendUserFromFixture(1);
43 Bootstrap::getInstance()->initializeLanguageObject();
44
45 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Fixtures/pages.xml');
46 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_language.xml');
47 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-default-language.xml');
48
49 $this->subject = new LocalizationController();
50 }
51
52 /**
53 * @test
54 */
55 public function recordsGetTranslatedFromDefaultLanguage()
56 {
57 $params = [
58 'pageId' => 1,
59 'srcLanguageId' => 0,
60 'destLanguageId' => 1,
61 'uidList' => [1, 2, 3],
62 'action' => LocalizationController::ACTION_LOCALIZE,
63 ];
64 $this->callInaccessibleMethod($this->subject, 'process', $params);
65
66 $expectedResults = [
67 [
68 'pid' => 1,
69 'sys_language_uid' => 1,
70 'l18n_parent' => 1,
71 'header' => '[Translate to Dansk:] Test content 1',
72 ],
73 [
74 'pid' => 1,
75 'sys_language_uid' => 1,
76 'l18n_parent' => 2,
77 'header' => '[Translate to Dansk:] Test content 2',
78 ],
79 [
80 'pid' => 1,
81 'sys_language_uid' => 1,
82 'l18n_parent' => 3,
83 'header' => '[Translate to Dansk:] Test content 3',
84 ],
85 ];
86 $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tt_content');
87 $queryBuilder->getRestrictions()->removeAll();
88 $results = $queryBuilder
89 ->select('pid', 'sys_language_uid', 'l18n_parent', 'header')
90 ->from('tt_content')
91 ->where(
92 $queryBuilder->expr()->andX(
93 $queryBuilder->expr()->eq(
94 'pid',
95 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
96 ),
97 $queryBuilder->expr()->eq(
98 'sys_language_uid',
99 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
100 )
101 )
102 )
103 ->execute()
104 ->fetchAll();
105 $this->assertSame($expectedResults, $results);
106 }
107
108 /**
109 * @test
110 */
111 public function recordsGetTranslatedFromDifferentTranslation()
112 {
113 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
114
115 $params = [
116 'pageId' => 1,
117 'srcLanguageId' => 1,
118 'destLanguageId' => 2,
119 'uidList' => [4, 5, 6], // uids of tt_content-danish-language
120 'action' => LocalizationController::ACTION_LOCALIZE,
121 ];
122 $this->callInaccessibleMethod($this->subject, 'process', $params);
123
124 $expectedResults = [
125 [
126 'pid' => 1,
127 'sys_language_uid' => 2,
128 'l18n_parent' => 1,
129 'header' => 'Test indhold 1 (copy 1)',
130 ],
131 [
132 'pid' => 1,
133 'sys_language_uid' => 2,
134 'l18n_parent' => 2,
135 'header' => 'Test indhold 2 (copy 1)',
136 ],
137 [
138 'pid' => 1,
139 'sys_language_uid' => 2,
140 'l18n_parent' => 3,
141 'header' => 'Test indhold 3 (copy 1)',
142 ],
143 ];
144 $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tt_content');
145 $queryBuilder->getRestrictions()->removeAll();
146 $results = $queryBuilder
147 ->select('pid', 'sys_language_uid', 'l18n_parent', 'header')
148 ->from('tt_content')
149 ->where(
150 $queryBuilder->expr()->andX(
151 $queryBuilder->expr()->eq(
152 'pid',
153 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
154 ),
155 $queryBuilder->expr()->eq(
156 'sys_language_uid',
157 $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)
158 )
159 )
160 )
161 ->execute()
162 ->fetchAll();
163 $this->assertSame($expectedResults, $results);
164 }
165
166 /**
167 * @test
168 */
169 public function recordsGetCopiedFromDefaultLanguage()
170 {
171 $params = [
172 'pageId' => 1,
173 'srcLanguageId' => 0,
174 'destLanguageId' => 2,
175 'uidList' => [1, 2, 3],
176 'action' => LocalizationController::ACTION_COPY,
177 ];
178 $this->callInaccessibleMethod($this->subject, 'process', $params);
179
180 $expectedResults = [
181 [
182 'pid' => 1,
183 'sys_language_uid' => 2,
184 'l18n_parent' => 0,
185 'header' => 'Test content 1 (copy 1)',
186 ],
187 [
188 'pid' => 1,
189 'sys_language_uid' => 2,
190 'l18n_parent' => 0,
191 'header' => 'Test content 2 (copy 1)',
192 ],
193 [
194 'pid' => 1,
195 'sys_language_uid' => 2,
196 'l18n_parent' => 0,
197 'header' => 'Test content 3 (copy 1)',
198 ],
199 ];
200 $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tt_content');
201 $queryBuilder->getRestrictions()->removeAll();
202 $results = $queryBuilder
203 ->select('pid', 'sys_language_uid', 'l18n_parent', 'header')
204 ->from('tt_content')
205 ->where(
206 $queryBuilder->expr()->andX(
207 $queryBuilder->expr()->eq(
208 'pid',
209 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
210 ),
211 $queryBuilder->expr()->eq(
212 'sys_language_uid',
213 $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)
214 )
215 )
216 )
217 ->execute()
218 ->fetchAll();
219 $this->assertSame($expectedResults, $results);
220 }
221
222 /**
223 * @test
224 */
225 public function recordsGetCopiedFromAnotherLanguage()
226 {
227 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
228
229 $params = [
230 'pageId' => 1,
231 'srcLanguageId' => 1,
232 'destLanguageId' => 2,
233 'uidList' => [4, 5, 6], // uids of tt_content-danish-language
234 'action' => LocalizationController::ACTION_COPY,
235 ];
236 $this->callInaccessibleMethod($this->subject, 'process', $params);
237
238 $expectedResults = [
239 [
240 'pid' => 1,
241 'sys_language_uid' => 2,
242 'l18n_parent' => 0,
243 'header' => 'Test indhold 1 (copy 1)',
244 ],
245 [
246 'pid' => 1,
247 'sys_language_uid' => 2,
248 'l18n_parent' => 0,
249 'header' => 'Test indhold 2 (copy 1)',
250 ],
251 [
252 'pid' => 1,
253 'sys_language_uid' => 2,
254 'l18n_parent' => 0,
255 'header' => 'Test indhold 3 (copy 1)',
256 ],
257 ];
258 $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tt_content');
259 $queryBuilder->getRestrictions()->removeAll();
260 $results = $queryBuilder
261 ->select('pid', 'sys_language_uid', 'l18n_parent', 'header')
262 ->from('tt_content')
263 ->where(
264 $queryBuilder->expr()->andX(
265 $queryBuilder->expr()->eq(
266 'pid',
267 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
268 ),
269 $queryBuilder->expr()->eq(
270 'sys_language_uid',
271 $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)
272 )
273 )
274 )
275 ->execute()
276 ->fetchAll();
277 $this->assertSame($expectedResults, $results);
278 }
279
280 /**
281 * @test
282 */
283 public function copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering()
284 {
285 $params = [
286 'pageId' => 1,
287 'srcLanguageId' => 0,
288 'destLanguageId' => 1,
289 'uidList' => [1, 2, 3],
290 'action' => LocalizationController::ACTION_COPY,
291 ];
292 $this->callInaccessibleMethod($this->subject, 'process', $params);
293
294 // Create another content element in default language
295 $data = [
296 'tt_content' => [
297 'NEW123456' => [
298 'sys_language_uid' => 0,
299 'header' => 'Test content 2.5',
300 'pid' => -2,
301 ],
302 ],
303 ];
304 $dataHandler = new DataHandler();
305 $dataHandler->start($data, []);
306 $dataHandler->process_datamap();
307 $dataHandler->process_cmdmap();
308 $newContentElementUid = $dataHandler->substNEWwithIDs['NEW123456'];
309
310 // Copy the new content element
311 $params = [
312 'pageId' => 1,
313 'srcLanguageId' => 0,
314 'destLanguageId' => 1,
315 'uidList' => [$newContentElementUid],
316 'action' => LocalizationController::ACTION_COPY,
317 ];
318 $this->callInaccessibleMethod($this->subject, 'process', $params);
319
320 $expectedResults = [
321 [
322 'pid' => 1,
323 'sys_language_uid' => 1,
324 'l18n_parent' => 0,
325 'header' => 'Test content 1 (copy 1)',
326 ],
327 [
328 'pid' => 1,
329 'sys_language_uid' => 1,
330 'l18n_parent' => 0,
331 'header' => 'Test content 2 (copy 1)',
332 ],
333 [
334 'pid' => 1,
335 'sys_language_uid' => 1,
336 'l18n_parent' => 0,
337 'header' => 'Test content 2.5 (copy 1)',
338 ],
339 [
340 'pid' => 1,
341 'sys_language_uid' => 1,
342 'l18n_parent' => 0,
343 'header' => 'Test content 3 (copy 1)',
344 ],
345 ];
346 $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tt_content');
347 $queryBuilder->getRestrictions()->removeAll();
348 $results = $queryBuilder
349 ->select('pid', 'sys_language_uid', 'l18n_parent', 'header')
350 ->from('tt_content')
351 ->where(
352 $queryBuilder->expr()->andX(
353 $queryBuilder->expr()->eq(
354 'pid',
355 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
356 ),
357 $queryBuilder->expr()->eq(
358 'sys_language_uid',
359 $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
360 )
361 )
362 )->orderBy('sorting', 'ASC')
363 ->execute()
364 ->fetchAll();
365 $this->assertSame($expectedResults, $results);
366 }
367 }