[TASK] Streamline functional data handling tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / Group / AbstractActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\Group;
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_ContentIdFirst = 297;
25 const VALUE_ContentIdLast = 298;
26 const VALUE_LanguageId = 1;
27 const VALUE_LanguageIdSecond = 2;
28 const VALUE_ElementIdFirst = 1;
29 const VALUE_ElementIdSecond = 2;
30 const VALUE_ElementIdThird = 3;
31
32 const TABLE_Content = 'tt_content';
33 const TABLE_Element = 'tx_testdatahandler_element';
34
35 const FIELD_ContentElement = 'tx_testdatahandler_group';
36
37 /**
38 * @var string
39 */
40 protected $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Group/DataSet/';
41
42 protected function setUp()
43 {
44 $this->testExtensionsToLoad[] = 'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler';
45
46 parent::setUp();
47 $this->importScenarioDataSet('LiveDefaultPages');
48 $this->importScenarioDataSet('LiveDefaultElements');
49 $this->importScenarioDataSet('ReferenceIndex');
50
51 $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
52 }
53
54 /**
55 * Relations
56 */
57
58 /**
59 * @see DataSet/addElementRelation.csv
60 */
61 public function addElementRelation()
62 {
63 $this->actionService->modifyReferences(
64 self::TABLE_Content,
65 self::VALUE_ContentIdFirst,
66 self::FIELD_ContentElement,
67 [self::VALUE_ElementIdFirst, self::VALUE_ElementIdSecond, self::VALUE_ElementIdThird]
68 );
69 }
70
71 /**
72 * @see DataSet/deleteElementRelation.csv
73 */
74 public function deleteElementRelation()
75 {
76 $this->actionService->modifyReferences(
77 self::TABLE_Content,
78 self::VALUE_ContentIdFirst,
79 self::FIELD_ContentElement,
80 [self::VALUE_ElementIdFirst]
81 );
82 }
83
84 /**
85 * @see DataSet/changeElementSorting.csv
86 */
87 public function changeElementSorting()
88 {
89 $this->actionService->moveRecord(self::TABLE_Element, self::VALUE_ElementIdFirst, -self::VALUE_ElementIdSecond);
90 }
91
92 /**
93 * @see DataSet/changeElementRelationSorting.csv
94 */
95 public function changeElementRelationSorting()
96 {
97 $this->actionService->modifyReferences(
98 self::TABLE_Content,
99 self::VALUE_ContentIdFirst,
100 self::FIELD_ContentElement,
101 [self::VALUE_ElementIdSecond, self::VALUE_ElementIdFirst]
102 );
103 }
104
105 /**
106 * @see DataSet/createContentNAddRelation.csv
107 */
108 public function createContentAndAddElementRelation()
109 {
110 $newTableIds = $this->actionService->createNewRecord(
111 self::TABLE_Content,
112 self::VALUE_PageId,
113 ['header' => 'Testing #1', self::FIELD_ContentElement => self::VALUE_ElementIdFirst]
114 );
115 $this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
116 }
117
118 /**
119 * @see DataSet/createContentNCreateRelation.csv
120 */
121 public function createContentAndCreateElementRelation()
122 {
123 $newElementIds = $this->actionService->createNewRecord(self::TABLE_Element, self::VALUE_PageId, ['title' => 'Testing #1']);
124 $this->recordIds['newElementId'] = $newElementIds[self::TABLE_Element][0];
125 // It's not possible to use "NEW..." values for the TCA type 'group'
126 $newContentIds = $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, ['header' => 'Testing #1', self::FIELD_ContentElement => $this->recordIds['newElementId']]);
127 $this->recordIds['newContentId'] = $newContentIds[self::TABLE_Content][0];
128 }
129
130 /**
131 * @see DataSet/modifyElementOfRelation.csv
132 */
133 public function modifyElementOfRelation()
134 {
135 $this->actionService->modifyRecord(self::TABLE_Element, self::VALUE_ElementIdFirst, ['title' => 'Testing #1']);
136 }
137
138 /**
139 * @see DataSet/modifyContentOfRelation.csv
140 */
141 public function modifyContentOfRelation()
142 {
143 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, ['header' => 'Testing #1']);
144 }
145
146 /**
147 * @see DataSet/modifyBothSidesOfRelation.csv
148 */
149 public function modifyBothSidesOfRelation()
150 {
151 $this->actionService->modifyRecord(self::TABLE_Element, self::VALUE_ElementIdFirst, ['title' => 'Testing #1']);
152 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, ['header' => 'Testing #1']);
153 }
154
155 /**
156 * @see DataSet/deleteContentOfRelation.csv
157 */
158 public function deleteContentOfRelation()
159 {
160 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
161 }
162
163 /**
164 * @see DataSet/deleteElementOfRelation.csv
165 */
166 public function deleteElementOfRelation()
167 {
168 $this->actionService->deleteRecord(self::TABLE_Element, self::VALUE_ElementIdFirst);
169 }
170
171 /**
172 * @see DataSet/copyContentOfRelation.csv
173 */
174 public function copyContentOfRelation()
175 {
176 $newTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
177 $this->recordIds['copiedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
178 }
179
180 /**
181 * @see DataSet/copyElementOfRelation.csv
182 */
183 public function copyElementOfRelation()
184 {
185 $newTableIds = $this->actionService->copyRecord(self::TABLE_Element, self::VALUE_ElementIdFirst, self::VALUE_PageId);
186 $this->recordIds['copiedElementId'] = $newTableIds[self::TABLE_Element][self::VALUE_ElementIdFirst];
187 }
188
189 /**
190 * @see DataSet/copyContentToLanguageOfRelation.csv
191 */
192 public function copyContentToLanguageOfRelation()
193 {
194 $newTableIds = $this->actionService->copyRecordToLanguage(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
195 $this->recordIds['localizedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
196 }
197
198 /**
199 * @see DataSet/copyElementToLanguageOfRelation.csv
200 */
201 public function copyElementToLanguageOfRelation()
202 {
203 $newTableIds = $this->actionService->copyRecordToLanguage(self::TABLE_Element, self::VALUE_ElementIdFirst, self::VALUE_LanguageId);
204 $this->recordIds['localizedElementId'] = $newTableIds[self::TABLE_Element][self::VALUE_ElementIdFirst];
205 }
206
207 /**
208 * @see DataSet/localizeContentOfRelation.csv
209 */
210 public function localizeContentOfRelation()
211 {
212 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
213 $this->recordIds['localizedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
214 }
215
216 public function localizeContentOfRelationWithLanguageSynchronization()
217 {
218 $GLOBALS['TCA']['tt_content']['columns'][self::FIELD_ContentElement]['config']['behaviour']['allowLanguageSynchronization'] = true;
219 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
220 $this->recordIds['localizedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
221 $this->actionService->modifyReferences(
222 self::TABLE_Content,
223 self::VALUE_ContentIdLast,
224 self::FIELD_ContentElement,
225 [self::VALUE_ElementIdFirst, self::VALUE_ElementIdSecond]
226 );
227 }
228
229 public function localizeContentChainOfRelationWithLanguageSynchronizationSource()
230 {
231 $GLOBALS['TCA']['tt_content']['columns'][self::FIELD_ContentElement]['config']['behaviour']['allowLanguageSynchronization'] = true;
232 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
233 $this->recordIds['localizedContentIdFirst'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
234 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Content, $this->recordIds['localizedContentIdFirst'], self::VALUE_LanguageIdSecond);
235 $this->recordIds['localizedContentIdSecond'] = $newTableIds[self::TABLE_Content][$this->recordIds['localizedContentIdFirst']];
236 $this->actionService->modifyRecord(
237 self::TABLE_Content,
238 $this->recordIds['localizedContentIdSecond'],
239 ['l10n_state' => [self::FIELD_ContentElement => 'source']]
240 );
241 $this->actionService->modifyReferences(
242 self::TABLE_Content,
243 self::VALUE_ContentIdLast,
244 self::FIELD_ContentElement,
245 [self::VALUE_ElementIdFirst, self::VALUE_ElementIdSecond]
246 );
247 }
248
249 /**
250 * @see DataSet/localizeElementOfRelation.csv
251 */
252 public function localizeElementOfRelation()
253 {
254 $newTableIds = $this->actionService->localizeRecord(self::TABLE_Element, self::VALUE_ElementIdFirst, self::VALUE_LanguageId);
255 $this->recordIds['localizedElementId'] = $newTableIds[self::TABLE_Element][self::VALUE_ElementIdFirst];
256 }
257
258 /**
259 * @see DataSet/moveContentOfRelationToDifferentPage.csv
260 */
261 public function moveContentOfRelationToDifferentPage()
262 {
263 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
264 }
265 }