OraclePlatformTest.php 6.39 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

namespace Doctrine\Tests\DBAL\Platforms;

use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Types\Type;

require_once __DIR__ . '/../../TestInit.php';
 
10
class OraclePlatformTest extends AbstractPlatformTestCase
11
{
12
    public function createPlatform()
13
    {
14
        return new OraclePlatform;
15 16
    }

17
    public function getGenerateTableSql()
18
    {
19
        return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))';
20 21
    }

22 23 24 25
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
    {
        return array(
            'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL, bar VARCHAR2(255) DEFAULT NULL)',
26
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
27 28 29
        );
    }

30
    public function getGenerateAlterTableSql()
31
    {
32
        return array(
33
            'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)',
34 35 36
            "ALTER TABLE mytable MODIFY (baz  VARCHAR2(255) DEFAULT 'def' NOT NULL)",
            "ALTER TABLE mytable DROP COLUMN foo",
            "ALTER TABLE mytable RENAME TO userlist",
37 38 39 40
        );
    }

    /**
41
     * @expectedException Doctrine\DBAL\DBALException
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
     */
    public function testRLike()
    {
        $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
    }

    public function testGeneratesSqlSnippets()
    {
        $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
        $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
    }

    public function testGeneratesTransactionsCommands()
    {
        $this->assertEquals(
            'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
58
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
59 60 61
        );
        $this->assertEquals(
            'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
62
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
63 64 65
        );
        $this->assertEquals(
            'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
66
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
67 68 69
        );
        $this->assertEquals(
            'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
70
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
71 72 73 74
        );
    }

    /**
75
     * @expectedException Doctrine\DBAL\DBALException
76 77 78
     */
    public function testShowDatabasesThrowsException()
    {
79
        $this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
80 81 82
    }

    /**
83
     * @expectedException Doctrine\DBAL\DBALException
84 85 86
     */
    public function testCreateDatabaseThrowsException()
    {
87
        $this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
88 89 90 91
    }

    public function testDropDatabaseThrowsException()
    {
92
        $this->assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSQL('foobar'));
93 94 95 96
    }

    public function testDropTable()
    {
97
        $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));        
98 99 100 101 102 103
    }

    public function testGeneratesTypeDeclarationForIntegers()
    {
        $this->assertEquals(
            'NUMBER(10)',
104
            $this->_platform->getIntegerTypeDeclarationSQL(array())
105 106 107
        );
        $this->assertEquals(
            'NUMBER(10)',
108
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
109 110 111
        ));
        $this->assertEquals(
            'NUMBER(10)',
112
            $this->_platform->getIntegerTypeDeclarationSQL(
113 114 115 116 117 118 119 120
                array('autoincrement' => true, 'primary' => true)
        ));
    }

    public function testGeneratesTypeDeclarationsForStrings()
    {
        $this->assertEquals(
            'CHAR(10)',
121
            $this->_platform->getVarcharTypeDeclarationSQL(
122 123 124 125
                array('length' => 10, 'fixed' => true)
        ));
        $this->assertEquals(
            'VARCHAR2(50)',
126
            $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
127 128 129
            'Variable string declaration is not correct'
        );
        $this->assertEquals(
130
            'VARCHAR2(255)',
131
            $this->_platform->getVarcharTypeDeclarationSQL(array()),
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
            'Long string declaration is not correct'
        );
    }

    public function testPrefersIdentityColumns()
    {
        $this->assertFalse($this->_platform->prefersIdentityColumns());
    }

    public function testSupportsIdentityColumns()
    {
        $this->assertFalse($this->_platform->supportsIdentityColumns());
    }

    public function testSupportsSavePoints()
    {
        $this->assertTrue($this->_platform->supportsSavepoints());   
    }
150
    
151
    public function getGenerateIndexSql()
152
    {
153
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
154 155
    }

156
    public function getGenerateUniqueIndexSql()
157
    {
158
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
159 160
    }

161
    public function getGenerateForeignKeySql()
162
    {
163
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)';
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    }

    public function testModifyLimitQuery()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
        $this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
    }

    public function testModifyLimitQueryWithEmptyOffset()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
        $this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
    }

    public function testModifyLimitQueryWithAscOrderBy()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
        $this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10', $sql);
    }

    public function testModifyLimitQueryWithDescOrderBy()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
        $this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql);
    }
}