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