[BUGFIX] Allow processing of multiple new record localizations
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / Regular / AbstractActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular;
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\Core\Utility\StringUtility;
18
19 /**
20 * Functional test for the DataHandler
21 */
22 abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
23 {
24 const VALUE_PageId = 89;
25 const VALUE_PageIdTarget = 90;
26 const VALUE_PageIdWebsite = 1;
27 const VALUE_ContentIdFirst = 297;
28 const VALUE_ContentIdSecond = 298;
29 const VALUE_ContentIdThird = 299;
30 const VALUE_ContentIdThirdLocalized = 300;
31 const VALUE_LanguageId = 1;
32 const VALUE_LanguageIdSecond = 2;
33
34 const TABLE_Page = 'pages';
35 const TABLE_PageOverlay = 'pages_language_overlay';
36 const TABLE_Content = 'tt_content';
37
38 /**
39 * @var string
40 */
41 protected $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Regular/DataSet/';
42
43 protected function setUp()
44 {
45 parent::setUp();
46 $this->importScenarioDataSet('LiveDefaultPages');
47 $this->importScenarioDataSet('LiveDefaultElements');
48
49 $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts']);
50 $this->backendUser->workspace = 0;
51 }
52
53 /**
54 * Content records
55 */
56
57 /**
58 * @see DataSet/createContentRecords.csv
59 */
60 public function createContents()
61 {
62 // Creating record at the beginning of the page
63 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
64 $this->recordIds['newContentIdFirst'] = $newTableIds[self::TABLE_Content][0];
65 // Creating record at the end of the page (after last one)
66 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, -self::VALUE_ContentIdSecond, ['header' => 'Testing #2']);
67 $this->recordIds['newContentIdLast'] = $newTableIds[self::TABLE_Content][0];
68 }
69
70 /**
71 * Creation of a content element with language set to all
72 *
73 * @see DataSet/createContentForLanguageAll.csv
74 */
75 public function createContentForLanguageAll()
76 {
77 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Language set to all', 'sys_language_uid' => -1]);
78 $this->recordIds['newContentLanguageAll'] = $newTableIds[self::TABLE_Content][0];
79 }
80
81 /**
82 * @see DataSet/modifyContentRecord.csv
83 */
84 public function modifyContent()
85 {
86 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, ['header' => 'Testing #1']);
87 }
88
89 /**
90 * @see DataSet/deleteContentRecord.csv
91 */
92 public function deleteContent()
93 {
94 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
95 }
96
97 /**
98 * @see DataSet/deleteLocalizedContentNDeleteContent.csv
99 */
100 public function deleteLocalizedContentAndDeleteContent()
101 {
102 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized);
103 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdThird);
104 }
105
106 /**
107 * @see DataSet/copyContentRecord.csv
108 */
109 public function copyContent()
110 {
111 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageId);
112 $this->recordIds['copiedContentId'] = $copiedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
113 }
114
115 /**
116 * @see DataSet/copyContentToLanguage.csv
117 */
118 public function copyContentToLanguage()
119 {
120 $copiedTableIds = $this->actionService->copyRecordToLanguage(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_LanguageId);
121 $this->recordIds['localizedContentId'] = $copiedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
122 }
123
124 /**
125 * Free mode "translation" of a record in non default language
126 *
127 * @see DataSet/copyContentToLanguageFromNonDefaultLanguage.csv
128 */
129 public function copyContentToLanguageFromNonDefaultLanguage()
130 {
131 $copiedTableIds = $this->actionService->copyRecordToLanguage(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized, self::VALUE_LanguageIdSecond);
132 $this->recordIds['localizedContentId'] = $copiedTableIds[self::TABLE_Content][self::VALUE_ContentIdThirdLocalized];
133 }
134
135 /**
136 * @see DataSet/copyPasteContent.csv
137 */
138 public function copyPasteContent()
139 {
140 $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageId, ['header' => 'Testing #1']);
141 }
142
143 /**
144 * @see DataSet/localizeContentRecord.csv
145 */
146 public function localizeContent()
147 {
148 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_LanguageId);
149 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
150 }
151
152 public function localizeContentWithLanguageSynchronization()
153 {
154 $GLOBALS['TCA']['tt_content']['columns']['header']['config']['behaviour']['allowLanguageSynchronization'] = true;
155 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_LanguageId);
156 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
157 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, ['header' => 'Testing #1']);
158 }
159
160 public function localizeContentWithLanguageSynchronizationHavingNullValue()
161 {
162 $GLOBALS['TCA']['tt_content']['columns']['bodytext']['config']['eval'] = 'null';
163 $GLOBALS['TCA']['tt_content']['columns']['bodytext']['config']['behaviour']['allowLanguageSynchronization'] = true;
164 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, ['bodytext' => null]);
165 self::localizeContentWithLanguageSynchronization();
166 }
167
168 /**
169 * @see DataSet/localizeContentFromNonDefaultLanguage.csv
170 */
171 public function localizeContentFromNonDefaultLanguage()
172 {
173 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized, self::VALUE_LanguageIdSecond);
174 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdThirdLocalized];
175 }
176
177 public function localizeContentFromNonDefaultLanguageWithLanguageSynchronizationDefault()
178 {
179 $GLOBALS['TCA']['tt_content']['columns']['header']['config']['behaviour']['allowLanguageSynchronization'] = true;
180 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized, self::VALUE_LanguageIdSecond);
181 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdThirdLocalized];
182 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdThird, ['header' => 'Testing #1']);
183 }
184
185 public function localizeContentFromNonDefaultLanguageWithLanguageSynchronizationSource()
186 {
187 $GLOBALS['TCA']['tt_content']['columns']['header']['config']['behaviour']['allowLanguageSynchronization'] = true;
188 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized, self::VALUE_LanguageIdSecond);
189 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdThirdLocalized];
190 $this->actionService->modifyRecord(self::TABLE_Content, $this->recordIds['localizedContentId'], ['l10n_state' => ['header' => 'source']]);
191 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdThird, ['header' => 'Testing #1']);
192 }
193
194 public function createLocalizedContent()
195 {
196 $newContentIdDefault = StringUtility::getUniqueId('NEW');
197 $newContentIdLocalized = StringUtility::getUniqueId('NEW');
198 $dataMap = [
199 self::TABLE_Content => [
200 $newContentIdDefault => ['pid' => self::VALUE_PageId, 'header' => 'Testing'],
201 $newContentIdLocalized => ['pid' => self::VALUE_PageId, 'header' => 'Localized Testing', 'sys_language_uid' => self::VALUE_LanguageId, 'l18n_parent' => $newContentIdDefault, 'l10n_source' => $newContentIdDefault],
202 ]
203 ];
204 $this->actionService->invoke($dataMap, []);
205 $this->recordIds['newContentIdDefault'] = $this->actionService->getDataHandler()->substNEWwithIDs[$newContentIdDefault];
206 $this->recordIds['newContentIdLocalized'] = $this->actionService->getDataHandler()->substNEWwithIDs[$newContentIdLocalized];
207 }
208
209 public function createLocalizedContentWithLanguageSynchronization()
210 {
211 $GLOBALS['TCA']['tt_content']['columns']['header']['config']['behaviour']['allowLanguageSynchronization'] = true;
212 self::createLocalizedContent();
213 }
214
215 public function createLocalizedContentWithLocalizationExclude()
216 {
217 $GLOBALS['TCA']['tt_content']['columns']['header']['l10n_mode'] = 'exclude';
218 self::createLocalizedContent();
219 }
220
221 /**
222 * @see DataSet/changeContentRecordSorting.csv
223 */
224 public function changeContentSorting()
225 {
226 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
227 }
228
229 /**
230 * @see DataSet/moveContentRecordToDifferentPage.csv
231 */
232 public function moveContentToDifferentPage()
233 {
234 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
235 }
236
237 /**
238 * @see DataSet/movePasteContentToDifferentPage.csv
239 */
240 public function movePasteContentToDifferentPage()
241 {
242 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget, ['header' => 'Testing #1']);
243 }
244
245 /**
246 * @see DataSet/moveContentRecordToDifferentPageAndChangeSorting.csv
247 */
248 public function moveContentToDifferentPageAndChangeSorting()
249 {
250 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
251 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
252 }
253
254 /**
255 * Page records
256 */
257
258 /**
259 * @see DataSet/createPageRecord.csv
260 */
261 public function createPage()
262 {
263 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
264 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][0];
265 }
266
267 /**
268 * @see DataSet/modifyPageRecord.csv
269 */
270 public function modifyPage()
271 {
272 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, ['title' => 'Testing #1']);
273 }
274
275 /**
276 * @see DataSet/deletePageRecord.csv
277 */
278 public function deletePage()
279 {
280 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
281 }
282
283 /**
284 * @see DataSet/copyPage.csv
285 */
286 public function copyPage()
287 {
288 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
289 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
290 $this->recordIds['newContentIdFirst'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdFirst];
291 $this->recordIds['newContentIdLast'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
292 }
293
294 /**
295 * @see DataSet/copyPageFreeMode.csv
296 */
297 public function copyPageFreeMode()
298 {
299 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdTarget);
300 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageIdTarget];
301 }
302
303 /**
304 * @see DataSet/localizePageRecord.csv
305 */
306 public function localizePage()
307 {
308 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
309 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
310 $this->recordIds['localizedPageOverlayId'] = $localizedTableIds[self::TABLE_PageOverlay][self::VALUE_PageId];
311 }
312
313 public function localizePageWithLanguageSynchronization()
314 {
315 $GLOBALS['TCA']['pages_language_overlay']['columns']['title']['config']['behaviour']['allowLanguageSynchronization'] = true;
316 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
317 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
318 $this->recordIds['localizedPageOverlayId'] = $localizedTableIds[self::TABLE_PageOverlay][self::VALUE_PageId];
319 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, ['title' => 'Testing #1']);
320 }
321
322 /**
323 * @see DataSet/changePageRecordSorting.csv
324 */
325 public function changePageSorting()
326 {
327 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
328 }
329
330 /**
331 * @see DataSet/movePageRecordToDifferentPage.csv
332 */
333 public function movePageToDifferentPage()
334 {
335 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
336 }
337
338 /**
339 * @see DataSet/movePageRecordToDifferentPageAndChangeSorting.csv
340 */
341 public function movePageToDifferentPageAndChangeSorting()
342 {
343 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
344 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
345 }
346 }