[TASK] Add functional tests for discarding created elements
[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 * Copyright notice
6 *
7 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 require_once __DIR__ . '/../../../../../core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php';
28
29 /**
30 * Functional test for the DataHandler
31 */
32 abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase {
33
34 const VALUE_PageId = 89;
35 const VALUE_PageIdTarget = 90;
36 const VALUE_PageIdWebsite = 1;
37 const VALUE_ContentIdFirst = 297;
38 const VALUE_ContentIdLast = 298;
39 const VALUE_LanguageId = 1;
40 const VALUE_WorkspaceId = 1;
41
42 const TABLE_Page = 'pages';
43 const TABLE_Content = 'tt_content';
44
45 /**
46 * @var array
47 */
48 protected $coreExtensionsToLoad = array(
49 'version',
50 'workspaces',
51 );
52
53 /**
54 * @var string
55 */
56 protected $dataSetDirectory = 'typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/DataSet/';
57
58 public function setUp() {
59 parent::setUp();
60 $this->importScenarioDataSet('LiveDefaultPages');
61 $this->importScenarioDataSet('LiveDefaultElements');
62
63 $this->setUpFrontendRootPage(1, array('typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts'));
64 }
65
66 /**
67 * Content records
68 */
69
70 /**
71 * @test
72 */
73 public function createContentRecords() {
74 // Creating record at the beginning of the page
75 $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, array('header' => 'Testing #1'));
76 // Creating record at the end of the page (after last one)
77 $this->actionService->createNewRecord(self::TABLE_Content, -self::VALUE_ContentIdLast, array('header' => 'Testing #2'));
78 $this->assertAssertionDataSet('createContentRecords');
79
80 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
81 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Testing #1', 'Testing #2'));
82 }
83
84 /**
85 * @test
86 */
87 public function createContentRecordAndDiscardCreatedContentRecord() {
88 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, array('header' => 'Testing #1'));
89 $newContentId = $newTableIds[self::TABLE_Content][0];
90 $versionedNewContentId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Content, $newContentId);
91 $this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedNewContentId);
92 $this->assertAssertionDataSet('createContentRecordAndDiscardCreatedContentRecord');
93
94 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
95 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
96 }
97
98 /**
99 * @test
100 */
101 public function createAndCopyContentRecordAndDiscardCopiedContentRecord() {
102 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, array('header' => 'Testing #1'));
103 $newContentId = $newTableIds[self::TABLE_Content][0];
104 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $newContentId, self::VALUE_PageId);
105 $copiedContentId = $copiedTableIds[self::TABLE_Content][$newContentId];
106 $versionedCopiedContentId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Content, $copiedContentId);
107 $this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedCopiedContentId);
108 $this->assertAssertionDataSet('createAndCopyContentRecordAndDiscardCopiedContentRecord');
109
110 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
111 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
112 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1 (copy 1)');
113 }
114
115 /**
116 * @test
117 */
118 public function modifyContentRecord() {
119 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, array('header' => 'Testing #1'));
120 $this->assertAssertionDataSet('modifyContentRecord');
121
122 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
123 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
124 }
125
126 /**
127 * @test
128 */
129 public function deleteContentRecord() {
130 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
131 $this->assertAssertionDataSet('deleteContentRecord');
132
133 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
134 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #1');
135 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2');
136 }
137
138 /**
139 * @test
140 */
141 public function copyContentRecord() {
142 $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
143 $this->assertAssertionDataSet('copyContentRecord');
144
145 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
146 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2 (copy 1)');
147 }
148
149 /**
150 * @test
151 */
152 public function localizeContentRecord() {
153 $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
154 $this->assertAssertionDataSet('localizeContentRecord');
155
156 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
157 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
158 }
159
160 /**
161 * @test
162 */
163 public function changeContentRecordSorting() {
164 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
165 $this->assertAssertionDataSet('changeContentRecordSorting');
166
167 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
168 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
169 }
170
171 /**
172 * @test
173 */
174 public function moveContentRecordToDifferentPage() {
175 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
176 $this->assertAssertionDataSet('moveContentRecordToDifferentPage');
177
178 $responseContentSource = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
179 $this->assertResponseContentHasRecords($responseContentSource, self::TABLE_Content, 'header', 'Regular Element #1');
180 $responseContentTarget = $this->getFrontendResponse(self::VALUE_PageIdTarget, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
181 $this->assertResponseContentHasRecords($responseContentTarget, self::TABLE_Content, 'header', 'Regular Element #2');
182 }
183
184 /**
185 * @test
186 */
187 public function moveContentRecordToDifferentPageAndChangeSorting() {
188 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
189 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
190 $this->assertAssertionDataSet('moveContentRecordToDifferentPageAndChangeSorting');
191
192 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
193 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
194 }
195
196 /**
197 * Page records
198 */
199
200 /**
201 * @test
202 */
203 public function createPageRecord() {
204 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_PageId, array('title' => 'Testing #1', 'hidden' => 0));
205 $this->assertAssertionDataSet('createPageRecord');
206
207 $newPageId = $newTableIds[self::TABLE_Page][0];
208 $responseContent = $this->getFrontendResponse($newPageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
209 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Testing #1');
210 }
211
212 /**
213 * @test
214 */
215 public function modifyPageRecord() {
216 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, array('title' => 'Testing #1'));
217 $this->assertAssertionDataSet('modifyPageRecord');
218
219 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
220 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Testing #1');
221 }
222
223 /**
224 * @test
225 */
226 public function deletePageRecord() {
227 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
228 $this->assertAssertionDataSet('deletePageRecord');
229
230 $response = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId, FALSE);
231 $this->assertContains('RuntimeException', $response->getError());
232 }
233
234 /**
235 * @test
236 */
237 public function copyPageRecord() {
238 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
239 $this->assertAssertionDataSet('copyPageRecord');
240
241 $newPageId = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
242 $responseContent = $this->getFrontendResponse($newPageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
243 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Relations');
244 }
245
246 /**
247 * @test
248 */
249 public function localizePageRecord() {
250 $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
251 $this->assertAssertionDataSet('localizePageRecord');
252
253 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
254 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', '[Translate to Dansk:] Relations');
255 }
256
257 /**
258 * @test
259 */
260 public function changePageRecordSorting() {
261 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
262 $this->assertAssertionDataSet('changePageRecordSorting');
263
264 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
265 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Relations');
266 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
267 }
268
269 /**
270 * @test
271 */
272 public function movePageRecordToDifferentPage() {
273 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
274 $this->assertAssertionDataSet('movePageRecordToDifferentPage');
275
276 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
277 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Relations');
278 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
279 }
280
281 /**
282 * @test
283 */
284 public function movePageRecordToDifferentPageAndChangeSorting() {
285 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
286 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
287 $this->assertAssertionDataSet('movePageRecordToDifferentPageAndChangeSorting');
288
289 $responseContentPage = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
290 $this->assertResponseContentHasRecords($responseContentPage, self::TABLE_Page, 'title', 'Relations');
291 $this->assertResponseContentHasRecords($responseContentPage, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
292 $responseContentWebsite = $this->getFrontendResponse(self::VALUE_PageIdWebsite, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
293 $this->assertResponseContentStructureHasRecords(
294 $responseContentWebsite, self::TABLE_Page . ':' . self::VALUE_PageIdWebsite, '__pages',
295 self::TABLE_Page, 'title', array('Target', 'Relations', 'DataHandlerTest')
296 );
297 }
298
299 /**
300 * @test
301 * @see http://forge.typo3.org/issues/33104
302 * @see http://forge.typo3.org/issues/55573
303 */
304 public function movePageRecordToDifferentPageAndCreatePageRecordAfterMovedPageRecord() {
305 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
306 $this->actionService->createNewRecord(self::TABLE_Page, -self::VALUE_PageIdTarget, array('title' => 'Testing #1', 'hidden' => 0));
307 $this->assertAssertionDataSet('movePageRecordToDifferentPageAndCreatePageRecordAfterMovedPageRecord');
308
309 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdWebsite, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
310 $this->assertResponseContentStructureHasRecords(
311 $responseContent, self::TABLE_Page . ':' . self::VALUE_PageIdWebsite, '__pages',
312 self::TABLE_Page, 'title', array('Target', 'Testing #1', 'DataHandlerTest')
313 );
314 }
315
316 }