TableTestCase.php 3.99 KB
Newer Older
doctrine's avatar
doctrine committed
1
<?php
2
require_once("UnitTestCase.php");
doctrine's avatar
doctrine committed
3
class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
doctrine's avatar
doctrine committed
4 5 6
    public function testBind() {
        $table = $this->session->getTable("User");
    }
doctrine's avatar
doctrine committed
7

8 9 10
    public function testGetIdentifier() {
        $table = $this->session->getTable("User");
    }
doctrine's avatar
doctrine committed
11 12 13 14
    public function testGetForeignKey() {
        $fk = $this->objTable->getForeignKey("Group");
        $this->assertTrue($fk instanceof Doctrine_Association);
        $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
15
        $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE);
doctrine's avatar
doctrine committed
16 17 18 19 20 21
        $this->assertTrue($fk->getLocal() == "user_id");
        $this->assertTrue($fk->getForeign() == "group_id");

        $fk = $this->objTable->getForeignKey("Email");
        $this->assertTrue($fk instanceof Doctrine_LocalKey);
        $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
22
        $this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE);
doctrine's avatar
doctrine committed
23
        $this->assertTrue($fk->getLocal() == "email_id");
24
        $this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier());
doctrine's avatar
doctrine committed
25 26 27 28 29


        $fk = $this->objTable->getForeignKey("Phonenumber");
        $this->assertTrue($fk instanceof Doctrine_ForeignKey);
        $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
30 31
        $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE);
        $this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());
doctrine's avatar
doctrine committed
32
        $this->assertTrue($fk->getForeign() == "entity_id");
33
        
doctrine's avatar
doctrine committed
34

doctrine's avatar
doctrine committed
35 36 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
    }
    public function testGetComponentName() {
        $this->assertTrue($this->objTable->getComponentName() == "User");
    } 
    public function testGetTableName() {
        $this->assertTrue($this->objTable->getTableName() == "entity");
    } 
    public function testGetSession() {
        $this->assertTrue($this->objTable->getSession() instanceof Doctrine_Session);
    }
    public function testGetData() {
        $this->assertTrue($this->objTable->getData() == array());
    }
    public function testSetSequenceName() {
        $this->objTable->setSequenceName("test-seq");
        $this->assertEqual($this->objTable->getSequenceName(),"test-seq");
        $this->objTable->setSequenceName(null);
    }
    public function testCreate() {
        $record = $this->objTable->create();
        $this->assertTrue($record instanceof Doctrine_Record);
        $this->assertTrue($record->getState() == Doctrine_Record::STATE_TCLEAN);
    }
    public function testFind() {
        $record = $this->objTable->find(4);
        $this->assertTrue($record instanceof Doctrine_Record);
        
        try {
            $record = $this->objTable->find(123);
        } catch(Exception $e) {
            $this->assertTrue($e instanceOf Doctrine_Find_Exception);
        }
    }
    public function testFindAll() {
        $users = $this->objTable->findAll();
        $this->assertEqual($users->count(), 8);
71
        $this->assertTrue($users instanceof Doctrine_Collection);
doctrine's avatar
doctrine committed
72 73 74 75
    }
    public function testFindBySql() {
        $users = $this->objTable->findBySql("name LIKE '%Arnold%'");
        $this->assertEqual($users->count(), 1);
76
        $this->assertTrue($users instanceof Doctrine_Collection);
doctrine's avatar
doctrine committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    }
    public function testGetProxy() {
        $user = $this->objTable->getProxy(4);
        $this->assertTrue($user instanceof Doctrine_Record);

        try {
            $record = $this->objTable->find(123);
        } catch(Exception $e) {
            $this->assertTrue($e instanceOf Doctrine_Find_Exception);
        }
    }
    public function testGetColumns() {
        $columns = $this->objTable->getColumns();
        $this->assertTrue(is_array($columns));

    }
    public function testIsNewEntry() {
        $this->assertFalse($this->objTable->isNewEntry());
    }
    public function testApplyInheritance() {
97
        $this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 AND type = ?");
doctrine's avatar
doctrine committed
98 99 100
    }
}
?>