MssqlTestCase.php 7.9 KB
Newer Older
zYne's avatar
zYne committed
1
<?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 */

/**
 * Doctrine_DataDict_Mysql_TestCase
 *
 * @package     Doctrine
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @category    Object Relational Mapping
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 */
33 34 35 36
class Doctrine_DataDict_Mssql_TestCase extends Doctrine_UnitTestCase 
{
    public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() 
    {
37 38 39
        try {
            $this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type'));
            $this->fail();
zYne's avatar
zYne committed
40
        } catch(Doctrine_DataDict_Exception $e) {
41 42 43
            $this->pass();
        }
    }
44 45
    public function testGetPortableDeclarationSupportsNativeBitType() 
    {
46 47 48 49
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'bit'));
        
        $this->assertEqual($type, array(array('boolean'), null, null, null));
    }
50 51
    public function testGetPortableDeclarationSupportsNativeStringTypes() 
    {
52 53 54 55 56
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'text'));

        $this->assertEqual($type, array(array('string', 'clob'), null, null, null));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'char', 'length' => 1));
57

58 59 60 61 62 63
        $this->assertEqual($type, array(array('string', 'boolean'), 1, null, true));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar', 'length' => 1));
        
        $this->assertEqual($type, array(array('string', 'boolean'), 1, null, false));
    }
64 65
    public function testGetPortableDeclarationSupportsNativeBlobTypes() 
    {
66 67 68 69 70 71 72 73
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'image'));
        
        $this->assertEqual($type, array(array('blob'), null, null, null));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'varbinary'));

        $this->assertEqual($type, array(array('blob'), null, null, null));
    }
74 75
    public function testGetPortableDeclarationSupportsNativeIntegerTypes() 
    {
76 77 78 79 80 81 82 83
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'int'));
        
        $this->assertEqual($type, array(array('integer'), null, null, null));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'int', 'length' => 1));
        
        $this->assertEqual($type, array(array('integer', 'boolean'), 1, null, null));
    }
84 85
    public function testGetPortableDeclarationSupportsNativeTimestampType() 
    {
86 87 88 89
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime'));
        
        $this->assertEqual($type, array(array('timestamp'), null, null, null));
    }
90 91
    public function testGetPortableDeclarationSupportsNativeDecimalTypes() 
    {
92 93 94 95 96 97 98 99
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal'));

        $this->assertEqual($type, array(array('decimal'), null, null, null));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'money'));

        $this->assertEqual($type, array(array('decimal'), null, null, null));
    }
100 101
    public function testGetPortableDeclarationSupportsNativeFloatTypes() 
    {
102 103 104 105 106 107 108 109 110 111 112
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'float'));

        $this->assertEqual($type, array(array('float'), null, null, null));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'real'));

        $this->assertEqual($type, array(array('float'), null, null, null));

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'numeric'));

        $this->assertEqual($type, array(array('float'), null, null, null));
zYne's avatar
zYne committed
113
    }
114 115
    public function testGetNativeDefinitionSupportsIntegerType() 
    {
zYne's avatar
zYne committed
116 117
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false);

118
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
zYne's avatar
zYne committed
119 120 121 122 123 124 125
        
        $a['length'] = 4;

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');

        $a['length'] = 2;

126
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
zYne's avatar
zYne committed
127 128
    }

129 130
    public function testGetNativeDefinitionSupportsFloatType() 
    {
zYne's avatar
zYne committed
131 132
        $a = array('type' => 'float', 'length' => 20, 'fixed' => false);

133
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'FLOAT');
zYne's avatar
zYne committed
134
    }
135 136
    public function testGetNativeDefinitionSupportsBooleanType() 
    {
zYne's avatar
zYne committed
137 138
        $a = array('type' => 'boolean', 'fixed' => false);

139
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIT');
zYne's avatar
zYne committed
140
    }
141 142
    public function testGetNativeDefinitionSupportsDateType() 
    {
zYne's avatar
zYne committed
143 144
        $a = array('type' => 'date', 'fixed' => false);

145
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
zYne's avatar
zYne committed
146
    }
147 148
    public function testGetNativeDefinitionSupportsTimestampType() 
    {
zYne's avatar
zYne committed
149 150
        $a = array('type' => 'timestamp', 'fixed' => false);

151
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(19)');
zYne's avatar
zYne committed
152
    }
153 154
    public function testGetNativeDefinitionSupportsTimeType() 
    {
zYne's avatar
zYne committed
155 156
        $a = array('type' => 'time', 'fixed' => false);

157
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(8)');
zYne's avatar
zYne committed
158
    }
159 160
    public function testGetNativeDefinitionSupportsClobType() 
    {
zYne's avatar
zYne committed
161 162
        $a = array('type' => 'clob');

163
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
zYne's avatar
zYne committed
164
    }
165 166
    public function testGetNativeDefinitionSupportsBlobType() 
    {
zYne's avatar
zYne committed
167 168
        $a = array('type' => 'blob');

169
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'IMAGE');
zYne's avatar
zYne committed
170
    }
171 172
    public function testGetNativeDefinitionSupportsCharType() 
    {
zYne's avatar
zYne committed
173 174 175 176
        $a = array('type' => 'char', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
    }
177 178
    public function testGetNativeDefinitionSupportsVarcharType() 
    {
zYne's avatar
zYne committed
179 180 181 182
        $a = array('type' => 'varchar', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(10)');
    }
183 184
    public function testGetNativeDefinitionSupportsArrayType() 
    {
zYne's avatar
zYne committed
185 186 187 188
        $a = array('type' => 'array', 'length' => 40);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)');
    }
189 190
    public function testGetNativeDefinitionSupportsStringType() 
    {
zYne's avatar
zYne committed
191 192 193 194
        $a = array('type' => 'string');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
195 196
    public function testGetNativeDefinitionSupportsArrayType2() 
    {
zYne's avatar
zYne committed
197 198 199 200
        $a = array('type' => 'array');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
201 202
    public function testGetNativeDefinitionSupportsObjectType() 
    {
zYne's avatar
zYne committed
203 204 205 206 207
        $a = array('type' => 'object');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
}