[BUGFIX] Typo3DbBackend language handling crashes in BE
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Storage / Typo3DbBackendTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Storage;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * All rights reserved
9 *
10 * This class is a backport of the corresponding class of FLOW3.
11 * All credits go to the v5 team.
12 *
13 * This script is part of the TYPO3 project. The TYPO3 project is
14 * free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * The GNU General Public License can be found at
20 * http://www.gnu.org/copyleft/gpl.html.
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
30
31 /**
32 * This is the data provider for the statement generation with a basic comparison
33 *
34 * @return array An array of data
35 */
36 public function providerForBasicComparison() {
37 return array(
38 'equal' => array(
39 \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO,
40 'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = \'baz\''
41 ),
42 'less' => array(
43 \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LESS_THAN,
44 'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < \'baz\''
45 ),
46 'less or equal' => array(
47 \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
48 'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= \'baz\''
49 ),
50 'greater' => array(
51 \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_GREATER_THAN,
52 'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > \'baz\''
53 ),
54 'greater or equal' => array(
55 \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
56 'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= \'baz\''
57 )
58 );
59 }
60
61 /**
62 * @test
63 */
64 public function getStatementWorksWithMinimalisticQueryObjectModel() {
65 $this->markTestIncomplete();
66 }
67
68 /**
69 * @test
70 */
71 public function getStatementWorksWithBasicEqualsCondition() {
72 $this->markTestIncomplete();
73 }
74
75 /**
76 * @test
77 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
78 */
79 public function countRowsWithStatementConstraintResultsInAnException() {
80 $this->markTestIncomplete();
81 }
82
83 /**
84 * @test
85 */
86 public function joinStatementGenerationWorks() {
87 $this->markTestIncomplete();
88 }
89
90 /**
91 * @test
92 */
93 public function addSysLanguageStatementWorksForDefaultLanguage() {
94 $table = uniqid('tx_coretest_table');
95 $GLOBALS['TCA'][$table]['ctrl'] = array(
96 'languageField' => 'sys_language_uid'
97 );
98 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', false);
99 $tsfe->sys_language_uid = 0;
100 $GLOBALS['TSFE'] = $tsfe;
101 $sql = array();
102 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
103 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
104 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
105 $this->assertSame($expectedSql, $sql);
106 }
107
108 /**
109 * @test
110 */
111 public function addSysLanguageStatementWorksInBackendContextWithNoGlobalTypoScriptFrontendControllerAvailable() {
112 $table = uniqid('tx_coretest_table');
113 $GLOBALS['TCA'][$table]['ctrl'] = array(
114 'languageField' => 'sys_language_uid'
115 );
116 $sql = array();
117 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
118 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
119 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
120 $this->assertSame($expectedSql, $sql);
121 }
122
123 /**
124 * @test
125 */
126 public function addSysLanguageStatementWorksForDefaultLanguageWithoutDeleteStatementReturned() {
127 $table = uniqid('tx_coretest_table');
128 $GLOBALS['TCA'][$table]['ctrl'] = array(
129 'languageField' => 'sys_language_uid',
130 'delete' => 'deleted'
131 );
132 $sql = array();
133 $languageUid = 0;
134 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
135 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $languageUid);
136 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
137 $this->assertSame($expectedSql, $sql);
138 }
139
140 /**
141 * @test
142 */
143 public function addSysLanguageStatementWorksForForeignLanguageWithoutSubselection() {
144 $table = uniqid('tx_coretest_table');
145 $GLOBALS['TCA'][$table]['ctrl'] = array(
146 'languageField' => 'sys_language_uid'
147 );
148 $sql = array();
149 $languageUid = 2;
150 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
151 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $languageUid);
152 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1))'));
153 $this->assertSame($expectedSql, $sql);
154 }
155
156 /**
157 * @test
158 */
159 public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionWithoutDeleteStatementReturned() {
160 $table = uniqid('tx_coretest_table');
161 $GLOBALS['TCA'][$table]['ctrl'] = array(
162 'languageField' => 'sys_language_uid',
163 'transOrigPointerField' => 'l10n_parent'
164 );
165 $sql = array();
166 $languageUid = 2;
167 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
168 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $languageUid);
169 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1) OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (SELECT ' . $table . '.l10n_parent FROM ' . $table . ' WHERE ' . $table . '.l10n_parent>0 AND ' . $table . '.sys_language_uid>0)))'));
170 $this->assertSame($expectedSql, $sql);
171 }
172
173 /**
174 * @test
175 */
176 public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
177 $table = uniqid('tx_coretest_table');
178 $GLOBALS['TCA'][$table]['ctrl'] = array(
179 'languageField' => 'sys_language_uid',
180 'transOrigPointerField' => 'l10n_parent',
181 'delete' => 'deleted'
182 );
183 $sql = array();
184 $languageUid = 2;
185 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
186 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $languageUid);
187 $expectedSql = array('additionalWhereClause' => array(
188 '(' . $table . '.sys_language_uid IN (2,-1)' .
189 ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
190 'SELECT ' . $table . '.l10n_parent FROM ' . $table .
191 ' WHERE ' . $table . '.l10n_parent>0 AND ' .
192 $table . '.sys_language_uid>0 AND ' .
193 $table . '.deleted=0)))')
194 );
195 $this->assertSame($expectedSql, $sql);
196 }
197
198 /**
199 * @test
200 */
201 public function addSysLanguageStatementWorksInBackendContextWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
202 $table = uniqid('tx_coretest_table');
203 $GLOBALS['TCA'][$table]['ctrl'] = array(
204 'languageField' => 'sys_language_uid',
205 'transOrigPointerField' => 'l10n_parent',
206 'delete' => 'deleted'
207 );
208 $sql = array();
209 $languageUid = 2;
210 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
211 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $languageUid);
212 $expectedSql = array('additionalWhereClause' => array(
213 '(' . $table . '.sys_language_uid IN (2,-1)' .
214 ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
215 'SELECT ' . $table . '.l10n_parent FROM ' . $table .
216 ' WHERE ' . $table . '.l10n_parent>0 AND ' .
217 $table . '.sys_language_uid>0 AND ' .
218 $table . '.deleted=0)))')
219 );
220 $this->assertSame($expectedSql, $sql);
221 }
222
223 /**
224 * @test
225 */
226 public function orderStatementGenerationWorks() {
227 $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
228 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
229 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
230 $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
231 $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
232 $sql = array();
233 $orderings = array('fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
234 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
235 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
236 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
237 $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
238 $this->assertSame($expectedSql, $sql);
239 }
240
241 /**
242 * @test
243 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
244 */
245 public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
246 $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
247 $mockSource->expects($this->never())->method('getNodeTypeName');
248 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
249 $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
250 $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
251 $sql = array();
252 $orderings = array('fooProperty' => 'unsupported_order');
253 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
254 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
255 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
256 }
257
258 /**
259 * @test
260 */
261 public function orderStatementGenerationWorksWithMultipleOrderings() {
262 $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
263 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
264 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
265 $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
266 $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
267 $sql = array();
268 $orderings = array(
269 'fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
270 'barProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
271 );
272 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
273 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
274 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
275 $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
276 $this->assertSame($expectedSql, $sql);
277 }
278
279 public function providerForVisibilityConstraintStatement() {
280 return array(
281 'in be: include all' => array('BE', TRUE, array(), TRUE, NULL),
282 'in be: ignore enable fields but do not include deleted' => array('BE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
283 'in be: respect enable fields but include deleted' => array('BE', FALSE, array(), TRUE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789)')),
284 'in be: respect enable fields and do not include deleted' => array('BE', FALSE, array(), FALSE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0')),
285 'in fe: include all' => array('FE', TRUE, array(), TRUE, NULL),
286 'in fe: ignore enable fields but do not include deleted' => array('FE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
287 'in fe: ignore only starttime and do not include deleted' => array('FE', TRUE, array('starttime'), FALSE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0')),
288 'in fe: respect enable fields and do not include deleted' => array('FE', FALSE, array(), FALSE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789'))
289 );
290 }
291
292 /**
293 * @test
294 * @dataProvider providerForVisibilityConstraintStatement
295 */
296 public function visibilityConstraintStatementIsGeneratedAccordingToTheQuerySettings($mode, $ignoreEnableFields, $enableFieldsToBeIgnored, $deletedValue, $expectedSql) {
297 $tableName = 'tx_foo_table';
298 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
299 'enablecolumns' => array(
300 'disabled' => 'disabled_column',
301 'starttime' => 'starttime_column'
302 ),
303 'delete' => 'deleted_column'
304 );
305 $GLOBALS['TSFE'] = new \stdClass();
306 $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
307 $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
308 $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
309 $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue($ignoreEnableFields));
310 $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue($enableFieldsToBeIgnored));
311 $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue($deletedValue));
312 $sql = array();
313 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
314 $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
315 $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
316 $this->assertSame($expectedSql, $sql['additionalWhereClause']);
317 unset($GLOBALS['TCA'][$tableName]);
318 }
319
320 public function providerForRespectEnableFields() {
321 return array(
322 'in be: respectEnableFields=false' => array('BE', FALSE, NULL),
323 'in be: respectEnableFields=true' => array('BE', TRUE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0')),
324 'in be: respectEnableFields=false' => array('FE', FALSE, NULL),
325 'in be: respectEnableFields=true' => array('FE', TRUE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789'))
326 );
327 }
328
329 /**
330 * @test
331 * @dataProvider providerForRespectEnableFields
332 */
333 public function respectEnableFieldsSettingGeneratesCorrectStatement($mode, $respectEnableFields, $expectedSql) {
334 $tableName = 'tx_foo_table';
335 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
336 'enablecolumns' => array(
337 'disabled' => 'disabled_column',
338 'starttime' => 'starttime_column'
339 ),
340 'delete' => 'deleted_column'
341 );
342 $GLOBALS['TSFE'] = new \stdClass();
343 $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
344 $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
345 $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'), array(), '', FALSE);
346 $mockQuerySettings->setRespectEnableFields($respectEnableFields);
347 $sql = array();
348 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
349 $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
350 $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
351 $this->assertSame($expectedSql, $sql['additionalWhereClause']);
352 unset($GLOBALS['TCA'][$tableName]);
353 }
354
355 /**
356 * @test
357 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException
358 */
359 public function visibilityConstraintStatementGenerationThrowsExceptionIfTheQuerySettingsAreInconsistent() {
360 $tableName = 'tx_foo_table';
361 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
362 'enablecolumns' => array(
363 'disabled' => 'disabled_column'
364 ),
365 'delete' => 'deleted_column'
366 );
367 $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
368 $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue(FALSE));
369 $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue(array()));
370 $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue(TRUE));
371 $sql = array();
372 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
373 $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue('FE'));
374 $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
375 unset($GLOBALS['TCA'][$tableName]);
376 }
377
378 /**
379 * @test
380 */
381 public function uidOfAlreadyPersistedValueObjectIsDeterminedCorrectly() {
382 $mockValueObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject', array('_getProperties'), '', FALSE);
383 $mockValueObject->expects($this->any())->method('_getProperties')->will($this->returnValue(array('propertyName' => 'propertyValue')));
384 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnName'), array(), '', FALSE);
385 $mockColumnMap->expects($this->any())->method('getColumnName')->will($this->returnValue('column_name'));
386 $tableName = 'tx_foo_table';
387 $mockDataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnMap', 'getTableName'), array(), '', FALSE);
388 $mockDataMap->expects($this->any())->method('isPersistableProperty')->will($this->returnValue(TRUE));
389 $mockDataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($mockColumnMap));
390 $mockDataMap->expects($this->any())->method('getTableName')->will($this->returnValue($tableName));
391 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'), array(), '', FALSE);
392 $mockDataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($mockDataMap));
393 $expectedStatement = 'SELECT * FROM tx_foo_table WHERE column_name=?';
394 $expectedParameters = array('plainPropertyValue');
395 $expectedUid = 52;
396 $mockDataBaseHandle = $this->getMock('t3lib_db', array('sql_query', 'sql_fetch_assoc'), array(), '', FALSE);
397 $mockDataBaseHandle->expects($this->once())->method('sql_query')->will($this->returnValue('resource'));
398 $mockDataBaseHandle->expects($this->any())->method('sql_fetch_assoc')->with('resource')->will($this->returnValue(array('uid' => $expectedUid)));
399 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getPlainValue', 'checkSqlErrors', 'replacePlaceholders', 'addVisibilityConstraintStatement'), array(), '', FALSE);
400 $mockTypo3DbBackend->expects($this->once())->method('getPlainValue')->will($this->returnValue('plainPropertyValue'));
401 $mockTypo3DbBackend->expects($this->once())->method('addVisibilityConstraintStatement')->with($this->isInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface'), $tableName, $this->isType('array'));
402 $mockTypo3DbBackend->expects($this->once())->method('replacePlaceholders')->with($expectedStatement, $expectedParameters)->will($this->returnValue('plainPropertyValue'));
403 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
404 $mockTypo3DbBackend->_set('databaseHandle', $mockDataBaseHandle);
405 $result = $mockTypo3DbBackend->_callRef('getUidOfAlreadyPersistedValueObject', $mockValueObject);
406 $this->assertSame($expectedUid, $result);
407 }
408
409 /**
410 * @test
411 */
412 public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview() {
413 $comparisonRow = array(
414 'uid' => '43',
415 'pid' => '42',
416 '_ORIG_pid' => '-1',
417 '_ORIG_uid' => '43'
418 );
419 $row = array(
420 'uid' => '42',
421 'pid' => '42'
422 );
423 $workspaceVersion = array(
424 'uid' => '43',
425 'pid' => '-1'
426 );
427 $languageUid = 2;
428 $workspaceUid = 2;
429 $sourceMock = new \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector('tx_foo', 'Tx_Foo');
430 /** @var $pageSelectMock \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject */
431 $pageSelectMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('movePlhOL', 'getWorkspaceVersionOfRecord'));
432 $pageSelectMock->versioningPreview = TRUE;
433 $pageSelectMock->expects($this->once())->method('getWorkspaceVersionOfRecord')->with($workspaceUid, 'tx_foo', '42')->will($this->returnValue($workspaceVersion));
434 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
435 $mockTypo3DbBackend->_set('pageSelectObject', $pageSelectMock);
436 $this->assertSame(array($comparisonRow), $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid));
437 }
438
439 }
440
441
442 ?>