2 namespace TYPO3\CMS\Dbal\Tests\Unit\Database;
32 protected function setUp()
34 $GLOBALS[
'TYPO3_LOADED_EXT'] = array();
37 $subject = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\DatabaseConnection::class, array(
'getFieldInfoCache'), array(),
'',
false);
40 $mockCacheFrontend = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, array(), array(),
'',
false);
41 $subject->expects($this->any())->method(
'getFieldInfoCache')->will($this->returnValue($mockCacheFrontend));
44 $sqlParser = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\SqlParser::class, array(
'dummy'), array(),
'',
false);
45 $sqlParser->_set(
'databaseConnection',
$subject);
49 $installerSqlMock = $this->getMock(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class, array(
'getFieldDefinitions_fileContent'), array(),
'',
false);
50 $installerSqlMock->expects($this->any())->method(
'getFieldDefinitions_fileContent')->will($this->returnValue(array()));
51 $subject->_set(
'installerSql', $installerSqlMock);
57 $subject->lastHandlerKey =
'_DEFAULT';
74 throw new \RuntimeException(
'Can\'t write temporary ext_tables file.');
76 $this->testFilesToDelete[] = $ext_tables;
77 $GLOBALS[
'TYPO3_LOADED_EXT'] = array(
79 'ext_tables.sql' => $ext_tables
83 $this->subject->initialize();
89 public function tableWithMappingIsDetected()
91 $dbalConfiguration = array(
93 'cf_cache_hash' => array(),
98 $subject = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\DatabaseConnection::class, array(
'getFieldInfoCache'), array(),
'',
false);
100 $mockCacheFrontend = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, array(), array(),
'',
false);
101 $subject->expects($this->any())->method(
'getFieldInfoCache')->will($this->returnValue($mockCacheFrontend));
103 $sqlParser = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\SqlParser::class, array(
'dummy'), array(),
'',
false);
104 $sqlParser->_set(
'databaseConnection',
$subject);
107 $installerSqlMock = $this->getMock(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class, array(), array(),
'',
false);
108 $subject->_set(
'installerSql', $installerSqlMock);
109 $schemaMigrationResult = array(
110 'cf_cache_pages' => array(),
112 $installerSqlMock->expects($this->once())->method(
'getFieldDefinitions_fileContent')->will($this->returnValue($schemaMigrationResult));
114 $subject->conf = $dbalConfiguration;
116 $subject->lastHandlerKey =
'_DEFAULT';
118 $this->assertFalse(
$subject->_call(
'map_needMapping',
'cf_cache_pages'));
119 $cfCacheHashNeedsMapping =
$subject->_call(
'map_needMapping',
'cf_cache_hash');
120 $this->assertEquals(
'cf_cache_hash', $cfCacheHashNeedsMapping[0][
'table']);
129 $handlerMock = $this->getMock(
'\ADODB_mock', array(
'MetaTables'), array(),
'',
false);
130 $handlerMock->expects($this->any())->method(
'MetaTables')->will($this->returnValue(array(
'cf_cache_hash')));
131 $this->subject->handlerCfg[
'_DEFAULT'][
'type'] =
'adodb';
132 $this->subject->handlerInstance[
'_DEFAULT'] = $handlerMock;
134 $actual = $this->subject->admin_get_tables();
135 $expected = array(
'cf_cache_hash' => array(
'Name' =>
'cf_cache_hash'));
136 $this->assertSame($expected, $actual);
145 $result = $this->subject->SELECTquery(
'*',
'sys_refindex, tx_dam_file_tracking',
'sys_refindex.tablename = \'tx_dam_file_tracking\'' .
' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)');
146 $expected =
'SELECT * FROM sys_refindex, tx_dam_file_tracking WHERE sys_refindex.tablename = \'tx_dam_file_tracking\'';
147 $expected .=
' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)';
148 $this->assertEquals($expected, $this->
cleanSql($result));
158 CREATE TABLE tx_test_dbal (
159 foo double default \'0\',
160 foobar int default \'0\'
167 $result = $this->subject->INSERTquery(
'tx_test_dbal', $data);
168 $expected =
'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'99.12\', \'-120\' )';
169 $this->assertEquals($expected, $this->
cleanSql($result));
178 if (!is_int(9223372036854775806)) {
179 $this->markTestSkipped(
'Test skipped because running on 32 bit system.');
182 CREATE TABLE tx_test_dbal (
183 foo int default \'0\',
184 foobar bigint default \'0\'
188 'foo' => 9223372036854775807,
189 'foobar' => 9223372036854775807
191 $result = $this->subject->INSERTquery(
'tx_test_dbal', $data);
192 $expected =
'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'9223372036854775807\', \'9223372036854775807\' )';
193 $this->assertEquals($expected, $this->
cleanSql($result));
201 $fields = array(
'uid',
'pid',
'title',
'body');
203 array(
'1',
'2',
'Title #1',
'Content #1'),
204 array(
'3',
'4',
'Title #2',
'Content #2'),
205 array(
'5',
'6',
'Title #3',
'Content #3')
207 $result = $this->subject->INSERTmultipleRows(
'tt_content', $fields, $rows);
208 $expected =
'INSERT INTO tt_content (uid, pid, title, body) VALUES ';
209 $expected .=
'(\'1\', \'2\', \'Title #1\', \'Content #1\'), ';
210 $expected .=
'(\'3\', \'4\', \'Title #2\', \'Content #2\'), ';
211 $expected .=
'(\'5\', \'6\', \'Title #3\', \'Content #3\')';
212 $this->assertEquals($expected, $this->
cleanSql($result));
220 $result = $this->subject->SELECT_mm_query(
'*',
'sys_category',
'sys_category_record_mm',
'tt_content',
'AND sys_category.uid = 1',
'',
'sys_category.title DESC');
221 $expected =
'SELECT * FROM sys_category,sys_category_record_mm,tt_content WHERE sys_category.uid=sys_category_record_mm.uid_local AND tt_content.uid=sys_category_record_mm.uid_foreign AND sys_category.uid = 1 ORDER BY sys_category.title DESC';
222 $this->assertEquals($expected, $result);
231 $result = $this->subject->SELECTquery(
'*',
'pages',
'MIN(uid) IN (1,2,3,4)');
232 $expected =
'SELECT * FROM pages WHERE MIN(uid) IN (1,2,3,4)';
233 $this->assertEquals($expected, $this->
cleanSql($result));
242 $result = $this->subject->SELECTquery(
'*',
'pages',
'MAX(uid) IN (1,2,3,4)');
243 $expected =
'SELECT * FROM pages WHERE MAX(uid) IN (1,2,3,4)';
244 $this->assertEquals($expected, $this->
cleanSql($result));
253 $result = $this->
cleanSql($this->subject->SELECTquery(
'*',
'tt_content',
'bodytext LIKE BINARY \'test\''));
254 $expected =
'SELECT * FROM tt_content WHERE bodytext LIKE BINARY \'test\'';
255 $this->assertEquals($expected, $this->
cleanSql($result));
264 $result = $this->
cleanSql($this->subject->SELECTquery(
'*',
'tt_content',
'bodytext NOT LIKE BINARY \'test\''));
265 $expected =
'SELECT * FROM tt_content WHERE bodytext NOT LIKE BINARY \'test\'';
266 $this->assertEquals($expected, $this->
cleanSql($result));
278 $sql =
'SELECT * FROM cache WHERE tag = :tag1 OR tag = :tag10 OR tag = :tag100';
279 $parameterValues = array(
280 ':tag1' =>
'tag-one',
281 ':tag10' =>
'tag-two',
282 ':tag100' =>
'tag-three'
284 $className = self::buildAccessibleProxy(\TYPO3\CMS\Core\Database\PreparedStatement::class);
286 $precompiledQueryParts = array();
287 $statement =
new $className($sql,
'cache');
288 $statement->bindValues($parameterValues);
289 $parameters = $statement->_get(
'parameters');
290 $statement->_callRef(
'convertNamedPlaceholdersToQuestionMarks', $query, $parameters, $precompiledQueryParts);
291 $expectedQuery =
'SELECT * FROM cache WHERE tag = ? OR tag = ? OR tag = ?';
292 $expectedParameterValues = array(
294 'type' => \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_STR,
295 'value' =>
'tag-one',
298 'type' => \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_STR,
299 'value' =>
'tag-two',
302 'type' => \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_STR,
303 'value' =>
'tag-three',
306 $this->assertEquals($expectedQuery, $query);
307 $this->assertEquals($expectedParameterValues, $parameters);
321 $result = $this->subject->getEquivalentIndexDefinition($indexSQL);
322 $this->assertSame($expected, $result);
331 array(
'KEY (foo,bar(199))',
'KEY (foo,bar)'),
332 array(
'KEY (foo(199), bar)',
'KEY (foo, bar)'),
333 array(
'KEY (foo(199),bar(199))',
'KEY (foo,bar)'),