Author: jasoneisen
Date: 2008-09-09 16:34:04 +0100 (Tue, 09 Sep 2008)
New Revision: 4900

Modified:
   branches/1.0/tests/Ticket/1131TestCase.php
Log:
Adding coverage for #1131


Modified: branches/1.0/tests/Ticket/1131TestCase.php
===================================================================
--- branches/1.0/tests/Ticket/1131TestCase.php  2008-09-08 23:33:52 UTC (rev 
4899)
+++ branches/1.0/tests/Ticket/1131TestCase.php  2008-09-09 15:34:04 UTC (rev 
4900)
@@ -37,6 +37,7 @@
         //$this->tables = array();
         $this->tables[] = 'Ticket_1131_User';
         $this->tables[] = 'Ticket_1131_Group';
+        $this->tables[] = 'Ticket_1131_Role';
         parent::prepareTables();
     }
     
@@ -45,20 +46,33 @@
     {
         parent::prepareData();
         
+        $role = new Ticket_1131_Role();
+        $role->name = 'Role One';
+        $role->save();
+        $this->role_one = $role->id;
+        
+        $role = new Ticket_1131_Role();
+        $role->name = 'Role Two';
+        $role->save();
+        $this->role_two = $role->id;
+        
         $group = new Ticket_1131_Group();
+        $group->role_id = $this->role_one;
         $group->name = 'Core Dev';
         $group->save();
 
         $user = new Ticket_1131_User();
         $user->Group = $group;
+        $user->role_id = $this->role_two;
         $user->name = 'jwage';
         $user->save();
         
+        $role->free();
         $group->free();
         $user->free();
     }
 
-    public function testTicket()
+    public function testOriginalTicket()
     {
         $user = Doctrine_Query::create()
             ->from('Ticket_1131_User u')
@@ -67,6 +81,71 @@
         $this->assertEqual($user->Group->id, 1);
         $this->assertFalse($user->get('group_id') instanceof Doctrine_Record);
     }
+    
+    public function testOriginalTicketWithJoins()
+    {
+        $user = Doctrine_Query::create()
+            ->from('Ticket_1131_User u')
+            ->leftJoin('u.Group g')
+            ->where('u.id = ?')->fetchOne(array(1));
+
+        $this->assertEqual($user->Group->id, 1);
+        $this->assertFalse($user->get('group_id') instanceof Doctrine_Record);
+    }
+    
+    public function testOverloading()
+    {
+        $orig = 
Doctrine_Manager::getInstance()->getAttribute('auto_accessor_override');
+        
Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', true);
+        
+        $user = Doctrine_Query::create()
+            ->from('Ticket_1131_User u')
+            ->where('u.id = ?')->fetchOne(array(1));
+        
+        $this->assertEqual($user->group_id, 1);
+        $this->assertEqual($user->get('group_id'), 1);
+        $this->assertFalse($user->get('group_id') instanceof Doctrine_Record);
+        
+        $this->assertEqual($user->role_id, 2);
+        $this->assertEqual($user->get('role_id'), 2);
+        $this->assertFalse($user->get('role_id') instanceof Doctrine_Record);
+        
+        $this->assertEqual($user->Group->id, 1);
+        $this->assertEqual($user->get('Group')->get('id'), 1);
+        
+        $this->assertEqual($user->Role->id, 2);
+        $this->assertEqual($user->get('Role')->get('id'), 2);
+        
+        
Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', $orig);
+    }
+    
+    public function testOverloadingWithJoins()
+    {
+        $orig = 
Doctrine_Manager::getInstance()->getAttribute('auto_accessor_override');
+        
Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', true);
+        
+        $user = Doctrine_Query::create()
+            ->from('Ticket_1131_UserWithOverloading u')
+            ->leftJoin('u.Group g')
+            ->leftJoin('u.Role r')
+            ->addWhere('u.id = ?')->fetchOne(array(1));
+        
+        $this->assertEqual($user->group_id, 1);
+        $this->assertEqual($user->get('group_id'), 1);
+        $this->assertFalse($user->get('group_id') instanceof Doctrine_Record);
+        
+        $this->assertEqual($user->role_id, 1);
+        $this->assertEqual($user->get('role_id'), 1);
+        $this->assertFalse($user->get('role_id') instanceof Doctrine_Record);
+        
+        $this->assertEqual($user->Group->id, 1);
+        $this->assertEqual($user->get('Group')->get('id'), 1);
+        
+        $this->assertEqual($user->Role->id, 1);
+        $this->assertEqual($user->get('Role')->get('id'), 1);
+        
+        
Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', $orig);
+    }
 }
 
 class Ticket_1131_User extends Doctrine_Record
@@ -76,6 +155,9 @@
         $this->hasColumn('group_id', 'integer', 20, array(
             'notnull' => false, 'default' => null
         ));
+        $this->hasColumn('role_id', 'integer', 20, array(
+            'notnull' => false, 'default' => null
+        ));
         $this->hasColumn('name', 'string', 255);
     }
 
@@ -85,22 +167,65 @@
             'local' => 'group_id',
             'foreign' => 'id'
         ));
+        
+        $this->hasOne('Ticket_1131_Role as Role', array(
+            'local' => 'role_id',
+            'foreign' => 'id'));
     }
 }
 
+class Ticket_1131_UserWithOverloading extends Ticket_1131_User
+{
+    public function getRole()
+    {
+        return $this->Group->Role;
+    }
+    
+    public function getRoleId()
+    {
+        return $this->Group->role_id;
+    }
+}
 
 class Ticket_1131_Group extends Doctrine_Record
 {
     public function setTableDefinition()
     {
+        $this->hasColumn('role_id', 'integer', 20, array(
+            'notnull' => false, 'default' => null
+        ));
         $this->hasColumn('name', 'string', 255);
     }
 
     public function setUp()
     {
+        $this->hasOne('Ticket_1131_Role as Role', array(
+            'local' => 'role_id',
+            'foreign' => 'id'));
+        
         $this->hasMany('Ticket_1131_User as Users', array(
             'local' => 'id',
             'foreign' => 'group_id'
         ));
     }
+}
+
+class Ticket_1131_Role extends Doctrine_Record
+{
+    public function setTableDefinition()
+    {
+        $this->hasColumn('name', 'string', 255);
+    }
+
+    public function setUp()
+    {
+        $this->hasMany('Ticket_1131_User as Users', array(
+            'local' => 'id',
+            'foreign' => 'role_id'
+        ));
+        $this->hasMany('Ticket_1131_Group as Groups', array(
+            'local' => 'id',
+            'foreign' => 'role_id'
+        ));
+    }
 }
\ No newline at end of file


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"doctrine-svn" group.
 To post to this group, send email to [email protected]
 To unsubscribe from this group, send email to [EMAIL PROTECTED]
 For more options, visit this group at 
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

Reply via email to