Changeset 4900
- Timestamp:
- 09/09/08 15:34:04 (10 months ago)
- Files:
-
- 1 modified
-
branches/1.0/tests/Ticket/1131TestCase.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/tests/Ticket/1131TestCase.php
r4780 r4900 38 38 $this->tables[] = 'Ticket_1131_User'; 39 39 $this->tables[] = 'Ticket_1131_Group'; 40 $this->tables[] = 'Ticket_1131_Role'; 40 41 parent::prepareTables(); 41 42 } … … 46 47 parent::prepareData(); 47 48 49 $role = new Ticket_1131_Role(); 50 $role->name = 'Role One'; 51 $role->save(); 52 $this->role_one = $role->id; 53 54 $role = new Ticket_1131_Role(); 55 $role->name = 'Role Two'; 56 $role->save(); 57 $this->role_two = $role->id; 58 48 59 $group = new Ticket_1131_Group(); 60 $group->role_id = $this->role_one; 49 61 $group->name = 'Core Dev'; 50 62 $group->save(); … … 52 64 $user = new Ticket_1131_User(); 53 65 $user->Group = $group; 66 $user->role_id = $this->role_two; 54 67 $user->name = 'jwage'; 55 68 $user->save(); 56 69 70 $role->free(); 57 71 $group->free(); 58 72 $user->free(); 59 73 } 60 74 61 public function test Ticket()75 public function testOriginalTicket() 62 76 { 63 77 $user = Doctrine_Query::create() … … 68 82 $this->assertFalse($user->get('group_id') instanceof Doctrine_Record); 69 83 } 84 85 public function testOriginalTicketWithJoins() 86 { 87 $user = Doctrine_Query::create() 88 ->from('Ticket_1131_User u') 89 ->leftJoin('u.Group g') 90 ->where('u.id = ?')->fetchOne(array(1)); 91 92 $this->assertEqual($user->Group->id, 1); 93 $this->assertFalse($user->get('group_id') instanceof Doctrine_Record); 94 } 95 96 public function testOverloading() 97 { 98 $orig = Doctrine_Manager::getInstance()->getAttribute('auto_accessor_override'); 99 Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', true); 100 101 $user = Doctrine_Query::create() 102 ->from('Ticket_1131_User u') 103 ->where('u.id = ?')->fetchOne(array(1)); 104 105 $this->assertEqual($user->group_id, 1); 106 $this->assertEqual($user->get('group_id'), 1); 107 $this->assertFalse($user->get('group_id') instanceof Doctrine_Record); 108 109 $this->assertEqual($user->role_id, 2); 110 $this->assertEqual($user->get('role_id'), 2); 111 $this->assertFalse($user->get('role_id') instanceof Doctrine_Record); 112 113 $this->assertEqual($user->Group->id, 1); 114 $this->assertEqual($user->get('Group')->get('id'), 1); 115 116 $this->assertEqual($user->Role->id, 2); 117 $this->assertEqual($user->get('Role')->get('id'), 2); 118 119 Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', $orig); 120 } 121 122 public function testOverloadingWithJoins() 123 { 124 $orig = Doctrine_Manager::getInstance()->getAttribute('auto_accessor_override'); 125 Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', true); 126 127 $user = Doctrine_Query::create() 128 ->from('Ticket_1131_UserWithOverloading u') 129 ->leftJoin('u.Group g') 130 ->leftJoin('u.Role r') 131 ->addWhere('u.id = ?')->fetchOne(array(1)); 132 133 $this->assertEqual($user->group_id, 1); 134 $this->assertEqual($user->get('group_id'), 1); 135 $this->assertFalse($user->get('group_id') instanceof Doctrine_Record); 136 137 $this->assertEqual($user->role_id, 1); 138 $this->assertEqual($user->get('role_id'), 1); 139 $this->assertFalse($user->get('role_id') instanceof Doctrine_Record); 140 141 $this->assertEqual($user->Group->id, 1); 142 $this->assertEqual($user->get('Group')->get('id'), 1); 143 144 $this->assertEqual($user->Role->id, 1); 145 $this->assertEqual($user->get('Role')->get('id'), 1); 146 147 Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', $orig); 148 } 70 149 } 71 150 … … 75 154 { 76 155 $this->hasColumn('group_id', 'integer', 20, array( 156 'notnull' => false, 'default' => null 157 )); 158 $this->hasColumn('role_id', 'integer', 20, array( 77 159 'notnull' => false, 'default' => null 78 160 )); … … 86 168 'foreign' => 'id' 87 169 )); 88 } 89 } 90 170 171 $this->hasOne('Ticket_1131_Role as Role', array( 172 'local' => 'role_id', 173 'foreign' => 'id')); 174 } 175 } 176 177 class Ticket_1131_UserWithOverloading extends Ticket_1131_User 178 { 179 public function getRole() 180 { 181 return $this->Group->Role; 182 } 183 184 public function getRoleId() 185 { 186 return $this->Group->role_id; 187 } 188 } 91 189 92 190 class Ticket_1131_Group extends Doctrine_Record … … 94 192 public function setTableDefinition() 95 193 { 194 $this->hasColumn('role_id', 'integer', 20, array( 195 'notnull' => false, 'default' => null 196 )); 96 197 $this->hasColumn('name', 'string', 255); 97 198 } … … 99 200 public function setUp() 100 201 { 202 $this->hasOne('Ticket_1131_Role as Role', array( 203 'local' => 'role_id', 204 'foreign' => 'id')); 205 101 206 $this->hasMany('Ticket_1131_User as Users', array( 102 207 'local' => 'id', … … 105 210 } 106 211 } 212 213 class Ticket_1131_Role extends Doctrine_Record 214 { 215 public function setTableDefinition() 216 { 217 $this->hasColumn('name', 'string', 255); 218 } 219 220 public function setUp() 221 { 222 $this->hasMany('Ticket_1131_User as Users', array( 223 'local' => 'id', 224 'foreign' => 'role_id' 225 )); 226 $this->hasMany('Ticket_1131_Group as Groups', array( 227 'local' => 'id', 228 'foreign' => 'role_id' 229 )); 230 } 231 }