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