[BUGFIX] moveContentRecordToDifferentPageAndChangeSorting fails
[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 modifyContentRecord() {
88 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, array('header' => 'Testing #1'));
89 $this->assertAssertionDataSet('modifyContentRecord');
90
91 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
92 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
93 }
94
95 /**
96 * @test
97 */
98 public function deleteContentRecord() {
99 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
100 $this->assertAssertionDataSet('deleteContentRecord');
101
102 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
103 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #1');
104 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2');
105 }
106
107 /**
108 * @test
109 */
110 public function copyContentRecord() {
111 $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
112 $this->assertAssertionDataSet('copyContentRecord');
113
114 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
115 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2 (copy 1)');
116 }
117
118 /**
119 * @test
120 */
121 public function localizeContentRecord() {
122 $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
123 $this->assertAssertionDataSet('localizeContentRecord');
124
125 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
126 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
127 }
128
129 /**
130 * @test
131 */
132 public function changeContentRecordSorting() {
133 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
134 $this->assertAssertionDataSet('changeContentRecordSorting');
135
136 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
137 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
138 }
139
140 /**
141 * @test
142 */
143 public function moveContentRecordToDifferentPage() {
144 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
145 $this->assertAssertionDataSet('moveContentRecordToDifferentPage');
146
147 $responseContentSource = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
148 $this->assertResponseContentHasRecords($responseContentSource, self::TABLE_Content, 'header', 'Regular Element #1');
149 $responseContentTarget = $this->getFrontendResponse(self::VALUE_PageIdTarget, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
150 $this->assertResponseContentHasRecords($responseContentTarget, self::TABLE_Content, 'header', 'Regular Element #2');
151 }
152
153 /**
154 * @test
155 */
156 public function moveContentRecordToDifferentPageAndChangeSorting() {
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 $this->assertAssertionDataSet('moveContentRecordToDifferentPageAndChangeSorting');
160
161 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
162 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
163 }
164
165 /**
166 * Page records
167 */
168
169 /**
170 * @test
171 */
172 public function createPageRecord() {
173 $newTableIds = $this->actionService->createNewRecord(self::TABLE_Page, self::VALUE_PageId, array('title' => 'Testing #1', 'hidden' => 0));
174 $this->assertAssertionDataSet('createPageRecord');
175
176 $newPageId = $newTableIds[self::TABLE_Page][0];
177 $responseContent = $this->getFrontendResponse($newPageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
178 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Testing #1');
179 }
180
181 /**
182 * @test
183 */
184 public function modifyPageRecord() {
185 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, array('title' => 'Testing #1'));
186 $this->assertAssertionDataSet('modifyPageRecord');
187
188 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
189 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Testing #1');
190 }
191
192 /**
193 * @test
194 */
195 public function deletePageRecord() {
196 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
197 $this->assertAssertionDataSet('deletePageRecord');
198
199 $response = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId, FALSE);
200 $this->assertContains('RuntimeException', $response->getError());
201 }
202
203 /**
204 * @test
205 */
206 public function copyPageRecord() {
207 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
208 $this->assertAssertionDataSet('copyPageRecord');
209
210 $newPageId = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
211 $responseContent = $this->getFrontendResponse($newPageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
212 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Relations');
213 }
214
215 /**
216 * @test
217 */
218 public function localizePageRecord() {
219 $this->actionService->localizeRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
220 $this->assertAssertionDataSet('localizePageRecord');
221
222 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
223 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', '[Translate to Dansk:] Relations');
224 }
225
226 /**
227 * @test
228 */
229 public function changePageRecordSorting() {
230 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
231 $this->assertAssertionDataSet('changePageRecordSorting');
232
233 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
234 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Relations');
235 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
236 }
237
238 /**
239 * @test
240 */
241 public function movePageRecordToDifferentPage() {
242 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
243 $this->assertAssertionDataSet('movePageRecordToDifferentPage');
244
245 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
246 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Relations');
247 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
248 }
249
250 /**
251 * @test
252 */
253 public function movePageRecordToDifferentPageAndChangeSorting() {
254 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
255 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageId, -self::VALUE_PageIdTarget);
256 $this->assertAssertionDataSet('movePageRecordToDifferentPageAndChangeSorting');
257
258 $responseContentPage = $this->getFrontendResponse(self::VALUE_PageId, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
259 $this->assertResponseContentHasRecords($responseContentPage, self::TABLE_Page, 'title', 'Relations');
260 $this->assertResponseContentHasRecords($responseContentPage, self::TABLE_Content, 'header', array('Regular Element #1', 'Regular Element #2'));
261 $responseContentWebsite = $this->getFrontendResponse(self::VALUE_PageIdWebsite, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
262 $this->assertResponseContentStructureHasRecords(
263 $responseContentWebsite, self::TABLE_Page . ':' . self::VALUE_PageIdWebsite, '__pages',
264 self::TABLE_Page, 'title', array('Target', 'Relations', 'DataHandlerTest')
265 );
266 }
267
268 /**
269 * @test
270 * @see http://forge.typo3.org/issues/33104
271 * @see http://forge.typo3.org/issues/55573
272 */
273 public function movePageRecordToDifferentPageAndCreatePageRecordAfterMovedPageRecord() {
274 $this->actionService->moveRecord(self::TABLE_Page, self::VALUE_PageIdTarget, self::VALUE_PageIdWebsite);
275 $this->actionService->createNewRecord(self::TABLE_Page, -self::VALUE_PageIdTarget, array('title' => 'Testing #1', 'hidden' => 0));
276 $this->assertAssertionDataSet('movePageRecordToDifferentPageAndCreatePageRecordAfterMovedPageRecord');
277
278 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdWebsite, 0, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseContent();
279 $this->assertResponseContentStructureHasRecords(
280 $responseContent, self::TABLE_Page . ':' . self::VALUE_PageIdWebsite, '__pages',
281 self::TABLE_Page, 'title', array('Target', 'Testing #1', 'DataHandlerTest')
282 );
283 }
284
285 }