Changeset 4492

Show
Ignore:
Timestamp:
06/08/08 19:23:14 (13 months ago)
Author:
jwage
Message:

Coverage for #1121

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/tests/Ticket/1121TestCase.php

    r4490 r4492  
    4444        $q = Doctrine_Query::create() 
    4545                ->from('Ticket_1121_User u') 
    46                 ->leftJoin('u.CustomProfileAlias p'); 
     46                // UserProfile has SoftDelete behavior but because it is aliased as Profile, it tries to  
     47                // call the dql callbacks for the query on a class named Profile instead of UserProfile 
     48                // Code responsible for this is in Doctrine_Query_Abstract::_preQuery() 
     49                ->leftJoin('u.Profile p'); 
    4750 
    48         try { 
    49             $q->execute(); 
    50             $this->pass(); 
    51         } catch (Exception $e) { 
    52             $this->fail($e->getMessage()); 
    53         } 
    54          
    55     } 
    56 } 
    57  
    58 spl_autoload_register(array('Ticket_1121_Autoloader', 'autoload')); 
    59  
    60 class Ticket_1121_Autoloader 
    61 { 
    62     public static function autoload($className) 
    63     { 
    64         // You will see the above query is parsing the from parts of the query 
    65         if ($className == 'CustomProfileAlias' || $className == 'CustomUserAlias') { 
    66             throw new Exception('DQL callbacks being called for CustomProfileAlias and CustomUserAlias. These are the relationship aliases, not the class name in this case'); 
    67         } 
     51        // The condition and params for UserProfile SoftDelete and are not added properly 
     52        $this->assertEqual($q->getSql(), 'SELECT t.id AS t__id, t.username AS t__username, t.password AS t__password, t.profile_id AS t__profile_id, t.deleted AS t__deleted, t2.id AS t2__id, t2.name AS t2__name, t2.about AS t2__about, t2.deleted AS t2__deleted FROM ticket_1121__user t LEFT JOIN ticket_1121__profile t2 ON t.profile_id = t2.id WHERE t.deleted = ? AND t2.deleted = ?'); 
     53        $this->assertEqual(count($q->getParams()), 2); 
    6854    } 
    6955} 
     
    8066    public function setUp() 
    8167    { 
    82         $this->hasOne('Ticket_1121_Profile as CustomProfileAlias', array('local'   => 'profile_id', 
     68        $this->actAs('SoftDelete'); 
     69        $this->hasOne('Ticket_1121_Profile as Profile', array('local'   => 'profile_id', 
    8370                                                              'foreign' => 'id')); 
    8471    } 
     
    9178        $this->hasColumn('name', 'string', 255); 
    9279        $this->hasColumn('about', 'string', 2000); 
    93         $this->hasColumn('active', 'integer'); 
    94         $this->addListener(new Ticket_1121_Profile_Listener()); 
    9580    } 
    9681 
    9782    public function setUp() 
    9883    { 
    99         $this->hasOne('Ticket_1121_User as CustomUserAlias', array('local'   => 'id', 
     84        $this->actAs('SoftDelete'); 
     85        $this->hasOne('Ticket_1121_User as User', array('local'   => 'id', 
    10086                                                        'foreign' => 'profile_id')); 
    10187    } 
    10288} 
    103  
    104 class Ticket_1121_Profile_Listener extends Doctrine_Record_Listener 
    105 { 
    106     public function preDqlSelect(Doctrine_Event $event) 
    107     { 
    108         $params = $event->getParams(); 
    109         $field = $params['alias'] . '.active'; 
    110  
    111         $event->getQuery()->addWhere($field . ' = ?', 1); 
    112     } 
    113 }