ConfigurableTestCase.php 9.43 KB
Newer Older
doctrine's avatar
doctrine committed
1
<?php
2
require_once("UnitTestCase.php");
doctrine's avatar
doctrine committed
3

4
class Doctrine_Configurable_TestCase extends Doctrine_UnitTestCase {
5 6
    public function prepareTables() { }
    public function prepareData() { }
7 8 9

    public function testGetIndexNameFormatAttribute() {
        // default index name format is %_idx
zYne's avatar
zYne committed
10
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT), '%s_idx');
11 12 13
    }
    public function testGetSequenceNameFormatAttribute() {
        // default sequence name format is %_seq
zYne's avatar
zYne committed
14
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT), '%s_seq');
15 16 17 18 19 20 21 22 23 24 25 26 27
    }
    public function testSetIndexNameFormatAttribute() {
        $this->manager->setAttribute(Doctrine::ATTR_IDXNAME_FORMAT, '%_index');

        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT), '%_index');
    }
    public function testSetSequenceNameFormatAttribute() {
        $this->manager->setAttribute(Doctrine::ATTR_SEQNAME_FORMAT, '%_sequence');

        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT), '%_sequence');
    }
    public function testExceptionIsThrownWhenSettingIndexNameFormatAttributeAtTableLevel() {
        try {
zYne's avatar
zYne committed
28
            $this->connection->getTable('Entity')->setAttribute(Doctrine::ATTR_IDXNAME_FORMAT, '%s_idx');
29 30 31 32 33 34 35
            $this->fail();
        } catch(Doctrine_Exception $e) {
            $this->pass();
        }
    }
    public function testExceptionIsThrownWhenSettingSequenceNameFormatAttributeAtTableLevel() {
        try {
zYne's avatar
zYne committed
36
            $this->connection->getTable('Entity')->setAttribute(Doctrine::ATTR_SEQNAME_FORMAT, '%s_seq');
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            $this->fail();
        } catch(Doctrine_Exception $e) {
            $this->pass();
        }
    }
    public function testSettingFieldCaseIsSuccesfulWithZero() {
        try {
            $this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, 0);
            $this->pass();
        } catch(Doctrine_Exception $e) {
            $this->fail();
        }
    }
    public function testSettingFieldCaseIsSuccesfulWithCaseConstants() {
        try {
            $this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, CASE_LOWER);
            $this->pass();
        } catch(Doctrine_Exception $e) {
            $this->fail();
        }
    }
    public function testSettingFieldCaseIsSuccesfulWithCaseConstants2() {
        try {
            $this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, CASE_UPPER);
            $this->pass();
        } catch(Doctrine_Exception $e) {
            $this->fail();
        }
    }
    public function testExceptionIsThrownWhenSettingFieldCaseToNotZeroOneOrTwo() {
        try {
            $this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, -1);
            $this->fail();
        } catch(Doctrine_Exception $e) {
            $this->pass();
        }
    }
    public function testExceptionIsThrownWhenSettingFieldCaseToNotZeroOneOrTwo2() {
        try {
            $this->connection->setAttribute(Doctrine::ATTR_FIELD_CASE, 5);
            $this->fail();
        } catch(Doctrine_Exception $e) {
            $this->pass();
        }
    }
    public function testDefaultQuoteIdentifierAttributeValueIsFalse() {
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER), false);
    }
    public function testQuoteIdentifierAttributeAcceptsBooleans() {
        $this->manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);

        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER), true);
zYne's avatar
zYne committed
89
                $this->manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, false);
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    }
    public function testDefaultSequenceColumnNameAttributeValueIsId() {
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQCOL_NAME), 'id');
    }
    public function testSequenceColumnNameAttributeAcceptsStrings() {
        $this->manager->setAttribute(Doctrine::ATTR_SEQCOL_NAME, 'sequence');

        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_SEQCOL_NAME), 'sequence');
    }
    public function testValidatorAttributeAcceptsBooleans() {
        $this->manager->setAttribute(Doctrine::ATTR_VLD, true);
        
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_VLD), true);
    }
    public function testAutoLengthValidationAttributeAcceptsBooleans() {
        $this->manager->setAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD, true);
        
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD), true);
    }
    public function testAutoTypeValidationAttributeAcceptsBooleans() {
        $this->manager->setAttribute(Doctrine::ATTR_AUTO_TYPE_VLD, true);
        
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD), true);
    }
    public function testDefaultPortabilityAttributeValueIsAll() {
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_PORTABILITY), Doctrine::PORTABILITY_ALL);
    }
    public function testPortabilityAttributeAcceptsPortabilityConstants() {
        $this->manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_RTRIM | Doctrine::PORTABILITY_FIX_CASE);

        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_PORTABILITY), 
                           Doctrine::PORTABILITY_RTRIM | Doctrine::PORTABILITY_FIX_CASE);
    }
    public function testDefaultListenerIsDoctrineEventListener() {
124
        $this->assertTrue($this->manager->getAttribute(Doctrine::ATTR_LISTENER) instanceof Doctrine_EventListener);                                                                     
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    }
    public function testListenerAttributeAcceptsEventListenerObjects() {
        $this->manager->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_Debugger());

        $this->assertTrue($this->manager->getAttribute(Doctrine::ATTR_LISTENER) instanceof Doctrine_EventListener_Debugger);
    }
    public function testCollectionKeyAttributeAcceptsValidColumnName() {
        try {
            $this->connection->getTable('User')->setAttribute(Doctrine::ATTR_COLL_KEY, 'name');
            
            $this->pass();
        } catch(Exception $e) {
            $this->fail();
        }
    }
    public function testSettingInvalidColumnNameToCollectionKeyAttributeThrowsException() {
        try {
            $this->connection->getTable('User')->setAttribute(Doctrine::ATTR_COLL_KEY, 'unknown');
            
            $this->fail();
        } catch(Exception $e) {
            $this->pass();
        }
    }
    public function testSettingCollectionKeyAttributeOnOtherThanTableLevelThrowsException() {
        try {
            $this->connection->setAttribute(Doctrine::ATTR_COLL_KEY, 'name');
            
            $this->fail();
        } catch(Exception $e) {
            $this->pass();
        }
    }
doctrine's avatar
doctrine committed
158
    public function testSetAttribute() {
zYne's avatar
zYne committed
159
        $table = $this->connection->getTable("User");
160
        /**
doctrine's avatar
doctrine committed
161 162
        $this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,100);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_TTL),100);
163

doctrine's avatar
doctrine committed
164 165 166 167 168
        $this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,1);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_SIZE),1);

        $this->manager->setAttribute(Doctrine::ATTR_CACHE_DIR,"%ROOT%".DIRECTORY_SEPARATOR."cache");
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_DIR),$this->manager->getRoot().DIRECTORY_SEPARATOR."cache");
169
        */
doctrine's avatar
doctrine committed
170 171 172 173 174 175 176 177 178 179
        $this->manager->setAttribute(Doctrine::ATTR_FETCHMODE,Doctrine::FETCH_LAZY);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_FETCHMODE),Doctrine::FETCH_LAZY);

        $this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE, 5);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_BATCH_SIZE),5);

        $this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_LOCKMODE), Doctrine::LOCK_PESSIMISTIC);

        // test invalid arguments
180
        /**
doctrine's avatar
doctrine committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        try {
            $this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }
        try {
            $this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }
        try {
            $this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }
196
        */
doctrine's avatar
doctrine committed
197
        try {
zYne's avatar
zYne committed
198
            $this->connection->beginTransaction();
doctrine's avatar
doctrine committed
199 200 201
            $this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
zYne's avatar
zYne committed
202
            $this->connection->commit();
doctrine's avatar
doctrine committed
203
        }
doctrine's avatar
doctrine committed
204

doctrine's avatar
doctrine committed
205
        try {
zYne's avatar
zYne committed
206 207
            $this->connection->beginTransaction();
            $this->connection->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
doctrine's avatar
doctrine committed
208 209
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
zYne's avatar
zYne committed
210
            $this->connection->commit();
doctrine's avatar
doctrine committed
211
        }
zYne's avatar
zYne committed
212

doctrine's avatar
doctrine committed
213 214 215 216 217
    }
    public function testGetAttributes() {
        $this->assertTrue(is_array($this->manager->getAttributes()));
    }
}