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