Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Platforms / PostgreSqlPlatformTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Platforms;
4
5 use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
6 use Doctrine\DBAL\Types\Type;
7
8 class PostgreSqlPlatformTest extends AbstractPlatformTestCase
9 {
10     public function createPlatform()
11     {
12         return new PostgreSqlPlatform;
13     }
14
15     public function getGenerateTableSql()
16     {
17         return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
18     }
19
20     public function getGenerateTableWithMultiColumnUniqueIndexSql()
21     {
22         return array(
23             'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
24             'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)'
25         );
26     }
27
28     public function getGenerateAlterTableSql()
29     {
30         return array(
31             'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
32             'ALTER TABLE mytable DROP foo',
33             'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)',
34             "ALTER TABLE mytable ALTER bar SET  DEFAULT 'def'",
35             'ALTER TABLE mytable ALTER bar SET NOT NULL',
36             'ALTER TABLE mytable ALTER bloo TYPE BOOLEAN',
37             "ALTER TABLE mytable ALTER bloo SET  DEFAULT 'false'",
38             'ALTER TABLE mytable ALTER bloo SET NOT NULL',
39             'ALTER TABLE mytable RENAME TO userlist',
40         );
41     }
42
43     public function getGenerateIndexSql()
44     {
45         return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
46     }
47
48     public function getGenerateForeignKeySql()
49     {
50         return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE';
51     }
52
53     public function testGeneratesForeignKeySqlForNonStandardOptions()
54     {
55         $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
56                 array('foreign_id'), 'my_table', array('id'), 'my_fk', array('onDelete' => 'CASCADE')
57         );
58         $this->assertEquals(
59             "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE",
60             $this->_platform->getForeignKeyDeclarationSQL($foreignKey)
61         );
62     }
63
64     public function testGeneratesSqlSnippets()
65     {
66         $this->assertEquals('SIMILAR TO', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
67         $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
68         $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
69         $this->assertEquals('SUBSTR(column, 5)', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
70         $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct');
71     }
72
73     public function testGeneratesTransactionCommands()
74     {
75         $this->assertEquals(
76             'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
77             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
78         );
79         $this->assertEquals(
80             'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED',
81             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
82         );
83         $this->assertEquals(
84             'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ',
85             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
86         );
87         $this->assertEquals(
88             'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE',
89             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
90         );
91     }
92
93     public function testGeneratesDDLSnippets()
94     {
95         $this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
96         $this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
97         $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
98     }
99
100     public function testGenerateTableWithAutoincrement()
101     {
102         $table = new \Doctrine\DBAL\Schema\Table('autoinc_table');
103         $column = $table->addColumn('id', 'integer');
104         $column->setAutoincrement(true);
105
106         $this->assertEquals(array('CREATE TABLE autoinc_table (id SERIAL NOT NULL)'), $this->_platform->getCreateTableSQL($table));
107     }
108
109     public function testGeneratesTypeDeclarationForIntegers()
110     {
111         $this->assertEquals(
112             'INT',
113             $this->_platform->getIntegerTypeDeclarationSQL(array())
114         );
115         $this->assertEquals(
116             'SERIAL',
117             $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
118         ));
119         $this->assertEquals(
120             'SERIAL',
121             $this->_platform->getIntegerTypeDeclarationSQL(
122                 array('autoincrement' => true, 'primary' => true)
123         ));
124     }
125
126     public function testGeneratesTypeDeclarationForStrings()
127     {
128         $this->assertEquals(
129             'CHAR(10)',
130             $this->_platform->getVarcharTypeDeclarationSQL(
131                 array('length' => 10, 'fixed' => true))
132         );
133         $this->assertEquals(
134             'VARCHAR(50)',
135             $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
136             'Variable string declaration is not correct'
137         );
138         $this->assertEquals(
139             'VARCHAR(255)',
140             $this->_platform->getVarcharTypeDeclarationSQL(array()),
141             'Long string declaration is not correct'
142         );
143     }
144
145     public function getGenerateUniqueIndexSql()
146     {
147         return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
148     }
149
150     public function testGeneratesSequenceSqlCommands()
151     {
152         $sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
153         $this->assertEquals(
154             'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1',
155             $this->_platform->getCreateSequenceSQL($sequence)
156         );
157         $this->assertEquals(
158             'DROP SEQUENCE myseq',
159             $this->_platform->getDropSequenceSQL('myseq')
160         );
161         $this->assertEquals(
162             "SELECT NEXTVAL('myseq')",
163             $this->_platform->getSequenceNextValSQL('myseq')
164         );
165     }
166
167     public function testDoesNotPreferIdentityColumns()
168     {
169         $this->assertFalse($this->_platform->prefersIdentityColumns());
170     }
171
172     public function testPrefersSequences()
173     {
174         $this->assertTrue($this->_platform->prefersSequences());
175     }
176
177     public function testSupportsIdentityColumns()
178     {
179         $this->assertTrue($this->_platform->supportsIdentityColumns());
180     }
181
182     public function testSupportsSavePoints()
183     {
184         $this->assertTrue($this->_platform->supportsSavepoints());
185     }
186
187     public function testSupportsSequences()
188     {
189         $this->assertTrue($this->_platform->supportsSequences());
190     }
191
192     public function testModifyLimitQuery()
193     {
194         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
195         $this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
196     }
197
198     public function testModifyLimitQueryWithEmptyOffset()
199     {
200         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
201         $this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
202     }
203
204     public function getCreateTableColumnCommentsSQL()
205     {
206         return array(
207             "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))",
208             "COMMENT ON COLUMN test.id IS 'This is a comment'",
209         );
210     }
211
212     public function getAlterTableColumnCommentsSQL()
213     {
214         return array(
215             "ALTER TABLE mytable ADD quota INT NOT NULL",
216             "COMMENT ON COLUMN mytable.quota IS 'A comment'",
217             "COMMENT ON COLUMN mytable.baz IS 'B comment'",
218         );
219     }
220
221     public function getCreateTableColumnTypeCommentsSQL()
222     {
223         return array(
224             "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))",
225             "COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
226         );
227     }
228 }