[!!!][BUGFIX] Respect rootLevel -1 for extbase queries
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Generic / Storage / Typo3DbQueryParserTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Storage;
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 class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
17
18 /**
19 * @test
20 */
21 public function addSysLanguageStatementWorksForDefaultLanguage() {
22 $table = $this->getUniqueId('tx_coretest_table');
23 $GLOBALS['TCA'][$table]['ctrl'] = array(
24 'languageField' => 'sys_language_uid'
25 );
26 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings|\PHPUnit_Framework_MockObject_MockObject $querySettings */
27 $querySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
28 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
29 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
30 $expectedSql = '(' . $table . '.sys_language_uid IN (0,-1))';
31 $this->assertSame($expectedSql, $sql);
32 }
33
34 /**
35 * @test
36 */
37 public function addSysLanguageStatementWorksForNonDefaultLanguage() {
38 $table = $this->getUniqueId('tx_coretest_table');
39 $GLOBALS['TCA'][$table]['ctrl'] = array(
40 'languageField' => 'sys_language_uid'
41 );
42 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings|\PHPUnit_Framework_MockObject_MockObject $querySettings */
43 $querySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class, array('dummy'));
44 $querySettings->setLanguageUid('1');
45 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
46 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
47 $result = '(' . $table . '.sys_language_uid IN (1,-1))';
48 $this->assertSame($result, $sql);
49 }
50
51 /**
52 * @test
53 */
54 public function addSysLanguageStatementWorksInBackendContextWithNoGlobalTypoScriptFrontendControllerAvailable() {
55 $table = $this->getUniqueId('tx_coretest_table');
56 $GLOBALS['TCA'][$table]['ctrl'] = array(
57 'languageField' => 'sys_language_uid'
58 );
59 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
60 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
61 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
62 $expectedSql = '(' . $table . '.sys_language_uid IN (0,-1))';
63 $this->assertSame($expectedSql, $sql);
64 }
65
66 /**
67 * @test
68 */
69 public function addSysLanguageStatementWorksForDefaultLanguageWithoutDeleteStatementReturned() {
70 $table = $this->getUniqueId('tx_coretest_table');
71 $GLOBALS['TCA'][$table]['ctrl'] = array(
72 'languageField' => 'sys_language_uid',
73 'delete' => 'deleted'
74 );
75 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
76 $querySettings->setLanguageUid(0);
77 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
78 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
79 $expectedSql = '(' . $table . '.sys_language_uid IN (0,-1))';
80 $this->assertSame($expectedSql, $sql);
81 }
82
83 /**
84 * @test
85 */
86 public function addSysLanguageStatementWorksForForeignLanguageWithoutSubselection() {
87 $table = $this->getUniqueId('tx_coretest_table');
88 $GLOBALS['TCA'][$table]['ctrl'] = array(
89 'languageField' => 'sys_language_uid'
90 );
91 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
92 $querySettings->setLanguageUid(2);
93 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
94 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
95 $expectedSql = '(' . $table . '.sys_language_uid IN (2,-1))';
96 $this->assertSame($expectedSql, $sql);
97 }
98
99 /**
100 * @test
101 */
102 public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionWithoutDeleteStatementReturned() {
103 $table = $this->getUniqueId('tx_coretest_table');
104 $GLOBALS['TCA'][$table]['ctrl'] = array(
105 'languageField' => 'sys_language_uid',
106 'transOrigPointerField' => 'l10n_parent'
107 );
108 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
109 $querySettings->setLanguageUid(2);
110 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
111 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
112 $expectedSql = '(' . $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=2)))';
113 $this->assertSame($expectedSql, $sql);
114 }
115
116 /**
117 * @test
118 */
119 public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
120 $table = $this->getUniqueId('tx_coretest_table');
121 $GLOBALS['TCA'][$table]['ctrl'] = array(
122 'languageField' => 'sys_language_uid',
123 'transOrigPointerField' => 'l10n_parent',
124 'delete' => 'deleted'
125 );
126 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
127 $querySettings->setLanguageUid(2);
128 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
129 $sql= $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
130 $expectedSql = '(' . $table . '.sys_language_uid IN (2,-1)' .
131 ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
132 'SELECT ' . $table . '.l10n_parent FROM ' . $table .
133 ' WHERE ' . $table . '.l10n_parent>0 AND ' .
134 $table . '.sys_language_uid=2 AND ' .
135 $table . '.deleted=0)))';
136 $this->assertSame($expectedSql, $sql);
137 }
138
139 /**
140 * @test
141 */
142 public function addSysLanguageStatementWorksInBackendContextWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
143 $table = 'tt_content';
144 $GLOBALS['TCA'][$table]['ctrl'] = array(
145 'languageField' => 'sys_language_uid',
146 'transOrigPointerField' => 'l10n_parent',
147 'delete' => 'deleted'
148 );
149 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
150 $querySettings->setLanguageUid(2);
151 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
152 $sql = $mockTypo3DbQueryParser->_callRef('getSysLanguageStatement', $table, $table, $querySettings);
153 $expectedSql = '(' . $table . '.sys_language_uid IN (2,-1)' .
154 ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
155 'SELECT ' . $table . '.l10n_parent FROM ' . $table .
156 ' WHERE ' . $table . '.l10n_parent>0 AND ' .
157 $table . '.sys_language_uid=2 AND ' .
158 $table . '.deleted=0)))';
159 $this->assertSame($expectedSql, $sql);
160 }
161
162 /**
163 * @test
164 */
165 public function orderStatementGenerationWorks() {
166 $mockSource = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector::class, array('getNodeTypeName'), array(), '', FALSE);
167 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
168 $mockDataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class, array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
169 $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
170 $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
171 $sql = array();
172 $orderings = array('fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
173 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
174 $mockTypo3DbQueryParser->_set('dataMapper', $mockDataMapper);
175 $mockTypo3DbQueryParser->_callRef('parseOrderings', $orderings, $mockSource, $sql);
176 $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
177 $this->assertSame($expectedSql, $sql);
178 }
179
180 /**
181 * @test
182 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
183 */
184 public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
185 $mockSource = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector::class, array('getNodeTypeName'), array(), '', FALSE);
186 $mockSource->expects($this->never())->method('getNodeTypeName');
187 $mockDataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class, array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
188 $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
189 $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
190 $sql = array();
191 $orderings = array('fooProperty' => 'unsupported_order');
192 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
193 $mockTypo3DbQueryParser->_set('dataMapper', $mockDataMapper);
194 $mockTypo3DbQueryParser->_callRef('parseOrderings', $orderings, $mockSource, $sql);
195 }
196
197 /**
198 * @test
199 */
200 public function orderStatementGenerationWorksWithMultipleOrderings() {
201 $mockSource = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector::class, array('getNodeTypeName'), array(), '', FALSE);
202 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
203 $mockDataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class, array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
204 $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
205 $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
206 $sql = array();
207 $orderings = array(
208 'fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
209 'barProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
210 );
211 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
212 $mockTypo3DbQueryParser->_set('dataMapper', $mockDataMapper);
213 $mockTypo3DbQueryParser->_callRef('parseOrderings', $orderings, $mockSource, $sql);
214 $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
215 $this->assertSame($expectedSql, $sql);
216 }
217
218 public function providerForVisibilityConstraintStatement() {
219 return array(
220 'in be: include all' => array('BE', TRUE, array(), TRUE, ''),
221 'in be: ignore enable fields but do not include deleted' => array('BE', TRUE, array(), FALSE, 'tx_foo_table.deleted_column=0'),
222 'in be: respect enable fields but include deleted' => array('BE', FALSE, array(), TRUE, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789)'),
223 'in be: respect enable fields and do not include deleted' => array('BE', FALSE, array(), FALSE, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0'),
224 'in fe: include all' => array('FE', TRUE, array(), TRUE, ''),
225 'in fe: ignore enable fields but do not include deleted' => array('FE', TRUE, array(), FALSE, 'tx_foo_table.deleted_column=0'),
226 'in fe: ignore only starttime and do not include deleted' => array('FE', TRUE, array('starttime'), FALSE, 'tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0'),
227 'in fe: respect enable fields and do not include deleted' => array('FE', FALSE, array(), FALSE, 'tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789')
228 );
229 }
230
231 /**
232 * @test
233 * @dataProvider providerForVisibilityConstraintStatement
234 */
235 public function visibilityConstraintStatementIsGeneratedAccordingToTheQuerySettings($mode, $ignoreEnableFields, $enableFieldsToBeIgnored, $deletedValue, $expectedSql) {
236 $tableName = 'tx_foo_table';
237 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
238 'enablecolumns' => array(
239 'disabled' => 'disabled_column',
240 'starttime' => 'starttime_column'
241 ),
242 'delete' => 'deleted_column'
243 );
244 $GLOBALS['TSFE'] = new \stdClass();
245 $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
246 $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
247 $mockQuerySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class, array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
248 $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue($ignoreEnableFields));
249 $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue($enableFieldsToBeIgnored));
250 $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue($deletedValue));
251
252 /** @var $mockEnvironmentService \TYPO3\CMS\Extbase\Service\EnvironmentService | \PHPUnit_Framework_MockObject_MockObject */
253 $mockEnvironmentService = $this->getMock(\TYPO3\CMS\Extbase\Service\EnvironmentService::class, array('isEnvironmentInFrontendMode'));
254 $mockEnvironmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->will($this->returnValue($mode == 'FE'));
255
256 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
257 $mockTypo3DbQueryParser->_set('environmentService', $mockEnvironmentService);
258 $resultSql = $mockTypo3DbQueryParser->_callRef('getVisibilityConstraintStatement', $mockQuerySettings, $tableName, $tableName);
259 $this->assertSame($expectedSql, $resultSql);
260 unset($GLOBALS['TCA'][$tableName]);
261 }
262
263 public function providerForRespectEnableFields() {
264 return array(
265 'in be: respectEnableFields=false' => array('BE', FALSE, ''),
266 'in be: respectEnableFields=true' => array('BE', TRUE, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0'),
267 'in FE: respectEnableFields=false' => array('FE', FALSE, ''),
268 'in FE: respectEnableFields=true' => array('FE', TRUE, 'tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789')
269 );
270 }
271
272 /**
273 * @test
274 * @dataProvider providerForRespectEnableFields
275 */
276 public function respectEnableFieldsSettingGeneratesCorrectStatement($mode, $respectEnableFields, $expectedSql) {
277 $tableName = 'tx_foo_table';
278 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
279 'enablecolumns' => array(
280 'disabled' => 'disabled_column',
281 'starttime' => 'starttime_column'
282 ),
283 'delete' => 'deleted_column'
284 );
285 $GLOBALS['TSFE'] = new \stdClass();
286 $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
287 $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
288 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings $mockQuerySettings */
289 $mockQuerySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class, array('dummy'), array(), '', FALSE);
290 $mockQuerySettings->setIgnoreEnableFields(!$respectEnableFields);
291 $mockQuerySettings->setIncludeDeleted(!$respectEnableFields);
292
293 /** @var $mockEnvironmentService \TYPO3\CMS\Extbase\Service\EnvironmentService | \PHPUnit_Framework_MockObject_MockObject */
294 $mockEnvironmentService = $this->getMock(\TYPO3\CMS\Extbase\Service\EnvironmentService::class, array('isEnvironmentInFrontendMode'));
295 $mockEnvironmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->will($this->returnValue($mode == 'FE'));
296
297 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
298 $mockTypo3DbQueryParser->_set('environmentService', $mockEnvironmentService);
299 $actualSql = $mockTypo3DbQueryParser->_callRef('getVisibilityConstraintStatement', $mockQuerySettings, $tableName, $tableName);
300 $this->assertSame($expectedSql, $actualSql);
301 unset($GLOBALS['TCA'][$tableName]);
302 }
303
304 /**
305 * @test
306 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException
307 */
308 public function visibilityConstraintStatementGenerationThrowsExceptionIfTheQuerySettingsAreInconsistent() {
309 $tableName = 'tx_foo_table';
310 $GLOBALS['TCA'][$tableName]['ctrl'] = array(
311 'enablecolumns' => array(
312 'disabled' => 'disabled_column'
313 ),
314 'delete' => 'deleted_column'
315 );
316 $mockQuerySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class, array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
317 $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue(FALSE));
318 $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue(array()));
319 $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue(TRUE));
320
321 /** @var $mockEnvironmentService \TYPO3\CMS\Extbase\Service\EnvironmentService | \PHPUnit_Framework_MockObject_MockObject */
322 $mockEnvironmentService = $this->getMock(\TYPO3\CMS\Extbase\Service\EnvironmentService::class, array('isEnvironmentInFrontendMode'));
323 $mockEnvironmentService->expects($this->any())->method('isEnvironmentInFrontendMode')->will($this->returnValue(TRUE));
324
325 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
326 $mockTypo3DbQueryParser->_set('environmentService', $mockEnvironmentService);
327 $mockTypo3DbQueryParser->_callRef('getVisibilityConstraintStatement', $mockQuerySettings, $tableName, $tableName);
328 unset($GLOBALS['TCA'][$tableName]);
329 }
330
331 /**
332 * DataProvider for addPageIdStatement Tests
333 */
334 public function providerForAddPageIdStatementData() {
335 $table = $this->getUniqueId('tx_coretest_table');
336 return array(
337 'set Pid to zero if rootLevel = 1' => array(
338 '1',
339 $table,
340 $table . '.pid = 0'
341 ),
342 'set Pid to given Pids if rootLevel = 0' => array(
343 '0',
344 $table,
345 $table . '.pid IN (42, 27)'
346 ),
347 'add 0 to given Pids if rootLevel = -1' => array(
348 '-1',
349 $table,
350 $table . '.pid IN (42, 27, 0)'
351 ),
352 'set Pid to zero if rootLevel = -1 and no further pids given' => array(
353 '-1',
354 $table,
355 $table . '.pid = 0',
356 array()
357 ),
358 'set no statement for invalid configuration' => array(
359 '2',
360 $table,
361 ''
362 )
363 );
364 }
365
366 /**
367 * @test
368 * @dataProvider providerForAddPageIdStatementData
369 */
370 public function addPageIdStatementSetsPidToZeroIfTableDeclaresRootlevel($rootLevel, $table, $expectedSql, $storagePageIds = array(42,27)) {
371
372 $GLOBALS['TCA'][$table]['ctrl'] = array(
373 'rootLevel' => $rootLevel
374 );
375 $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', FALSE);
376 $mockFrontendVariableCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, array(), array(), '', FALSE);
377 $mockTypo3DbQueryParser->_set('tableColumnCache', $mockFrontendVariableCache);
378 $mockFrontendVariableCache->expects($this->once())->method('get')->will($this->returnValue(array('pid' => '42')));
379 $sql = $mockTypo3DbQueryParser->_callRef('getPageIdStatement', $table, $table, $storagePageIds);
380
381 $this->assertSame($expectedSql, $sql);
382 }
383
384 }