[TASK] Enable DataHandler frontend rendering tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / DataHandlerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Tymoteusz Motylewski <t.motylewski@gmail.com>
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 use TYPO3\CMS\Core\Database\DatabaseConnection;
28 use TYPO3\CMS\Core\DataHandling\DataHandler;
29 use TYPO3\CMS\Core\Utility\GeneralUtility;
30
31 /**
32 * Functional test for the DataHandler
33 */
34 class DataHandlerTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
35
36 public function setUp() {
37 parent::setUp();
38
39 /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
40 $backendUser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
41 $backendUser->user['admin'] = 1;
42 $backendUser->user['uid'] = 1;
43 // By default make tests on live workspace
44 $backendUser->workspace = 0;
45 $GLOBALS['BE_USER'] = $backendUser;
46 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
47 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
48 }
49
50 /**
51 * @test
52 */
53 public function canCreateTtContent() {
54 $dataHandler = $this->getDataHandler();
55
56 $temporaryId = uniqid('NEW');
57 $dataArray = array(
58 'tt_content' => array(
59 $temporaryId => array(
60 'pid' => 1,
61 'header' => "Test Title",
62 )
63 )
64 );
65
66 $dataHandler->start($dataArray, array());
67 $dataHandler->process_datamap();
68 $uid = $dataHandler->substNEWwithIDs[$temporaryId];
69
70 $this->assertGreaterThanOrEqual(1, $uid);
71
72 $database = $this->getDatabase();
73 $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $uid);
74 $this->assertNotEmpty($row);
75
76 $this->assertEquals($dataArray['tt_content'][$temporaryId]['pid'], $row['pid']);
77 $this->assertEquals($dataArray['tt_content'][$temporaryId]['header'], $row['header']);
78 $this->assertEquals($uid, $row['uid']);
79 }
80
81 /**
82 * @test
83 */
84 public function canLocalizeTtContent() {
85 $this->importDataSet(__DIR__. '/../Fixtures/sys_language.xml');
86 $this->importDataSet(__DIR__ . '/../Fixtures/pages_language_overlay.xml');
87 $this->importDataSet(__DIR__ . '/../Fixtures/tt_content.xml');
88
89 $dataHandler = $this->getDataHandler();
90 $originalRecordId = 1;
91 $languageRecordUid = 1;
92
93 $commandMap = array(
94 'tt_content' => array(
95 $originalRecordId => array(
96 'localize' => $languageRecordUid
97 )
98 )
99 );
100
101 $dataHandler->start(array(), $commandMap);
102 $dataHandler->process_cmdmap();
103 $uid = $dataHandler->copyMappingArray_merged['tt_content'][$originalRecordId];
104 $this->assertGreaterThanOrEqual(2, $uid);
105
106 $database = $this->getDatabase();
107 $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $uid);
108 $this->assertNotEmpty($row);
109
110 $this->assertEquals(1, $row['pid']);
111 $this->assertContains('Test content', $row['header']);
112 $this->assertEquals($uid, $row['uid']);
113 $this->assertEquals(1, $row['l18n_parent']);
114 }
115
116 /**
117 * @test
118 */
119 public function canCopyPasteTtContent() {
120 $this->importDataSet(dirname(__FILE__) . '/../Fixtures/tt_content.xml');
121 $database = $this->getDatabase();
122
123 $dataHandler = $this->getDataHandler();
124 $originalRecordId = 1;
125 $originalRecord = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $originalRecordId);
126 $targetPage = 2;
127 $targetColumn = 3;
128
129 $commandMap = array(
130 'tt_content' => array(
131 $originalRecordId => array(
132 'copy' => array(
133 'action' => 'paste',
134 'target' => $targetPage,
135 'update' => array(
136 'colPos' => $targetColumn
137 )
138 ),
139 )
140 )
141 );
142
143 $dataHandler->start(array(), $commandMap);
144 $dataHandler->process_cmdmap();
145
146 $rows = $database->exec_SELECTgetRows('*', 'tt_content', '1=1');
147
148 // Check whether there are exactly two records now
149 $rowCount = $database->exec_SELECTcountRows('*', 'tt_content', '1=1');
150 $this->assertEquals(2, $rowCount);
151
152 // Retrieve the UID of the copied record. Should be 2 (auto_increment)
153 $uid = $dataHandler->copyMappingArray_merged['tt_content'][$originalRecordId];
154 $this->assertGreaterThanOrEqual(2, $uid);
155
156 // Retrieve copied record
157 $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $uid);
158 $this->assertNotEmpty($row);
159
160 // Check whether the copy&pasted record is at expected page and column
161 $this->assertEquals($targetPage, $row['pid']);
162 $this->assertEquals($targetColumn, $row['colPos']);
163
164 // Check whether original record has not changed
165 $checkRecord = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $originalRecordId);
166 $this->assertEquals($checkRecord, $originalRecord);
167 }
168
169 /**
170 * @test
171 */
172 public function canCutPasteTtContent() {
173 $this->importDataSet(dirname(__FILE__) . '/../Fixtures/tt_content.xml');
174 $database = $this->getDatabase();
175
176 $dataHandler = $this->getDataHandler();
177 $originalRecordId = 1;
178 $targetPage = 2;
179 $targetColumn = 3;
180
181 $commandMap = array(
182 'tt_content' => array(
183 $originalRecordId => array(
184 'move' => array(
185 'action' => 'paste',
186 'target' => $targetPage,
187 'update' => array(
188 'colPos' => $targetColumn
189 )
190 ),
191 )
192 )
193 );
194
195 $dataHandler->start(array(), $commandMap);
196 $dataHandler->process_cmdmap();
197
198 $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $originalRecordId);
199 $this->assertNotEmpty($row);
200
201 // Check whether the pasted record is at expected page and column
202 $this->assertEquals($targetPage, $row['pid']);
203 $this->assertEquals($targetColumn, $row['colPos']);
204
205 // Check whether this was the only existing record
206 $rowCount = $database->exec_SELECTcountRows('*', 'tt_content', '1=1');
207 $this->assertEquals(1, $rowCount);
208 }
209
210 /**
211 * @return \TYPO3\CMS\Core\DataHandling\DataHandler
212 */
213 protected function getDataHandler() {
214 $dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
215 return $dataHandler;
216 }
217 }