TYPO3  7.6
DatabaseConnectionPostgresqlTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Dbal\Tests\Unit\Database;
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 
21 {
25  protected $subject;
26 
32  protected function setUp()
33  {
34  $configuration = array(
35  'handlerCfg' => array(
36  '_DEFAULT' => array(
37  'type' => 'adodb',
38  'config' => array(
39  'driver' => 'postgres',
40  ),
41  ),
42  ),
43  'mapping' => array(
44  'tx_templavoila_tmplobj' => array(
45  'mapFieldNames' => array(
46  'datastructure' => 'ds',
47  ),
48  ),
49  'Members' => array(
50  'mapFieldNames' => array(
51  'pid' => '0',
52  'cruser_id' => '1',
53  'uid' => 'MemberID',
54  ),
55  ),
56  ),
57  );
58  $this->subject = $this->prepareSubject('postgres7', $configuration);
59  }
60 
65  {
66  $this->assertTrue($this->subject->runningADOdbDriver('postgres'));
67  }
68 
73  public function limitIsProperlyRemapped()
74  {
75  $result = $this->subject->SELECTquery('*', 'be_users', '1=1', '', '', '20');
76  $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 20';
77  $this->assertEquals($expected, $this->cleanSql($result));
78  }
79 
85  {
86  $result = $this->subject->SELECTquery('*', 'be_users', '1=1', '', '', '20,40');
87  $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 40 OFFSET 20';
88  $this->assertEquals($expected, $this->cleanSql($result));
89  }
90 
95  public function findInSetIsProperlyRemapped()
96  {
97  $result = $this->subject->SELECTquery('*', 'fe_users', 'FIND_IN_SET(10, usergroup)');
98  $expected = 'SELECT * FROM "fe_users" WHERE FIND_IN_SET(10, CAST("usergroup" AS CHAR)) != 0';
99  $this->assertEquals($expected, $this->cleanSql($result));
100  }
101 
107  {
108  $result = $this->subject->SELECTquery('pages.uid', 'pages', 'FIND_IN_SET(10, pages.fe_group)');
109  $expected = 'SELECT "pages"."uid" FROM "pages" WHERE FIND_IN_SET(10, CAST("pages"."fe_group" AS CHAR)) != 0';
110  $this->assertEquals($expected, $this->cleanSql($result));
111  }
112 
118  {
119  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext LIKE BINARY \'test\'');
120  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" LIKE \'test\'';
121  $this->assertEquals($expected, $this->cleanSql($result));
122  }
123 
129  {
130  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext NOT LIKE BINARY \'test\'');
131  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT LIKE \'test\'';
132  $this->assertEquals($expected, $this->cleanSql($result));
133  }
134 
140  {
141  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext LIKE \'test\'');
142  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" ILIKE \'test\'';
143  $this->assertEquals($expected, $this->cleanSql($result));
144  }
145 
151  {
152  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext NOT LIKE \'test\'');
153  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT ILIKE \'test\'';
154  $this->assertEquals($expected, $this->cleanSql($result));
155  }
156 
162  {
163  $result = $this->subject->SELECTquery('*', 'pages', 'pid<>3');
164  $expected = 'SELECT * FROM "pages" WHERE "pid" <> 3';
165  $this->assertEquals($expected, $this->cleanSql($result));
166  }
167 
173  {
174  $parseString = 'ALTER TABLE sys_collection ADD KEY parent (pid,deleted)';
175  $components = $this->subject->SQLparser->_callRef('parseALTERTABLE', $parseString);
176  $this->assertInternalType('array', $components);
177 
178  $result = $this->subject->SQLparser->compileSQL($components);
179  $expected = array('CREATE INDEX "dd81ee97_parent" ON "sys_collection" ("pid", "deleted")');
180  $this->assertSame($expected, $this->cleanSql($result));
181  }
182 
188  {
189  $parseString = 'ALTER TABLE sys_file ADD uid INT(11) NOT NULL AUTO_INCREMENT';
190  $components = $this->subject->SQLparser->_callRef('parseALTERTABLE', $parseString);
191  $this->assertInternalType('array', $components);
192 
193  $result = $this->subject->SQLparser->compileSQL($components);
194  $expected = array('ALTER TABLE "sys_file" ADD COLUMN "uid" SERIAL');
195  $this->assertSame($expected, $this->cleanSql($result));
196  }
197 
203  {
204  $parseString = 'ALTER TABLE sys_collection DROP KEY parent';
205  $components = $this->subject->SQLparser->_callRef('parseALTERTABLE', $parseString);
206  $this->assertInternalType('array', $components);
207 
208  $result = $this->subject->SQLparser->compileSQL($components);
209  $expected = array('DROP INDEX "dd81ee97_parent"');
210  $this->assertSame($expected, $this->cleanSql($result));
211  }
212 
218  {
219  $result = $this->subject->SELECTquery('COUNT(title)', 'pages', '', 'title', 'title');
220  $expected = 'SELECT COUNT("title") FROM "pages" GROUP BY "title" ORDER BY "title"';
221  $this->assertEquals($expected, $this->cleanSql($result));
222  }
223 
229  {
230  $result = $this->subject->SELECTquery('COUNT(title), COUNT(pid)', 'pages', '', 'title, pid', 'title, pid');
231  $expected = 'SELECT COUNT("title"), COUNT("pid") FROM "pages" GROUP BY "title", "pid" ORDER BY "title", "pid"';
232  $this->assertEquals($expected, $this->cleanSql($result));
233  }
234 
240  {
241  $result = $this->subject->SELECTquery('COUNT(title)', 'pages', '', '', 'title');
242  $expected = 'SELECT COUNT("title") FROM "pages"';
243  $this->assertEquals($expected, $this->cleanSql($result));
244  }
245 
251  {
252  $result = $this->subject->SELECTquery('COUNT(title), COUNT(pid)', 'pages', '', '', 'title, pid');
253  $expected = 'SELECT COUNT("title"), COUNT("pid") FROM "pages"';
254  $this->assertEquals($expected, $this->cleanSql($result));
255  }
256 
262  {
263  $result = $this->subject->SELECTquery('COUNT(title), COUNT(pid)', 'pages', '', 'title', 'title, pid');
264  $expected = 'SELECT COUNT("title"), COUNT("pid") FROM "pages" GROUP BY "title" ORDER BY "title"';
265  $this->assertEquals($expected, $this->cleanSql($result));
266  }
267 
275  public function suggestEquivalentFieldDefinitions($fieldSQL, $expected)
276  {
277  $actual= $this->subject->getEquivalentFieldDefinition($fieldSQL);
278  $this->assertSame($expected, $actual);
279  }
280 
285  {
286  return array(
287  array('int(11) NOT NULL default \'0\'', 'int(11) NOT NULL default \'0\''),
288  array('int(10) NOT NULL', 'int(11) NOT NULL'),
289  array('tinyint(3)', 'smallint(6)'),
290  array('bigint(20) NOT NULL', 'bigint(20) NOT NULL'),
291  array('tinytext NOT NULL', 'varchar(255) NOT NULL default \'\''),
292  array('tinytext', 'varchar(255) default NULL'),
293  array('mediumtext', 'longtext')
294  );
295  }
296 }