Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Platforms / OraclePlatformTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Platforms;
4
5 use Doctrine\DBAL\Platforms\OraclePlatform;
6 use Doctrine\DBAL\Types\Type;
7
8 require_once __DIR__ . '/../../TestInit.php';
9
10 class OraclePlatformTest extends AbstractPlatformTestCase
11 {
12     static public function dataValidIdentifiers()
13     {
14         return array(
15             array('a'),
16             array('foo'),
17             array('Foo'),
18             array('Foo123'),
19             array('Foo#bar_baz$'),
20             array('"a"'),
21             array('"1"'),
22             array('"foo_bar"'),
23             array('"@$%&!"'),
24         );
25     }
26
27     /**
28      * @dataProvider dataValidIdentifiers
29      */
30     public function testValidIdentifiers($identifier)
31     {
32         $platform = $this->createPlatform();
33         $platform->assertValidIdentifier($identifier);
34     }
35
36     static public function dataInvalidIdentifiers()
37     {
38         return array(
39             array('1'),
40             array('abc&'),
41             array('abc-def'),
42             array('"'),
43             array('"foo"bar"'),
44         );
45     }
46
47     /**
48      * @dataProvider dataInvalidIdentifiers
49      */
50     public function testInvalidIdentifiers($identifier)
51     {
52         $this->setExpectedException('Doctrine\DBAL\DBALException');
53         $platform = $this->createPlatform();
54         $platform->assertValidIdentifier($identifier);
55     }
56
57     public function createPlatform()
58     {
59         return new OraclePlatform;
60     }
61
62     public function getGenerateTableSql()
63     {
64         return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))';
65     }
66
67     public function getGenerateTableWithMultiColumnUniqueIndexSql()
68     {
69         return array(
70             'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL, bar VARCHAR2(255) DEFAULT NULL)',
71             'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
72         );
73     }
74
75     public function getGenerateAlterTableSql()
76     {
77         return array(
78             'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)',
79             "ALTER TABLE mytable MODIFY (baz  VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo  NUMBER(1) DEFAULT '0' NOT NULL)",
80             "ALTER TABLE mytable DROP (foo)",
81             "ALTER TABLE mytable RENAME TO userlist",
82         );
83     }
84
85     /**
86      * @expectedException Doctrine\DBAL\DBALException
87      */
88     public function testRLike()
89     {
90         $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
91     }
92
93     public function testGeneratesSqlSnippets()
94     {
95         $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
96         $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
97     }
98
99     public function testGeneratesTransactionsCommands()
100     {
101         $this->assertEquals(
102             'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
103             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
104         );
105         $this->assertEquals(
106             'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
107             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
108         );
109         $this->assertEquals(
110             'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
111             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
112         );
113         $this->assertEquals(
114             'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
115             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
116         );
117     }
118
119     /**
120      * @expectedException Doctrine\DBAL\DBALException
121      */
122     public function testShowDatabasesThrowsException()
123     {
124         $this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
125     }
126
127     /**
128      * @expectedException Doctrine\DBAL\DBALException
129      */
130     public function testCreateDatabaseThrowsException()
131     {
132         $this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
133     }
134
135     public function testDropDatabaseThrowsException()
136     {
137         $this->assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSQL('foobar'));
138     }
139
140     public function testDropTable()
141     {
142         $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
143     }
144
145     public function testGeneratesTypeDeclarationForIntegers()
146     {
147         $this->assertEquals(
148             'NUMBER(10)',
149             $this->_platform->getIntegerTypeDeclarationSQL(array())
150         );
151         $this->assertEquals(
152             'NUMBER(10)',
153             $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
154         ));
155         $this->assertEquals(
156             'NUMBER(10)',
157             $this->_platform->getIntegerTypeDeclarationSQL(
158                 array('autoincrement' => true, 'primary' => true)
159         ));
160     }
161
162     public function testGeneratesTypeDeclarationsForStrings()
163     {
164         $this->assertEquals(
165             'CHAR(10)',
166             $this->_platform->getVarcharTypeDeclarationSQL(
167                 array('length' => 10, 'fixed' => true)
168         ));
169         $this->assertEquals(
170             'VARCHAR2(50)',
171             $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
172             'Variable string declaration is not correct'
173         );
174         $this->assertEquals(
175             'VARCHAR2(255)',
176             $this->_platform->getVarcharTypeDeclarationSQL(array()),
177             'Long string declaration is not correct'
178         );
179     }
180
181     public function testPrefersIdentityColumns()
182     {
183         $this->assertFalse($this->_platform->prefersIdentityColumns());
184     }
185
186     public function testSupportsIdentityColumns()
187     {
188         $this->assertFalse($this->_platform->supportsIdentityColumns());
189     }
190
191     public function testSupportsSavePoints()
192     {
193         $this->assertTrue($this->_platform->supportsSavepoints());
194     }
195
196     public function getGenerateIndexSql()
197     {
198         return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
199     }
200
201     public function getGenerateUniqueIndexSql()
202     {
203         return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
204     }
205
206     public function getGenerateForeignKeySql()
207     {
208         return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
209     }
210
211     public function testModifyLimitQuery()
212     {
213         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
214         $this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
215     }
216
217     public function testModifyLimitQueryWithEmptyOffset()
218     {
219         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
220         $this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
221     }
222
223     public function testModifyLimitQueryWithAscOrderBy()
224     {
225         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
226         $this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10', $sql);
227     }
228
229     public function testModifyLimitQueryWithDescOrderBy()
230     {
231         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
232         $this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql);
233     }
234
235     public function getCreateTableColumnCommentsSQL()
236     {
237         return array(
238             "CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))",
239             "COMMENT ON COLUMN test.id IS 'This is a comment'",
240         );
241     }
242
243     public function getCreateTableColumnTypeCommentsSQL()
244     {
245         return array(
246             "CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))",
247             "COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
248         );
249     }
250
251     public function getAlterTableColumnCommentsSQL()
252     {
253         return array(
254             "ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)",
255             "ALTER TABLE mytable MODIFY (baz  VARCHAR2(255) NOT NULL)",
256             "COMMENT ON COLUMN mytable.quota IS 'A comment'",
257             "COMMENT ON COLUMN mytable.baz IS 'B comment'",
258         );
259     }
260
261     public function getBitAndComparisonExpressionSql($value1, $value2)
262     {
263         return 'BITAND('.$value1 . ', ' . $value2 . ')';
264     }
265
266     public function getBitOrComparisonExpressionSql($value1, $value2)
267     {
268         return '(' . $value1 . '-' .
269                 $this->getBitAndComparisonExpressionSql($value1, $value2)
270                 . '+' . $value2 . ')';
271     }
272 }