[TASK] Tests: Refactor and activate dbal tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / Tests / Unit / Database / DatabaseConnectionPostgresqlTest.php
1 <?php
2 namespace TYPO3\CMS\Dbal\Tests\Unit\Database;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2014 Xavier Perseguers <xavier@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Test case
31 */
32 class DatabaseConnectionPostgresqlTest extends AbstractTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Dbal\Database\DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
36 */
37 protected $subject;
38
39 /**
40 * Prepare a DatabaseConnection subject ready to parse mssql queries
41 *
42 * @return void
43 */
44 public function setUp() {
45 $configuration = array(
46 'handlerCfg' => array(
47 '_DEFAULT' => array(
48 'type' => 'adodb',
49 'config' => array(
50 'driver' => 'postgres',
51 ),
52 ),
53 ),
54 'mapping' => array(
55 'tx_templavoila_tmplobj' => array(
56 'mapFieldNames' => array(
57 'datastructure' => 'ds',
58 ),
59 ),
60 'Members' => array(
61 'mapFieldNames' => array(
62 'pid' => '0',
63 'cruser_id' => '1',
64 'uid' => 'MemberID',
65 ),
66 ),
67 ),
68 );
69 $this->subject = $this->prepareSubject('postgres7', $configuration);
70 }
71
72 /**
73 * @test
74 */
75 public function runningADOdbDriverReturnsTrueWithPostgresForPostgres8DefaultDriverConfiguration() {
76 $this->assertTrue($this->subject->runningADOdbDriver('postgres'));
77 }
78
79 /**
80 * @test
81 * @see http://forge.typo3.org/issues/15492
82 */
83 public function limitIsProperlyRemapped() {
84 $result = $this->subject->SELECTquery('*', 'be_users', '1=1', '', '', '20');
85 $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 20';
86 $this->assertEquals($expected, $this->cleanSql($result));
87 }
88
89 /**
90 * @test
91 * @see http://forge.typo3.org/issues/15492
92 */
93 public function limitWithSkipIsProperlyRemapped() {
94 $result = $this->subject->SELECTquery('*', 'be_users', '1=1', '', '', '20,40');
95 $expected = 'SELECT * FROM "be_users" WHERE 1 = 1 LIMIT 40 OFFSET 20';
96 $this->assertEquals($expected, $this->cleanSql($result));
97 }
98
99 /**
100 * @test
101 * @see http://forge.typo3.org/issues/23087
102 */
103 public function findInSetIsProperlyRemapped() {
104 $result = $this->subject->SELECTquery('*', 'fe_users', 'FIND_IN_SET(10, usergroup)');
105 $expected = 'SELECT * FROM "fe_users" WHERE FIND_IN_SET(10, "usergroup") != 0';
106 $this->assertEquals($expected, $this->cleanSql($result));
107 }
108
109 /**
110 * @test
111 * @see http://forge.typo3.org/issues/21514
112 */
113 public function likeBinaryOperatorIsRemappedToLike() {
114 $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext LIKE BINARY \'test\'');
115 $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" LIKE \'test\'';
116 $this->assertEquals($expected, $this->cleanSql($result));
117 }
118
119 /**
120 * @test
121 * @see http://forge.typo3.org/issues/21514
122 */
123 public function notLikeBinaryOperatorIsRemappedToNotLike() {
124 $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext NOT LIKE BINARY \'test\'');
125 $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT LIKE \'test\'';
126 $this->assertEquals($expected, $this->cleanSql($result));
127 }
128
129 /**
130 * @test
131 * @see http://forge.typo3.org/issues/21514
132 */
133 public function likeOperatorIsRemappedToIlike() {
134 $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext LIKE \'test\'');
135 $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" ILIKE \'test\'';
136 $this->assertEquals($expected, $this->cleanSql($result));
137 }
138
139 /**
140 * @test
141 * @see http://forge.typo3.org/issues/21514
142 */
143 public function notLikeOperatorIsRemappedToNotIlike() {
144 $result = $this->subject->SELECTquery('*', 'tt_content', 'bodytext NOT LIKE \'test\'');
145 $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT ILIKE \'test\'';
146 $this->assertEquals($expected, $this->cleanSql($result));
147 }
148
149 /**
150 * @test
151 * @see http://forge.typo3.org/issues/32626
152 */
153 public function notEqualAnsiOperatorCanBeParsed() {
154 $result = $this->subject->SELECTquery('*', 'pages', 'pid<>3');
155 $expected = 'SELECT * FROM "pages" WHERE "pid" <> 3';
156 $this->assertEquals($expected, $this->cleanSql($result));
157 }
158
159 }