[BUGFIX] Make checks in localize compatible with new Localization Wizard
[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\DataHandling\DataHandler;
20 use TYPO3\CMS\Core\Tests\FunctionalTestCase;
21
22 /**
23 * Test case for TYPO3\CMS\Backend\Controller\Page\LocalizationController
24 */
25 class LocalizationControllerTest extends FunctionalTestCase
26 {
27 /**
28 * @var LocalizationController
29 */
30 protected $subject;
31
32 /**
33 * Sets up this test case.
34 *
35 * @return void
36 */
37 protected function setUp()
38 {
39 parent::setUp();
40
41 $this->setUpBackendUserFromFixture(1);
42 Bootstrap::getInstance()->initializeLanguageObject();
43
44 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Fixtures/pages.xml');
45 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_language.xml');
46 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-default-language.xml');
47
48 $this->subject = new LocalizationController();
49 }
50
51 /**
52 * @test
53 */
54 public function recordsGetTranslatedFromDefaultLanguage()
55 {
56 $params = [
57 'pageId' => 1,
58 'srcLanguageId' => 0,
59 'destLanguageId' => 1,
60 'uidList' => [1, 2, 3],
61 'action' => LocalizationController::ACTION_LOCALIZE,
62 ];
63 $this->callInaccessibleMethod($this->subject, 'process', $params);
64
65 $expectedResults = [
66 [
67 'pid' => '1',
68 'sys_language_uid' => '1',
69 'l18n_parent' => '1',
70 'header' => '[Translate to Dansk:] Test content 1',
71 ],
72 [
73 'pid' => '1',
74 'sys_language_uid' => '1',
75 'l18n_parent' => '2',
76 'header' => '[Translate to Dansk:] Test content 2',
77 ],
78 [
79 'pid' => '1',
80 'sys_language_uid' => '1',
81 'l18n_parent' => '3',
82 'header' => '[Translate to Dansk:] Test content 3',
83 ],
84 ];
85 $results = $this->getDatabaseConnection()->exec_SELECTgetRows('pid, sys_language_uid, l18n_parent, header', 'tt_content', 'pid = 1 AND sys_language_uid = 1');
86 $this->assertSame($expectedResults, $results);
87 }
88
89 /**
90 * @test
91 */
92 public function recordsGetTranslatedFromDifferentTranslation()
93 {
94 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
95
96 $params = [
97 'pageId' => 1,
98 'srcLanguageId' => 1,
99 'destLanguageId' => 2,
100 'uidList' => [4, 5, 6], // uids of tt_content-danish-language
101 'action' => LocalizationController::ACTION_LOCALIZE,
102 ];
103 $this->callInaccessibleMethod($this->subject, 'process', $params);
104
105 $expectedResults = [
106 [
107 'pid' => '1',
108 'sys_language_uid' => '2',
109 'l18n_parent' => '1',
110 'header' => '[Translate to Deutsch:] Test indhold 1',
111 ],
112 [
113 'pid' => '1',
114 'sys_language_uid' => '2',
115 'l18n_parent' => '2',
116 'header' => '[Translate to Deutsch:] Test indhold 2',
117 ],
118 [
119 'pid' => '1',
120 'sys_language_uid' => '2',
121 'l18n_parent' => '3',
122 'header' => '[Translate to Deutsch:] Test indhold 3',
123 ],
124 ];
125 $results = $this->getDatabaseConnection()->exec_SELECTgetRows('pid, sys_language_uid, l18n_parent, header', 'tt_content', 'pid = 1 AND sys_language_uid = 2');
126 $this->assertSame($expectedResults, $results);
127 }
128
129 /**
130 * @test
131 */
132 public function recordsGetCopiedFromDefaultLanguage()
133 {
134 $params = [
135 'pageId' => 1,
136 'srcLanguageId' => 0,
137 'destLanguageId' => 2,
138 'uidList' => [1, 2, 3],
139 'action' => LocalizationController::ACTION_COPY,
140 ];
141 $this->callInaccessibleMethod($this->subject, 'process', $params);
142
143 $expectedResults = [
144 [
145 'pid' => '1',
146 'sys_language_uid' => '2',
147 'l18n_parent' => '0',
148 'header' => 'Test content 1 (copy 1)',
149 ],
150 [
151 'pid' => '1',
152 'sys_language_uid' => '2',
153 'l18n_parent' => '0',
154 'header' => 'Test content 2 (copy 1)',
155 ],
156 [
157 'pid' => '1',
158 'sys_language_uid' => '2',
159 'l18n_parent' => '0',
160 'header' => 'Test content 3 (copy 1)',
161 ],
162 ];
163 $results = $this->getDatabaseConnection()->exec_SELECTgetRows('pid, sys_language_uid, l18n_parent, header', 'tt_content', 'pid = 1 AND sys_language_uid = 2');
164 $this->assertSame($expectedResults, $results);
165 }
166
167 /**
168 * @test
169 */
170 public function recordsGetCopiedFromAnotherLanguage()
171 {
172 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
173
174 $params = [
175 'pageId' => 1,
176 'srcLanguageId' => 1,
177 'destLanguageId' => 2,
178 'uidList' => [4, 5, 6], // uids of tt_content-danish-language
179 'action' => LocalizationController::ACTION_COPY,
180 ];
181 $this->callInaccessibleMethod($this->subject, 'process', $params);
182
183 $expectedResults = [
184 [
185 'pid' => '1',
186 'sys_language_uid' => '2',
187 'l18n_parent' => '0',
188 'header' => 'Test indhold 1 (copy 1)',
189 ],
190 [
191 'pid' => '1',
192 'sys_language_uid' => '2',
193 'l18n_parent' => '0',
194 'header' => 'Test indhold 2 (copy 1)',
195 ],
196 [
197 'pid' => '1',
198 'sys_language_uid' => '2',
199 'l18n_parent' => '0',
200 'header' => 'Test indhold 3 (copy 1)',
201 ],
202 ];
203 $results = $this->getDatabaseConnection()->exec_SELECTgetRows('pid, sys_language_uid, l18n_parent, header', 'tt_content', 'pid = 1 AND sys_language_uid = 2');
204 $this->assertSame($expectedResults, $results);
205 }
206
207 /**
208 * @test
209 */
210 public function copyingNewContentFromLanguageIntoExistingLocalizationHasSameOrdering()
211 {
212 $params = [
213 'pageId' => 1,
214 'srcLanguageId' => 0,
215 'destLanguageId' => 1,
216 'uidList' => [1, 2, 3],
217 'action' => LocalizationController::ACTION_COPY,
218 ];
219 $this->callInaccessibleMethod($this->subject, 'process', $params);
220
221 // Create another content element in default language
222 $data = [
223 'tt_content' => [
224 'NEW123456' => [
225 'sys_language_uid' => 0,
226 'header' => 'Test content 2.5',
227 'pid' => -2,
228 ],
229 ],
230 ];
231 $dataHandler = new DataHandler();
232 $dataHandler->start($data, []);
233 $dataHandler->process_datamap();
234 $dataHandler->process_cmdmap();
235 $newContentElementUid = $dataHandler->substNEWwithIDs['NEW123456'];
236
237 // Copy the new content element
238 $params = [
239 'pageId' => 1,
240 'srcLanguageId' => 0,
241 'destLanguageId' => 1,
242 'uidList' => [$newContentElementUid],
243 'action' => LocalizationController::ACTION_COPY,
244 ];
245 $this->callInaccessibleMethod($this->subject, 'process', $params);
246
247 $expectedResults = [
248 [
249 'pid' => '1',
250 'sys_language_uid' => '1',
251 'l18n_parent' => '0',
252 'header' => 'Test content 1 (copy 1)',
253 ],
254 [
255 'pid' => '1',
256 'sys_language_uid' => '1',
257 'l18n_parent' => '0',
258 'header' => 'Test content 2 (copy 1)',
259 ],
260 [
261 'pid' => '1',
262 'sys_language_uid' => '1',
263 'l18n_parent' => '0',
264 'header' => 'Test content 2.5 (copy 1)',
265 ],
266 [
267 'pid' => '1',
268 'sys_language_uid' => '1',
269 'l18n_parent' => '0',
270 'header' => 'Test content 3 (copy 1)',
271 ],
272 ];
273 $results = $this->getDatabaseConnection()->exec_SELECTgetRows('pid, sys_language_uid, l18n_parent, header', 'tt_content', 'pid = 1 AND sys_language_uid = 1', '', 'sorting ASC');
274 $this->assertSame($expectedResults, $results);
275 }
276 }