15add586755d4a5b5d3920fdd44f4c704d187a4f
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / IRRE / CSV / AbstractActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\IRRE\CSV;
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 /**
18 * Functional test for the DataHandler
19 */
20 abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
21 {
22 const VALUE_PageId = 89;
23 const VALUE_PageIdTarget = 90;
24 const VALUE_PageIdWebsite = 1;
25 const VALUE_ContentIdFirst = 297;
26 const VALUE_ContentIdLast = 298;
27 const VALUE_HotelIdFirst = 3;
28 const VALUE_HotelIdSecond = 4;
29 const VALUE_HotelIdThird = 5;
30 const VALUE_LanguageId = 1;
31 const VALUE_LanguageIdSecond = 2;
32
33 const TABLE_Page = 'pages';
34 const TABLE_Content = 'tt_content';
35 const TABLE_Hotel = 'tx_irretutorial_1ncsv_hotel';
36 const TABLE_Offer = 'tx_irretutorial_1ncsv_offer';
37
38 const FIELD_PageHotel = 'tx_irretutorial_1ncsv_hotels';
39 const FIELD_ContentHotel = 'tx_irretutorial_1ncsv_hotels';
40 const FIELD_HotelOffer = 'offers';
41
42 /**
43 * @var string
44 */
45 protected $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/IRRE/CSV/DataSet/';
46
47 protected function setUp()
48 {
49 parent::setUp();
50 $this->importScenarioDataSet('LiveDefaultPages');
51 $this->importScenarioDataSet('LiveDefaultElements');
52
53 $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
54 }
55
56 /**
57 * Parent content records
58 */
59
60 /**
61 * @see DataSet/createParentContentRecord.csv
62 */
63 public function createParentContent()
64 {
65 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
66 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
67 }
68
69 /**
70 * @see DataSet/modifyParentContentRecord.csv
71 */
72 public function modifyParentContent()
73 {
74 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, ['header' => 'Testing #1']);
75 }
76
77 /**
78 * @see DataSet/deleteParentContentRecord.csv
79 */
80 public function deleteParentContent()
81 {
82 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
83 }
84
85 /**
86 * @see DataSet/copyParentContentRecord.csv
87 */
88 public function copyParentContent()
89 {
90 $newTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
91 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
92 }
93
94 /**
95 * @see DataSet/copyParentContentToDifferentPage.csv
96 */
97 public function copyParentContentToDifferentPage()
98 {
99 $newTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
100 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
101 }
102
103 /**
104 * @see DataSet/copyParentContentToLanguage.csv
105 * Should copy all children as well
106 */
107 public function copyParentContentToLanguage()
108 {
109 $newTableIds = $this->actionService->copyRecordToLanguage(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
110 $this->recordIds['localizedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
111 }
112 /**
113 * @see DataSet/localizeParentContentWAllChildren.csv
114 * Should localize all children as well
115 */
116 public function localizeParentContentWithAllChildren()
117 {
118 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
119 $this->recordIds['localizedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
120 }
121
122 public function localizeParentContentWithLanguageSynchronization()
123 {
124 $GLOBALS['TCA'][self::TABLE_Content]['columns'][self::FIELD_ContentHotel]['config']['behaviour']['allowLanguageSynchronization'] = true;
125 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
126 $this->recordIds['localizedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
127 $this->actionService->modifyRecords(
128 self::VALUE_PageId,
129 [
130 self::TABLE_Content => ['uid' => self::VALUE_ContentIdLast, self::FIELD_ContentHotel => '5,__nextUid'],
131 self::TABLE_Hotel => ['uid' => '__NEW', 'title' => 'Hotel #2'],
132 ]
133 );
134 }
135
136 /**
137 * @see DataSet/changeParentContentRecordSorting.csv
138 */
139 public function changeParentContentSorting()
140 {
141 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
142 }
143
144 /**
145 * @see DataSet/moveParentContentRecordToDifferentPage.csv
146 */
147 public function moveParentContentToDifferentPage()
148 {
149 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
150 }
151
152 /**
153 * @see DataSet/moveParentContentRecordToDifferentPageAndChangeSorting.csv
154 */
155 public function moveParentContentToDifferentPageAndChangeSorting()
156 {
157 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
158 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
159 }
160
161 /**
162 * Page records
163 */
164
165 /**
166 * @see DataSet/modifyPageRecord.csv
167 */
168 public function modifyPage()
169 {
170 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, ['title' => 'Testing #1']);
171 }
172
173 /**
174 * @see DataSet/deletePageRecord.csv
175 */
176 public function deletePage()
177 {
178 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
179 }
180
181 /**
182 * @see DataSet/copyPageRecord.csv
183 */
184 public function copyPage()
185 {
186 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
187 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
188 $this->recordIds['newContentIdFirst'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdFirst];
189 $this->recordIds['newContentIdLast'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
190 }
191
192 /**
193 * @see DataSet/copyPageWHotelBeforeParentContent.csv
194 */
195 public function copyPageWithHotelBeforeParentContent()
196 {
197 // Ensure hotels get processed first
198 $GLOBALS['TCA'] = array_merge(
199 [self::TABLE_Hotel => $GLOBALS['TCA'][self::TABLE_Hotel]],
200 $GLOBALS['TCA']
201 );
202
203 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
204 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
205 $this->recordIds['newContentIdFirst'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdFirst];
206 $this->recordIds['newContentIdLast'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
207 }
208
209 /**
210 * IRRE Child Records
211 */
212
213 /**
214 * @see DataSet/createParentContentRecordWithHotelAndOfferChildRecords.csv
215 */
216 public function createParentContentWithHotelAndOfferChildren()
217 {
218 $newTableIds = $this->actionService->createNewRecords(
219 self::VALUE_PageId,
220 [
221 self::TABLE_Content => ['header' => 'Testing #1', self::FIELD_ContentHotel => '__nextUid'],
222 self::TABLE_Hotel => ['title' => 'Hotel #1', self::FIELD_HotelOffer => '__nextUid'],
223 self::TABLE_Offer => ['title' => 'Offer #1'],
224 ]
225 );
226 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
227 }
228
229 /**
230 * @see DataSet/createAndCopyParentContentRecordWithHotelAndOfferChildRecords.csv
231 */
232 public function createAndCopyParentContentWithHotelAndOfferChildren()
233 {
234 $newTableIds = $this->actionService->createNewRecords(
235 self::VALUE_PageId,
236 [
237 self::TABLE_Content => ['header' => 'Testing #1', self::FIELD_ContentHotel => '__nextUid'],
238 self::TABLE_Hotel => ['title' => 'Hotel #1', self::FIELD_HotelOffer => '__nextUid'],
239 self::TABLE_Offer => ['title' => 'Offer #1'],
240 ]
241 );
242 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
243 $this->recordIds['newHotelId'] = $newTableIds[self::TABLE_Hotel][0];
244 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $this->recordIds['newContentId'], self::VALUE_PageId);
245 $this->recordIds['copiedContentId'] = $copiedTableIds[self::TABLE_Content][$this->recordIds['newContentId']];
246 $this->recordIds['copiedHotelId'] = $copiedTableIds[self::TABLE_Hotel][$this->recordIds['newHotelId']];
247 }
248
249 /**
250 * @see DataSet/createAndLocalizeParentContentRecordWithHotelAndOfferChildRecords.csv
251 */
252 public function createAndLocalizeParentContentWithHotelAndOfferChildren()
253 {
254 $newTableIds = $this->actionService->createNewRecords(
255 self::VALUE_PageId,
256 [
257 self::TABLE_Content => ['header' => 'Testing #1', self::FIELD_ContentHotel => '__nextUid'],
258 self::TABLE_Hotel => ['title' => 'Hotel #1', self::FIELD_HotelOffer => '__nextUid'],
259 self::TABLE_Offer => ['title' => 'Offer #1'],
260 ]
261 );
262 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
263 $this->recordIds['newHotelId'] = $newTableIds[self::TABLE_Hotel][0];
264 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, $this->recordIds['newContentId'], self::VALUE_LanguageId);
265 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][$this->recordIds['newContentId']];
266 $this->recordIds['localizedHotelId'] = $localizedTableIds[self::TABLE_Hotel][$this->recordIds['newHotelId']];
267 }
268
269 /**
270 * @see DataSet/modifyOnlyHotelChildRecord.csv
271 */
272 public function modifyOnlyHotelChild()
273 {
274 $this->actionService->modifyRecord(self::TABLE_Hotel, 4, ['title' => 'Testing #1']);
275 }
276
277 /**
278 * @see DataSet/modifyParentRecordAndChangeHotelChildRecordsSorting.csv
279 */
280 public function modifyParentAndChangeHotelChildrenSorting()
281 {
282 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, [self::FIELD_ContentHotel => '4,3']);
283 }
284
285 /**
286 * @see DataSet/modifyParentRecordWithHotelChildRecord.csv
287 */
288 public function modifyParentWithHotelChild()
289 {
290 $this->actionService->modifyRecords(
291 self::VALUE_PageId,
292 [
293 self::TABLE_Content => ['uid' => self::VALUE_ContentIdFirst, self::FIELD_ContentHotel => '3,4'],
294 self::TABLE_Hotel => ['uid' => 4, 'title' => 'Testing #1'],
295 ]
296 );
297 }
298
299 /**
300 * @see DataSet/modifyParentRecordAndAddHotelChildRecord.csv
301 */
302 public function modifyParentAndAddHotelChild()
303 {
304 $this->actionService->modifyRecords(
305 self::VALUE_PageId,
306 [
307 self::TABLE_Content => ['uid' => self::VALUE_ContentIdLast, self::FIELD_ContentHotel => '5,__nextUid'],
308 self::TABLE_Hotel => ['uid' => '__NEW', 'title' => 'Hotel #2'],
309 ]
310 );
311 }
312
313 /**
314 * @see DataSet/modifyParentRecordAndDeleteHotelChildRecord.csv
315 */
316 public function modifyParentAndDeleteHotelChild()
317 {
318 $this->actionService->modifyRecord(
319 self::TABLE_Content,
320 self::VALUE_ContentIdFirst,
321 [self::FIELD_ContentHotel => '3'],
322 [self::TABLE_Hotel => [4]]
323 );
324 }
325
326 public function localizePageWithLocalizationExclude()
327 {
328 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['l10n_mode'] = 'exclude';
329 // in these test cases we expect new pages not to be hidden in order to
330 // verify proper overlaying behavior during the frontend render process
331 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
332 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
333 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
334 }
335
336 public function localizePageTwiceWithLocalizationExclude()
337 {
338 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['l10n_mode'] = 'exclude';
339 // in these test cases we expect new pages not to be hidden in order to
340 // verify proper overlaying behavior during the frontend render process
341 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
342 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
343 $this->recordIds['localizedPageIdFirst'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
344 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageIdSecond);
345 $this->recordIds['localizedPageIdSecond'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
346 }
347
348 public function localizePageAndAddHotelChildWithLocalizationExclude()
349 {
350 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['l10n_mode'] = 'exclude';
351 // in these test cases we expect new pages not to be hidden in order to
352 // verify proper overlaying behavior during the frontend render process
353 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
354 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
355 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
356 $this->actionService->modifyRecords(
357 self::VALUE_PageId,
358 [
359 self::TABLE_Page => ['uid' => self::VALUE_PageId, self::FIELD_PageHotel => '2,__nextUid'],
360 self::TABLE_Hotel => ['uid' => '__NEW', 'title' => 'Hotel #007'],
361 ]
362 );
363 }
364
365 public function localizePageWithLanguageSynchronization()
366 {
367 // in these test cases we expect new pages not to be hidden in order to
368 // verify proper overlaying behavior during the frontend render process
369 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
370 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['config']['behaviour']['allowLanguageSynchronization'] = true;
371 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
372 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
373 }
374
375 public function localizePageAndAddHotelChildWithLanguageSynchronization()
376 {
377 // in these test cases we expect new pages not to be hidden in order to
378 // verify proper overlaying behavior during the frontend render process
379 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
380 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['config']['behaviour']['allowLanguageSynchronization'] = true;
381 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
382 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
383 $this->actionService->modifyRecords(
384 self::VALUE_PageId,
385 [
386 self::TABLE_Page => ['uid' => self::VALUE_PageId, self::FIELD_PageHotel => '2,__nextUid'],
387 self::TABLE_Hotel => ['uid' => '__NEW', 'title' => 'Hotel #007'],
388 ]
389 );
390 }
391
392 public function localizePageAndAddMonoglotHotelChildWithLanguageSynchronization()
393 {
394 // in these test cases we expect new pages not to be hidden in order to
395 // verify proper overlaying behavior during the frontend render process
396 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
397 unset($GLOBALS['TCA'][self::TABLE_Hotel]['ctrl']['languageField']);
398 unset($GLOBALS['TCA'][self::TABLE_Hotel]['ctrl']['transOrigPointerField']);
399 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['config']['behaviour']['allowLanguageSynchronization'] = true;
400 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
401 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
402 $this->actionService->modifyRecords(
403 self::VALUE_PageId,
404 [
405 self::TABLE_Page => ['uid' => self::VALUE_PageId, self::FIELD_PageHotel => '2,__nextUid'],
406 self::TABLE_Hotel => ['uid' => '__NEW', 'title' => 'Hotel #007'],
407 ]
408 );
409 }
410
411 public function localizeAndCopyPageWithLanguageSynchronization()
412 {
413 // in these test cases we expect new pages not to be hidden in order to
414 // verify proper overlaying behavior during the frontend render process
415 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
416 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['config']['behaviour']['allowLanguageSynchronization'] = true;
417 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
418 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
419 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
420 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
421 }
422
423 public function localizePageWithSynchronizationAndCustomLocalizedHotel()
424 {
425 // in these test cases we expect new pages not to be hidden in order to
426 // verify proper overlaying behavior during the frontend render process
427 $GLOBALS['TCA'][self::TABLE_Page]['columns']['hidden']['config']['default'] = 0;
428 $GLOBALS['TCA'][self::TABLE_Page]['columns'][self::FIELD_PageHotel]['config']['behaviour']['allowLanguageSynchronization'] = true;
429 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
430 $this->recordIds['localizedPageId'] = $localizedTableIds[self::TABLE_Page][self::VALUE_PageId];
431 // Using "localized page ID" on purpose because BE editing uses a "page" record and data handler
432 $this->actionService->modifyRecords(
433 $this->recordIds['localizedPageId'],
434 [
435 self::TABLE_Page => ['uid' => $this->recordIds['localizedPageId'], self::FIELD_PageHotel => '6,__nextUid', 'l10n_state' => [self::FIELD_PageHotel => 'custom']],
436 self::TABLE_Hotel => ['uid' => '__NEW', 'sys_language_uid' => self::VALUE_LanguageId, 'title' => 'Hotel in dansk page only'],
437 ]
438 );
439 }
440 }