TYPO3 CMS  TYPO3_7-6
DatabaseConnectionPostgresqlTest.php
Go to the documentation of this file.
1 <?php
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  if (!defined('ADODB_ASSOC_CASE')) {
35  define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE);
36  }
37  $configuration = [
38  'handlerCfg' => [
39  '_DEFAULT' => [
40  'type' => 'adodb',
41  'config' => [
42  'driver' => 'postgres',
43  ],
44  ],
45  ],
46  'mapping' => [
47  'tx_templavoila_tmplobj' => [
48  'mapFieldNames' => [
49  'datastructure' => 'ds',
50  ],
51  ],
52  'Members' => [
53  'mapFieldNames' => [
54  'pid' => '0',
55  'cruser_id' => '1',
56  'uid' => 'MemberID',
57  ],
58  ],
59  ],
60  ];
61  $this->subject = $this->prepareSubject('postgres7', $configuration);
62  }
63 
68  {
69  $this->assertTrue($this->subject->runningADOdbDriver('postgres'));
70  }
71 
76  public function limitIsProperlyRemapped()
77  {
78  $result = $this->subject->SELECTquery('*', 'be_users', '1=1', '', '', '20');
79  $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 20';
80  $this->assertEquals($expected, $this->cleanSql($result));
81  }
82 
88  {
89  $result = $this->subject->SELECTquery('*', 'be_users', '1=1', '', '', '20,40');
90  $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 40 OFFSET 20';
91  $this->assertEquals($expected, $this->cleanSql($result));
92  }
93 
98  public function findInSetIsProperlyRemapped()
99  {
100  $result = $this->subject->SELECTquery('*', 'fe_users', 'FIND_IN_SET(10, usergroup)');
101  $expected = 'SELECT * FROM "fe_users" WHERE FIND_IN_SET(10, CAST("usergroup" AS CHAR)) != 0';
102  $this->assertEquals($expected, $this->cleanSql($result));
103  }
104 
110  {
111  $result = $this->subject->SELECTquery('pages.uid', 'pages', 'FIND_IN_SET(10, pages.fe_group)');
112  $expected = 'SELECT "pages"."uid" FROM "pages" WHERE FIND_IN_SET(10, CAST("pages"."fe_group" AS CHAR)) != 0';
113  $this->assertEquals($expected, $this->cleanSql($result));
114  }
115 
121  {
122  $result = $this->subject->SELECTquery('uid', 'sys_category', 'FIND_IN_SET(\'0\',parent) OR CAST(parent AS CHAR) = \'\'');
123  $expected = 'SELECT "uid" FROM "sys_category" WHERE FIND_IN_SET(\'0\', CAST("parent" AS CHAR)) != 0 OR CAST("parent" AS CHAR) = \'\'';
124  $this->assertEquals($expected, $this->cleanSql($result));
125  }
126 
132  {
133  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext LIKE BINARY \'test\'');
134  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" LIKE \'test\'';
135  $this->assertEquals($expected, $this->cleanSql($result));
136  }
137 
143  {
144  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext NOT LIKE BINARY \'test\'');
145  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT LIKE \'test\'';
146  $this->assertEquals($expected, $this->cleanSql($result));
147  }
148 
154  {
155  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext LIKE \'test\'');
156  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" ILIKE \'test\'';
157  $this->assertEquals($expected, $this->cleanSql($result));
158  }
159 
165  {
166  $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext NOT LIKE \'test\'');
167  $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT ILIKE \'test\'';
168  $this->assertEquals($expected, $this->cleanSql($result));
169  }
170 
176  {
177  $result = $this->subject->SELECTquery('*', 'pages', 'pid<>3');
178  $expected = 'SELECT * FROM "pages" WHERE "pid" <> 3';
179  $this->assertEquals($expected, $this->cleanSql($result));
180  }
181 
187  {
188  $parseString = 'ALTER TABLE sys_collection ADD KEY parent (pid,deleted)';
189  $components = $this->subject->SQLparser->_callRef('parseALTERTABLE', $parseString);
190  $this->assertInternalType('array', $components);
191 
192  $result = $this->subject->SQLparser->compileSQL($components);
193  $expected = ['CREATE INDEX "dd81ee97_parent" ON "sys_collection" ("pid", "deleted")'];
194  $this->assertSame($expected, $this->cleanSql($result));
195  }
196 
202  {
203  $parseString = 'ALTER TABLE sys_file ADD uid INT(11) NOT NULL AUTO_INCREMENT';
204  $components = $this->subject->SQLparser->_callRef('parseALTERTABLE', $parseString);
205  $this->assertInternalType('array', $components);
206 
207  $result = $this->subject->SQLparser->compileSQL($components);
208  $expected = ['ALTER TABLE "sys_file" ADD COLUMN "uid" SERIAL'];
209  $this->assertSame($expected, $this->cleanSql($result));
210  }
211 
217  {
218  $parseString = 'ALTER TABLE sys_collection DROP KEY parent';
219  $components = $this->subject->SQLparser->_callRef('parseALTERTABLE', $parseString);
220  $this->assertInternalType('array', $components);
221 
222  $result = $this->subject->SQLparser->compileSQL($components);
223  $expected = ['DROP INDEX "dd81ee97_parent"'];
224  $this->assertSame($expected, $this->cleanSql($result));
225  }
226 
232  {
233  $result = $this->subject->SELECTquery('COUNT(title)', 'pages', '', 'title', 'title');
234  $expected = 'SELECT COUNT("title") FROM "pages" GROUP BY "title" ORDER BY "title"';
235  $this->assertEquals($expected, $this->cleanSql($result));
236  }
237 
243  {
244  $result = $this->subject->SELECTquery('COUNT(title), COUNT(pid)', 'pages', '', 'title, pid', 'title, pid');
245  $expected = 'SELECT COUNT("title"), COUNT("pid") FROM "pages" GROUP BY "title", "pid" ORDER BY "title", "pid"';
246  $this->assertEquals($expected, $this->cleanSql($result));
247  }
248 
254  {
255  $result = $this->subject->SELECTquery('COUNT(title)', 'pages', '', '', 'title');
256  $expected = 'SELECT COUNT("title") FROM "pages"';
257  $this->assertEquals($expected, $this->cleanSql($result));
258  }
259 
265  {
266  $result = $this->subject->SELECTquery('COUNT(title), COUNT(pid)', 'pages', '', '', 'title, pid');
267  $expected = 'SELECT COUNT("title"), COUNT("pid") FROM "pages"';
268  $this->assertEquals($expected, $this->cleanSql($result));
269  }
270 
276  {
277  $result = $this->subject->SELECTquery('COUNT(title), COUNT(pid)', 'pages', '', 'title', 'title, pid');
278  $expected = 'SELECT COUNT("title"), COUNT("pid") FROM "pages" GROUP BY "title" ORDER BY "title"';
279  $this->assertEquals($expected, $this->cleanSql($result));
280  }
281 
289  public function suggestEquivalentFieldDefinitions($fieldSQL, $expected)
290  {
291  $actual= $this->subject->getEquivalentFieldDefinition($fieldSQL);
292  $this->assertSame($expected, $actual);
293  }
294 
299  {
300  return [
301  ['int(11) NOT NULL default \'0\'', 'int(11) NOT NULL default \'0\''],
302  ['int(10) NOT NULL', 'int(11) NOT NULL'],
303  ['tinyint(3)', 'smallint(6)'],
304  ['bigint(20) NOT NULL', 'bigint(20) NOT NULL'],
305  ['tinytext NOT NULL', 'varchar(255) NOT NULL default \'\''],
306  ['tinytext', 'varchar(255) default NULL'],
307  ['mediumtext', 'longtext']
308  ];
309  }
310 }