f208db55475adeef219e49e0902669f3c44b77e7
[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 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', false);
133 $tsfe->sys_language_uid = 0;
134 $GLOBALS['TSFE'] = $tsfe;
135 $sql = array();
136 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
137 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
138 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
139 $this->assertSame($expectedSql, $sql);
140 }
141
142 /**
143 * @test
144 */
145 public function addSysLanguageStatementWorksForForeignLanguageWithoutSubselection() {
146 $table = uniqid('tx_coretest_table');
147 $GLOBALS['TCA'][$table]['ctrl'] = array(
148 'languageField' => 'sys_language_uid'
149 );
150 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', false);
151 $tsfe->sys_language_uid = 2;
152 $GLOBALS['TSFE'] = $tsfe;
153 $sql = array();
154 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
155 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
156 $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1))'));
157 $this->assertSame($expectedSql, $sql);
158 }
159
160 /**
161 * @test
162 */
163 public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionWithoutDeleteStatementReturned() {
164 $table = uniqid('tx_coretest_table');
165 $GLOBALS['TCA'][$table]['ctrl'] = array(
166 'languageField' => 'sys_language_uid',
167 'transOrigPointerField' => 'l10n_parent'
168 );
169 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', false);
170 $tsfe->sys_language_uid = 2;
171 $GLOBALS['TSFE'] = $tsfe;
172 $sql = array();
173 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
174 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
175 $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)))'));
176 $this->assertSame($expectedSql, $sql);
177 }
178
179 /**
180 * @test
181 */
182 public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
183 $table = uniqid('tx_coretest_table');
184 $GLOBALS['TCA'][$table]['ctrl'] = array(
185 'languageField' => 'sys_language_uid',
186 'transOrigPointerField' => 'l10n_parent',
187 'delete' => 'deleted'
188 );
189 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', false);
190 $tsfe->sys_language_uid = 2;
191 $GLOBALS['TSFE'] = $tsfe;
192 $sql = array();
193 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', false);
194 $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
195 $expectedSql = array('additionalWhereClause' => array(
196 '(' . $table . '.sys_language_uid IN (2,-1)' .
197 ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
198 'SELECT ' . $table . '.l10n_parent FROM ' . $table .
199 ' WHERE ' . $table . '.l10n_parent>0 AND ' .
200 $table . '.sys_language_uid>0 AND ' .
201 $table . '.deleted=0)))')
202 );
203 $this->assertSame($expectedSql, $sql);
204 }
205
206 /**
207 * @test
208 */
209 public function orderStatementGenerationWorks() {
210 $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
211 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
212 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
213 $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
214 $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
215 $sql = array();
216 $orderings = array('fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
217 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
218 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
219 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
220 $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
221 $this->assertSame($expectedSql, $sql);
222 }
223
224 /**
225 * @test
226 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
227 */
228 public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
229 $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
230 $mockSource->expects($this->never())->method('getNodeTypeName');
231 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
232 $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
233 $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
234 $sql = array();
235 $orderings = array('fooProperty' => 'unsupported_order');
236 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
237 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
238 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
239 }
240
241 /**
242 * @test
243 */
244 public function orderStatementGenerationWorksWithMultipleOrderings() {
245 $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
246 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
247 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
248 $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
249 $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
250 $sql = array();
251 $orderings = array(
252 'fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
253 'barProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
254 );
255 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
256 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
257 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
258 $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
259 $this->assertSame($expectedSql, $sql);
260 }
261
262 public function providerForVisibilityConstraintStatement() {
263 return array(
264 'in be: include all' => array('BE', TRUE, array(), TRUE, NULL),
265 'in be: ignore enable fields but do not include deleted' => array('BE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
266 '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)')),
267 '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')),
268 'in fe: include all' => array('FE', TRUE, array(), TRUE, NULL),
269 'in fe: ignore enable fields but do not include deleted' => array('FE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
270 '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')),
271 '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'))
272 );
273 }
274
275 /**
276 * @test
277 * @dataProvider providerForVisibilityConstraintStatement
278 */
279 public function visibilityConstraintStatementIsGeneratedAccordingToTheQuerySettings($mode, $ignoreEnableFields, $enableFieldsToBeIgnored, $deletedValue, $expectedSql) {
280 $tableName = 'tx_foo_table';
281 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
282 'enablecolumns' => array(
283 'disabled' => 'disabled_column',
284 'starttime' => 'starttime_column'
285 ),
286 'delete' => 'deleted_column'
287 );
288 $GLOBALS['TSFE'] = new \stdClass();
289 $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
290 $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
291 $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
292 $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue($ignoreEnableFields));
293 $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue($enableFieldsToBeIgnored));
294 $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue($deletedValue));
295 $sql = array();
296 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
297 $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
298 $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
299 $this->assertSame($expectedSql, $sql['additionalWhereClause']);
300 unset($GLOBALS['TCA'][$tableName]);
301 }
302
303 public function providerForRespectEnableFields() {
304 return array(
305 'in be: respectEnableFields=false' => array('BE', FALSE, NULL),
306 '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')),
307 'in be: respectEnableFields=false' => array('FE', FALSE, NULL),
308 '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'))
309 );
310 }
311
312 /**
313 * @test
314 * @dataProvider providerForRespectEnableFields
315 */
316 public function respectEnableFieldsSettingGeneratesCorrectStatement($mode, $respectEnableFields, $expectedSql) {
317 $tableName = 'tx_foo_table';
318 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
319 'enablecolumns' => array(
320 'disabled' => 'disabled_column',
321 'starttime' => 'starttime_column'
322 ),
323 'delete' => 'deleted_column'
324 );
325 $GLOBALS['TSFE'] = new \stdClass();
326 $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
327 $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
328 $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'), array(), '', FALSE);
329 $mockQuerySettings->setRespectEnableFields($respectEnableFields);
330 $sql = array();
331 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
332 $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
333 $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
334 $this->assertSame($expectedSql, $sql['additionalWhereClause']);
335 unset($GLOBALS['TCA'][$tableName]);
336 }
337
338 /**
339 * @test
340 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException
341 */
342 public function visibilityConstraintStatementGenerationThrowsExceptionIfTheQuerySettingsAreInconsistent() {
343 $tableName = 'tx_foo_table';
344 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
345 'enablecolumns' => array(
346 'disabled' => 'disabled_column'
347 ),
348 'delete' => 'deleted_column'
349 );
350 $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
351 $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue(FALSE));
352 $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue(array()));
353 $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue(TRUE));
354 $sql = array();
355 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
356 $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue('FE'));
357 $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
358 unset($GLOBALS['TCA'][$tableName]);
359 }
360
361 /**
362 * @test
363 */
364 public function uidOfAlreadyPersistedValueObjectIsDeterminedCorrectly() {
365 $mockValueObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject', array('_getProperties'), '', FALSE);
366 $mockValueObject->expects($this->any())->method('_getProperties')->will($this->returnValue(array('propertyName' => 'propertyValue')));
367 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnName'), array(), '', FALSE);
368 $mockColumnMap->expects($this->any())->method('getColumnName')->will($this->returnValue('column_name'));
369 $tableName = 'tx_foo_table';
370 $mockDataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnMap', 'getTableName'), array(), '', FALSE);
371 $mockDataMap->expects($this->any())->method('isPersistableProperty')->will($this->returnValue(TRUE));
372 $mockDataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($mockColumnMap));
373 $mockDataMap->expects($this->any())->method('getTableName')->will($this->returnValue($tableName));
374 $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'), array(), '', FALSE);
375 $mockDataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($mockDataMap));
376 $expectedStatement = 'SELECT * FROM tx_foo_table WHERE column_name=?';
377 $expectedParameters = array('plainPropertyValue');
378 $expectedUid = 52;
379 $mockDataBaseHandle = $this->getMock('t3lib_db', array('sql_query', 'sql_fetch_assoc'), array(), '', FALSE);
380 $mockDataBaseHandle->expects($this->once())->method('sql_query')->will($this->returnValue('resource'));
381 $mockDataBaseHandle->expects($this->any())->method('sql_fetch_assoc')->with('resource')->will($this->returnValue(array('uid' => $expectedUid)));
382 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getPlainValue', 'checkSqlErrors', 'replacePlaceholders', 'addVisibilityConstraintStatement'), array(), '', FALSE);
383 $mockTypo3DbBackend->expects($this->once())->method('getPlainValue')->will($this->returnValue('plainPropertyValue'));
384 $mockTypo3DbBackend->expects($this->once())->method('addVisibilityConstraintStatement')->with($this->isInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface'), $tableName, $this->isType('array'));
385 $mockTypo3DbBackend->expects($this->once())->method('replacePlaceholders')->with($expectedStatement, $expectedParameters)->will($this->returnValue('plainPropertyValue'));
386 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
387 $mockTypo3DbBackend->_set('databaseHandle', $mockDataBaseHandle);
388 $result = $mockTypo3DbBackend->_callRef('getUidOfAlreadyPersistedValueObject', $mockValueObject);
389 $this->assertSame($expectedUid, $result);
390 }
391
392 /**
393 * @test
394 */
395 public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview() {
396 $comparisonRow = array(
397 'uid' => '43',
398 'pid' => '42',
399 '_ORIG_pid' => '-1',
400 '_ORIG_uid' => '43'
401 );
402 $row = array(
403 'uid' => '42',
404 'pid' => '42'
405 );
406 $workspaceVersion = array(
407 'uid' => '43',
408 'pid' => '-1'
409 );
410 $languageUid = 2;
411 $workspaceUid = 2;
412 $sourceMock = new \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector('tx_foo', 'Tx_Foo');
413 /** @var $pageSelectMock \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject */
414 $pageSelectMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('movePlhOL', 'getWorkspaceVersionOfRecord'));
415 $pageSelectMock->versioningPreview = TRUE;
416 $pageSelectMock->expects($this->once())->method('getWorkspaceVersionOfRecord')->with($workspaceUid, 'tx_foo', '42')->will($this->returnValue($workspaceVersion));
417 $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
418 $mockTypo3DbBackend->_set('pageSelectObject', $pageSelectMock);
419 $this->assertSame(array($comparisonRow), $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid));
420 }
421
422 }
423
424
425 ?>