[TASK] Streamline workspace DataHandler functional tests
[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\Regular\AbstractActionTestCase
21 {
22 const VALUE_ParentPageId = 88;
23 const VALUE_ContentIdZero = 296;
24
25 const VALUE_ContentIdTenth = 310;
26 const VALUE_ContentIdTenthLocalized = 311;
27 const VALUE_ContentIdTenthLocalized2 = 312;
28
29 const VALUE_WorkspaceId = 1;
30
31 /**
32 * @var array
33 */
34 protected $coreExtensionsToLoad = [
35 'fluid',
36 'version',
37 'workspaces',
38 ];
39
40 /**
41 * @var string
42 */
43 protected $scenarioDataSetDirectory = 'typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/DataSet/';
44
45 protected function setUp()
46 {
47 parent::setUp();
48 $this->importScenarioDataSet('LivePageFreeModeElements');
49 $this->importScenarioDataSet('VersionDefaultElements');
50 $this->importScenarioDataSet('ReferenceIndex');
51 $this->backendUser->workspace = self::VALUE_WorkspaceId;
52 }
53
54 /**
55 * Content records
56 */
57
58 /**
59 * @see DataSet/createContentRecordAndDiscardCreatedContentRecord.csv
60 */
61 public function createContentAndDiscardCreatedContent()
62 {
63 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
64 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
65 $versionedNewContentId = $this->actionService->getDataHandler()->getAutoVersionId(self::TABLE_Content, $this->recordIds['newContentId']);
66 $this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedNewContentId);
67 }
68
69 /**
70 * @see DataSet/createAndCopyContentRecordAndDiscardCopiedContentRecord.csv
71 */
72 public function createAndCopyContentAndDiscardCopiedContent()
73 {
74 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
75 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
76 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $this->recordIds['newContentId'], self::VALUE_PageId);
77 $this->recordIds['copiedContentId'] = $copiedTableIds[self::TABLE_Content][$this->recordIds['newContentId']];
78 $versionedCopiedContentId = $this->actionService->getDataHandler()->getAutoVersionId(self::TABLE_Content, $this->recordIds['copiedContentId']);
79 $this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedCopiedContentId);
80 }
81
82 /**
83 * @see DataSet/changeContentSortingNDeleteMovedRecord.csv
84 */
85 public function changeContentSortingAndDeleteMovedRecord()
86 {
87 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
88 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdFirst);
89 }
90
91 /**
92 * @see DataSet/changeContentSortingNDeleteLiveRecord.csv
93 */
94 public function changeContentSortingAndDeleteLiveRecord()
95 {
96 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
97 // Switch to live workspace
98 $this->backendUser->workspace = 0;
99 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdFirst);
100 // Switch back to draft workspace
101 $this->backendUser->workspace = static::VALUE_WorkspaceId;
102 }
103
104 /**
105 * Page records
106 */
107
108 /**
109 * @see DataSet/deleteContentAndPage.csv
110 */
111 public function deleteContentAndPage()
112 {
113 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
114 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
115 }
116
117 /**
118 * @see DataSet/copyPageFreeMode.csv
119 */
120 public function copyPageFreeMode()
121 {
122 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdTarget);
123 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageIdTarget];
124 $this->recordIds['newContentIdTenth'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdTenth];
125 $this->recordIds['newContentIdTenthLocalized'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdTenthLocalized];
126 $this->recordIds['newContentIdTenthLocalized2'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdTenthLocalized2];
127 }
128
129 /**
130 * @see DataSet/movePageRecordToDifferentPageAndCreatePageRecordAfterMovedPageRecord.csv
131 * @see http://forge.typo3.org/issues/33104
132 * @see http://forge.typo3.org/issues/55573
133 */
134 public function movePageToDifferentPageAndCreatePageAfterMovedPage()
135 {
136 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
137 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Page, -self::VALUE_PageIdTarget, ['title' => 'Testing #1', 'hidden' => 0]);
138 $this->recordIds['newPageId'] = $newTableIds[self::TABLE_Page][0];
139 }
140
141 /**
142 * Creates a content element and copies the page in draft workspace.
143 */
144 public function createContentAndCopyDraftPage()
145 {
146 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
147 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
148 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
149 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
150 }
151
152 /**
153 * Creates a content element and copies the page in live workspace.
154 */
155 public function createContentAndCopyLivePage()
156 {
157 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1']);
158 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
159
160 // Switch to live workspace
161 $this->backendUser->workspace = 0;
162
163 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
164 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
165
166 // Switch back to draft workspace
167 $this->backendUser->workspace = static::VALUE_WorkspaceId;
168 }
169
170 /**
171 * Creates a page in a draft workspace and copies the parent page in draft workspace.
172 */
173 public function createPageAndCopyDraftParentPage()
174 {
175 $this->backendUser->uc['copyLevels'] = 10;
176
177 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
178 $this->recordIds['newPageId'] = $newTableIds[static::TABLE_Page][0];
179 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
180 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
181 }
182 /**
183 * Creates a page in a draft workspace and copies the parent page in live workspace.
184 */
185 public function createPageAndCopyLiveParentPage()
186 {
187 $this->backendUser->uc['copyLevels'] = 10;
188
189 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
190 $this->recordIds['newPageId'] = $newTableIds[static::TABLE_Page][0];
191
192 // Switch to live workspace
193 $this->backendUser->workspace = 0;
194
195 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
196 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
197
198 // Switch back to draft workspace
199 $this->backendUser->workspace = static::VALUE_WorkspaceId;
200 }
201
202 /**
203 * Creates nested pages in a draft workspace and copies the parent page in draft workspace.
204 */
205 public function createNestedPagesAndCopyDraftParentPage()
206 {
207 $this->backendUser->uc['copyLevels'] = 10;
208
209 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
210 $this->recordIds['newPageIdFirst'] = $newTableIds[static::TABLE_Page][0];
211 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, $this->recordIds['newPageIdFirst'], ['title' => 'Testing #2', 'hidden' => 0]);
212 $this->recordIds['newPageIdSecond'] = $newTableIds[static::TABLE_Page][0];
213 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
214 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
215 $this->recordIds['copiedPageIdFirst'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdFirst']];
216 $this->recordIds['copiedPageIdSecond'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdSecond']];
217 }
218
219 /**
220 * Creates nested pages in a draft workspace and copies the parent page in live workspace.
221 */
222 public function createNestedPagesAndCopyLiveParentPage()
223 {
224 $this->backendUser->uc['copyLevels'] = 10;
225
226 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, static::VALUE_PageId, ['title' => 'Testing #1', 'hidden' => 0]);
227 $this->recordIds['newPageIdFirst'] = $newTableIds[static::TABLE_Page][0];
228 $newTableIds = $this->actionService->createNewRecord(static::TABLE_Page, $this->recordIds['newPageIdFirst'], ['title' => 'Testing #2', 'hidden' => 0]);
229 $this->recordIds['newPageIdSecond'] = $newTableIds[static::TABLE_Page][0];
230
231 // Switch to live workspace
232 $this->backendUser->workspace = 0;
233
234 $newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
235 $this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
236 $this->recordIds['copiedPageIdFirst'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdFirst']];
237 $this->recordIds['copiedPageIdSecond'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdSecond']];
238
239 // Switch back to draft workspace
240 $this->backendUser->workspace = static::VALUE_WorkspaceId;
241 }
242
243 /**
244 * Deletes a content element and copies the page in draft workspace
245 */
246 public function deleteContentAndCopyDraftPage()
247 {
248 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
249 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
250 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
251 }
252
253 /**
254 * Deletes a content element and copies the page in live workspace
255 */
256 public function deleteContentAndCopyLivePage()
257 {
258 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdSecond);
259
260 // Switch to live workspace
261 $this->backendUser->workspace = 0;
262
263 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
264 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
265
266 // Switch back to draft workspace
267 $this->backendUser->workspace = static::VALUE_WorkspaceId;
268 }
269
270 /**
271 * Changes content sorting and copies the page in draft workspace.
272 */
273 public function changeContentSortingAndCopyDraftPage()
274 {
275 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
276 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
277 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
278 }
279
280 /**
281 * Changes content sorting and copies the page in live workspace.
282 */
283 public function changeContentSortingAndCopyLivePage()
284 {
285 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
286
287 // Switch to live workspace
288 $this->backendUser->workspace = 0;
289
290 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
291 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
292
293 // Switch back to draft workspace
294 $this->backendUser->workspace = static::VALUE_WorkspaceId;
295 }
296
297 /**
298 * Moves content either from and to the current page and copies the page in draft workspace.
299 */
300 public function moveContentAndCopyDraftPage()
301 {
302 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
303 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdZero, self::VALUE_PageId);
304 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
305 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
306 }
307
308 /**
309 * Moves content either from and to the current page and copies the page in draft workspace.
310 */
311 public function moveContentAndCopyLivePage()
312 {
313 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_PageIdTarget);
314 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdZero, self::VALUE_PageId);
315
316 // Switch to live workspace
317 $this->backendUser->workspace = 0;
318
319 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
320 $this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
321
322 // Switch back to draft workspace
323 $this->backendUser->workspace = static::VALUE_WorkspaceId;
324 }
325
326 /**
327 * Creates new and move placeholders for pages and deleted the parent page in draft workspace.
328 */
329 public function createPlaceholdersAndDeleteDraftParentPage()
330 {
331 $this->backendUser->uc['recursiveDelete'] = true;
332
333 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
334 $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_ParentPageId, ['title' => 'Testing #1']);
335 $newTableIds = $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_ParentPageId);
336 $this->recordIds['deletedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_ParentPageId];
337 }
338
339 /**
340 * Creates new and move placeholders for pages and deleted the parent page in live workspace.
341 */
342 public function createPlaceholdersAndDeleteLiveParentPage()
343 {
344 $this->backendUser->uc['recursiveDelete'] = true;
345
346 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
347 $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_ParentPageId, ['title' => 'Testing #1']);
348
349 // Switch to live workspace
350 $this->backendUser->workspace = 0;
351
352 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_ParentPageId);
353
354 // Switch back to draft workspace
355 $this->backendUser->workspace = static::VALUE_WorkspaceId;
356 }
357 }