| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Concrete Table Inheritance mapping tests. |
|---|
| 5 | */ |
|---|
| 6 | class Doctrine_Inheritance_TablePerClass_TestCase extends Doctrine_UnitTestCase |
|---|
| 7 | { |
|---|
| 8 | public function prepareData() |
|---|
| 9 | { } |
|---|
| 10 | |
|---|
| 11 | public function setUp() |
|---|
| 12 | { |
|---|
| 13 | parent::setUp(); |
|---|
| 14 | $this->prepareTables(); |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | public function prepareTables() |
|---|
| 18 | { |
|---|
| 19 | $this->tables[] = 'CCTI_User'; |
|---|
| 20 | $this->tables[] = 'CCTI_Manager'; |
|---|
| 21 | $this->tables[] = 'CCTI_Customer'; |
|---|
| 22 | $this->tables[] = 'CCTI_SuperManager'; |
|---|
| 23 | parent::prepareTables(); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | public function testMetadataTableSetup() |
|---|
| 27 | { |
|---|
| 28 | $supMngrTable = $this->conn->getClassMetadata('CCTI_SuperManager'); |
|---|
| 29 | $usrTable = $this->conn->getClassMetadata('CCTI_User'); |
|---|
| 30 | $mngrTable = $this->conn->getClassMetadata('CCTI_Manager'); |
|---|
| 31 | $customerTable = $this->conn->getClassMetadata('CCTI_Customer'); |
|---|
| 32 | |
|---|
| 33 | $this->assertEqual(3, count($usrTable->getColumns())); |
|---|
| 34 | $this->assertEqual(4, count($mngrTable->getColumns())); |
|---|
| 35 | $this->assertEqual(4, count($customerTable->getColumns())); |
|---|
| 36 | $this->assertEqual(5, count($supMngrTable->getColumns())); |
|---|
| 37 | |
|---|
| 38 | $this->assertEqual('ccti_user', $usrTable->getTableName()); |
|---|
| 39 | $this->assertEqual('ccti_manager', $mngrTable->getTableName()); |
|---|
| 40 | $this->assertEqual('ccti_customer', $customerTable->getTableName()); |
|---|
| 41 | $this->assertEqual('ccti_supermanager', $supMngrTable->getTableName()); |
|---|
| 42 | |
|---|
| 43 | //var_dump($mngrTable->getColumns()); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public function testSave() |
|---|
| 47 | { |
|---|
| 48 | $manager = new CCTI_Manager(); |
|---|
| 49 | $manager->salary = 80000; |
|---|
| 50 | $manager->name = 'John Smith'; |
|---|
| 51 | try { |
|---|
| 52 | $manager->save(); |
|---|
| 53 | $this->assertEqual(1, $manager->id); |
|---|
| 54 | $this->assertEqual(80000, $manager->salary); |
|---|
| 55 | $this->assertEqual('John Smith', $manager->name); |
|---|
| 56 | } catch (Exception $e) { |
|---|
| 57 | $this->fail("Saving record in concrete table inheritance failed: " . $e->getMessage()); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public function testQuery() |
|---|
| 62 | { |
|---|
| 63 | //$manager = $this->conn->query("FROM CCTI_Manager")->getFirst(); |
|---|
| 64 | //var_dump($manager); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | class CCTI_User extends Doctrine_Entity |
|---|
| 70 | { |
|---|
| 71 | public static function initMetadata($class) |
|---|
| 72 | { |
|---|
| 73 | $class->setInheritanceType(Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS); |
|---|
| 74 | $class->setTableName('ccti_user'); |
|---|
| 75 | $class->setSubclasses(array('CCTI_Manager', 'CCTI_Customer', 'CCTI_SuperManager')); |
|---|
| 76 | $class->setColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true)); |
|---|
| 77 | $class->setColumn('ccti_foo as foo', 'integer', 4); |
|---|
| 78 | $class->setColumn('ccti_name as name', 'varchar', 50, array ()); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | class CCTI_Manager extends CCTI_User |
|---|
| 83 | { |
|---|
| 84 | public static function initMetadata($class) |
|---|
| 85 | { |
|---|
| 86 | $class->setTableName('ccti_manager'); |
|---|
| 87 | $class->setSubclasses(array('CCTI_SuperManager')); |
|---|
| 88 | $class->setColumn('ccti_salary as salary', 'varchar', 50, array()); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | class CCTI_Customer extends CCTI_User |
|---|
| 93 | { |
|---|
| 94 | public static function initMetadata($class) |
|---|
| 95 | { |
|---|
| 96 | $class->setTableName('ccti_customer'); |
|---|
| 97 | $class->setColumn('ccti_bonuspoints as bonuspoints', 'varchar', 50, array()); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | class CCTI_SuperManager extends CCTI_Manager |
|---|
| 102 | { |
|---|
| 103 | public static function initMetadata($class) |
|---|
| 104 | { |
|---|
| 105 | $class->setTableName('ccti_supermanager'); |
|---|
| 106 | $class->setColumn('ccti_gosutitle as gosutitle', 'varchar', 50, array()); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|