8ad8a66bd7f0b1fe5273f504bd71a476c00fccba
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Tests / Functional / DataHandling / Regular / AbstractActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\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 /**
18 * Functional test for the DataHandler
19 */
20 abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
21 {
22 const VALUE_ParentPageId = 88;
23 const VALUE_PageId = 89;
24 const VALUE_PageIdTarget = 90;
25 const VALUE_PageIdWebsite = 1;
26 const VALUE_ContentIdZero = 296;
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_WorkspaceId = 1;
33
34 const TABLE_Page = 'pages';
35 const TABLE_PageOverlay = 'pages_language_overlay';
36 const TABLE_Content = 'tt_content';
37
38 /**
39 * @var array
40 */
41 protected $coreExtensionsToLoad = [
42 'fluid',
43 'version',
44 'workspaces',
45 ];
46
47 /**
48 * @var string
49 */
50 protected $scenarioDataSetDirectory = 'typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/DataSet/';
51
52 protected function setUp()
53 {
54 parent::setUp();
55 $this->importScenarioDataSet('LiveDefaultPages');
56 $this->importScenarioDataSet('LiveDefaultElements');
57 $this->importScenarioDataSet('ReferenceIndex');
58
59 $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts']);
60 $this->backendUser->workspace = self::VALUE_WorkspaceId;
61 }
62
63 /**
64 * Content records
65 */
66
67 /**
68 * @see DataSet/Assertion/createContentRecords.csv
69 */
70 public function createContents()
71 {
72 // Creating record at the beginning of the page
73 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
74 $this->recordIds['newContentIdFirst'] = $newTableIds[self::TABLE_Content][0];
75 // Creating record at the end of the page (after last one)
76 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, -self::VALUE_ContentIdSecond, ['header' => 'Testing #2']);
77 $this->recordIds['newContentIdLast'] = $newTableIds[self::TABLE_Content][0];
78 }
79
80 /**
81 * @see DataSet/Assertion/createContentRecordAndDiscardCreatedContentRecord.csv
82 */
83 public function createContentAndDiscardCreatedContent()
84 {
85 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
86 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
87 $versionedNewContentId = $this->actionService->getDataHandler()->getAutoVersionId(self::TABLE_Content, $this->recordIds['newContentId']);
88 $this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedNewContentId);
89 }
90
91 /**
92 * @see DataSet/Assertion/createAndCopyContentRecordAndDiscardCopiedContentRecord.csv
93 */
94 public function createAndCopyContentAndDiscardCopiedContent()
95 {
96 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
97 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
98 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $this->recordIds['newContentId'], self::VALUE_PageId);
99 $this->recordIds['copiedContentId'] = $copiedTableIds[self::TABLE_Content][$this->recordIds['newContentId']];
100 $versionedCopiedContentId = $this->actionService->getDataHandler()->getAutoVersionId(self::TABLE_Content, $this->recordIds['copiedContentId']);
101 $this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedCopiedContentId);
102 }
103
104 /**
105 * @see DataSet/Assertion/modifyContentRecord.csv
106 */
107 public function modifyContent()
108 {
109 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, ['header' => 'Testing #1']);
110 }
111
112 /**
113 * @see DataSet/Assertion/deleteContentRecord.csv
114 */
115 public function deleteContent()
116 {
117 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
118 }
119
120 /**
121 * @see DataSet/deleteLocalizedContentNDeleteContent.csv
122 */
123 public function deleteLocalizedContentAndDeleteContent()
124 {
125 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized);
126 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdThird);
127 }
128
129 /**
130 * @see DataSet/Assertion/copyContentRecord.csv
131 */
132 public function copyContent()
133 {
134 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageId);
135 $this->recordIds['copiedContentId'] = $copiedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
136 }
137
138 /**
139 * @see DataSet/Assertion/localizeContentRecord.csv
140 */
141 public function localizeContent()
142 {
143 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_LanguageId);
144 $this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
145 }
146
147 /**
148 * @see DataSet/Assertion/changeContentRecordSorting.csv
149 */
150 public function changeContentSorting()
151 {
152 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
153 }
154
155 /**
156 * @see DataSet/changeContentSortingNDeleteMovedRecord.csv
157 */
158 public function changeContentSortingAndDeleteMovedRecord()
159 {
160 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
161 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdFirst);
162 }
163
164 /**
165 * @see DataSet/changeContentSortingNDeleteLiveRecord.csv
166 */
167 public function changeContentSortingAndDeleteLiveRecord()
168 {
169 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
170 // Switch to live workspace
171 $this->backendUser->workspace = 0;
172 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdFirst);
173 // Switch back to draft workspace
174 $this->backendUser->workspace = static::VALUE_WorkspaceId;
175 }
176
177 /**
178 * @see DataSet/Assertion/moveContentRecordToDifferentPage.csv
179 */
180 public function moveContentToDifferentPage()
181 {
182 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
183 }
184
185 /**
186 * @see DataSet/Assertion/moveContentRecordToDifferentPageAndChangeSorting.csv
187 */
188 public function moveContentToDifferentPageAndChangeSorting()
189 {
190 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
191 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
192 }
193
194 /**
195 * Page records
196 */
197
198 /**
199 * @see DataSet/Assertion/createPageRecord.csv
200 */
201 public function createPage()
202 {
203 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
204 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][0];
205 }
206
207 /**
208 * @see DataSet/Assertion/modifyPageRecord.csv
209 */
210 public function modifyPage()
211 {
212 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, ['title' => 'Testing #1']);
213 }
214
215 /**
216 * @see DataSet/Assertion/deletePageRecord.csv
217 */
218 public function deletePage()
219 {
220 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
221 }
222
223 /**
224 * @see DataSet/Assertion/copyPageRecord.csv
225 */
226 public function copyPage()
227 {
228 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
229 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
230 $this->recordIds['newContentIdFirst'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdFirst];
231 $this->recordIds['newContentIdLast'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
232 }
233
234 /**
235 * @see DataSet/Assertion/localizePageRecord.csv
236 */
237 public function localizePage()
238 {
239 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
240 $this->recordIds['localizedPageOverlayId'] = $localizedTableIds[self::TABLE_PageOverlay][self::VALUE_PageId];
241 }
242
243 /**
244 * @see DataSet/Assertion/changePageRecordSorting.csv
245 */
246 public function changePageSorting()
247 {
248 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
249 }
250
251 /**
252 * @see DataSet/Assertion/movePageRecordToDifferentPage.csv
253 */
254 public function movePageToDifferentPage()
255 {
256 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
257 }
258
259 /**
260 * @see DataSet/Assertion/movePageRecordToDifferentPageAndChangeSorting.csv
261 */
262 public function movePageToDifferentPageAndChangeSorting()
263 {
264 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
265 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
266 }
267
268 /**
269 * @see DataSet/Assertion/movePageRecordToDifferentPageAndCreatePageRecordAfterMovedPageRecord.csv
270 * @see http://forge.typo3.org/issues/33104
271 * @see http://forge.typo3.org/issues/55573
272 */
273 public function movePageToDifferentPageAndCreatePageAfterMovedPage()
274 {
275 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
276 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Page, -self::VALUE_PageIdTarget, ['title' => 'Testing #1', 'hidden' => 0]);
277 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][0];
278 }
279
280 /**
281 * Creates a content element and copies the page in draft workspace.
282 */
283 public function createContentAndCopyDraftPage()
284 {
285 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
286 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
287 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
288 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
289 }
290
291 /**
292 * Creates a content element and copies the page in live workspace.
293 */
294 public function createContentAndCopyLivePage()
295 {
296 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
297 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
298
299 // Switch to live workspace
300 $this->backendUser->workspace = 0;
301
302 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
303 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
304
305 // Switch back to draft workspace
306 $this->backendUser->workspace = static::VALUE_WorkspaceId;
307 }
308
309 /**
310 * Creates a page in a draft workspace and copies the parent page in draft workspace.
311 */
312 public function createPageAndCopyDraftParentPage()
313 {
314 $this->backendUser->uc['copyLevels'] = 10;
315
316 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
317 $this->recordIds['newPageId'] = $newTableIds[static::TABLE_Page][0];
318 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
319 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
320 }
321 /**
322 * Creates a page in a draft workspace and copies the parent page in live workspace.
323 */
324 public function createPageAndCopyLiveParentPage()
325 {
326 $this->backendUser->uc['copyLevels'] = 10;
327
328 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
329 $this->recordIds['newPageId'] = $newTableIds[static::TABLE_Page][0];
330
331 // Switch to live workspace
332 $this->backendUser->workspace = 0;
333
334 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
335 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
336
337 // Switch back to draft workspace
338 $this->backendUser->workspace = static::VALUE_WorkspaceId;
339 }
340
341 /**
342 * Creates nested pages in a draft workspace and copies the parent page in draft workspace.
343 */
344 public function createNestedPagesAndCopyDraftParentPage()
345 {
346 $this->backendUser->uc['copyLevels'] = 10;
347
348 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
349 $this->recordIds['newPageIdFirst'] = $newTableIds[static::TABLE_Page][0];
350 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, $this->recordIds['newPageIdFirst'], ['title' => 'Testing #2', 'hidden' => 0]);
351 $this->recordIds['newPageIdSecond'] = $newTableIds[static::TABLE_Page][0];
352 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
353 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
354 $this->recordIds['copiedPageIdFirst'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdFirst']];
355 $this->recordIds['copiedPageIdSecond'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdSecond']];
356 }
357
358 /**
359 * Creates nested pages in a draft workspace and copies the parent page in live workspace.
360 */
361 public function createNestedPagesAndCopyLiveParentPage()
362 {
363 $this->backendUser->uc['copyLevels'] = 10;
364
365 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
366 $this->recordIds['newPageIdFirst'] = $newTableIds[static::TABLE_Page][0];
367 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, $this->recordIds['newPageIdFirst'], ['title' => 'Testing #2', 'hidden' => 0]);
368 $this->recordIds['newPageIdSecond'] = $newTableIds[static::TABLE_Page][0];
369
370 // Switch to live workspace
371 $this->backendUser->workspace = 0;
372
373 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
374 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
375 $this->recordIds['copiedPageIdFirst'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdFirst']];
376 $this->recordIds['copiedPageIdSecond'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdSecond']];
377
378 // Switch back to draft workspace
379 $this->backendUser->workspace = static::VALUE_WorkspaceId;
380 }
381
382 /**
383 * Deletes a content element and copies the page in draft workspace
384 */
385 public function deleteContentAndCopyDraftPage()
386 {
387 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
388 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
389 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
390 }
391
392 /**
393 * Deletes a content element and copies the page in live workspace
394 */
395 public function deleteContentAndCopyLivePage()
396 {
397 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
398
399 // Switch to live workspace
400 $this->backendUser->workspace = 0;
401
402 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
403 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
404
405 // Switch back to draft workspace
406 $this->backendUser->workspace = static::VALUE_WorkspaceId;
407 }
408
409 /**
410 * Changes content sorting and copies the page in draft workspace.
411 */
412 public function changeContentSortingAndCopyDraftPage()
413 {
414 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
415 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
416 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
417 }
418
419 /**
420 * Changes content sorting and copies the page in live workspace.
421 */
422 public function changeContentSortingAndCopyLivePage()
423 {
424 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
425
426 // Switch to live workspace
427 $this->backendUser->workspace = 0;
428
429 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
430 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
431
432 // Switch back to draft workspace
433 $this->backendUser->workspace = static::VALUE_WorkspaceId;
434 }
435
436 /**
437 * Moves content either from and to the current page and copies the page in draft workspace.
438 */
439 public function moveContentAndCopyDraftPage()
440 {
441 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
442 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdZero, self::VALUE_PageId);
443 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
444 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
445 }
446
447 /**
448 * Moves content either from and to the current page and copies the page in draft workspace.
449 */
450 public function moveContentAndCopyLivePage()
451 {
452 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
453 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdZero, self::VALUE_PageId);
454
455 // Switch to live workspace
456 $this->backendUser->workspace = 0;
457
458 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
459 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
460
461 // Switch back to draft workspace
462 $this->backendUser->workspace = static::VALUE_WorkspaceId;
463 }
464
465 /**
466 * Creates new and move placeholders for pages and deleted the parent page in draft workspace.
467 */
468 public function createPlaceholdersAndDeleteDraftParentPage()
469 {
470 $this->backendUser->uc['recursiveDelete'] = true;
471
472 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
473 $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_ParentPageId, ['title' => 'Testing #1']);
474 $newTableIds = $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_ParentPageId);
475 $this->recordIds['deletedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_ParentPageId];
476 }
477
478 /**
479 * Creates new and move placeholders for pages and deleted the parent page in live workspace.
480 */
481 public function createPlaceholdersAndDeleteLiveParentPage()
482 {
483 $this->backendUser->uc['recursiveDelete'] = true;
484
485 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
486 $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_ParentPageId, ['title' => 'Testing #1']);
487
488 // Switch to live workspace
489 $this->backendUser->workspace = 0;
490
491 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_ParentPageId);
492
493 // Switch back to draft workspace
494 $this->backendUser->workspace = static::VALUE_WorkspaceId;
495 }
496 }