Changeset 14663 for events

Show
Ignore:
Timestamp:
06/26/08 23:18:09 (5 years ago)
Author:
kumatch
Message:

Reviewed and refactored.

Location:
events/phpframework/piece_framework/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/piece_framework/trunk/config/orm/mappers/Users.yaml

    r14558 r14663  
    3535    WHERE 
    3636      id <> $id 
    37       AND ( 
    38         (($userName IS NULL OR $userName = '') OR user_name = $userName) 
    39         OR (($email IS NULL OR $email = '') OR email = $email) 
    40       ) 
     37      AND ( user_name = $userName OR email = $email ) 
    4138 
    4239- name: findAllByIdForListFriends 
  • events/phpframework/piece_framework/trunk/libs/Phwittr/Account.php

    r14099 r14663  
    7676    { 
    7777        $mapper = Piece_ORM::getMapper('Users'); 
    78         $duplicatingUser = $mapper->findByCriteriaForConfirmationOfUpdateAccount($user); 
    79         if ($duplicatingUser) { 
     78        $userId = $mapper->findByCriteriaForConfirmationOfUpdateAccount($user); 
     79        if ($userId) { 
    8080            throw new Phwittr_Account_Exception('ユーザ名が重複'); 
    8181        } 
    8282 
    83         $mapper = Piece_ORM::getMapper('Users'); 
    8483        $user->updatedAt = date('Y-m-d H:i:s'); 
    8584 
  • events/phpframework/piece_framework/trunk/specs/Phwittr/AccountSpec.php

    r14099 r14663  
    6161        @unlink($this->_sampleDirectory . '/example_mini.png'); 
    6262        @unlink($this->_sampleDirectory . '/example_normal.png'); 
     63 
     64        $this->_fooId = $this->_createUserRecord($this->_foo); 
     65        $this->_createUserRecord($this->_bar); 
     66    } 
     67 
     68    public function after() 
     69    { 
     70        $mapper = Piece_ORM::getMapper('Users'); 
     71        $user->id = $this->_fooId; 
     72        $mapper->delete($user); 
     73 
     74        $this->_fooId = $this->_createUserRecord($this->_foo); 
    6375    } 
    6476 
     
    7183    } 
    7284 
     85    public function it変更後のユーザ名が重複しないかを確認して問題がなければ正を得る() 
     86    { 
     87        $mapper = Piece_ORM::getMapper('Users'); 
     88        $user = $mapper->findByUserName($this->_foo->userName); 
     89 
     90        $this->spec(Phwittr_Account::confirmNewUserName($user->id, 'NewUserName') 
     91                    )->should->beTrue(); 
     92    } 
     93 
     94    public function it変更後のユーザ名が重複していれば例外発生() 
     95    { 
     96        $mapper = Piece_ORM::getMapper('Users'); 
     97        $user = $mapper->findByUserName($this->_foo->userName); 
     98 
     99        try { 
     100            Phwittr_Account::confirmNewUserName($user->id, $this->_bar->userName); 
     101        } catch (Phwittr_Account_Exception $e) { 
     102            return; 
     103        } 
     104 
     105        $this->fail(); 
     106    } 
     107 
     108    public function it変更後のメールアドレスが重複しないかを確認して問題がなければ正を得る() 
     109    { 
     110        $mapper = Piece_ORM::getMapper('Users'); 
     111        $user = $mapper->findByUserName($this->_foo->userName); 
     112 
     113        $this->spec(Phwittr_Account::confirmNewEmail($user->id, 'new@example.com') 
     114                    )->should->beTrue(); 
     115    } 
     116 
     117    public function it変更後のメールアドレスが重複していれば例外発生() 
     118    { 
     119        $mapper = Piece_ORM::getMapper('Users'); 
     120        $user = $mapper->findByUserName($this->_foo->userName); 
     121 
     122        try { 
     123            Phwittr_Account::confirmNewEmail($user->id, $this->_bar->email); 
     124        } catch (Phwittr_Account_Exception $e) { 
     125            return; 
     126        } 
     127 
     128        $this->fail(); 
     129    } 
     130 
     131    public function itユーザ名が他レコードのものと重複している状態では更新できない() 
     132    { 
     133        $mapper = Piece_ORM::getMapper('Users'); 
     134        $fooUser = $mapper->findByUserName($this->_foo->userName); 
     135 
     136        $fooUser->userName = $this->_bar->userName; 
     137 
     138        try { 
     139            $account = new Phwittr_Account(); 
     140            $account->update($fooUser); 
     141        } catch (Phwittr_Account_Exception $e) { 
     142            return; 
     143        } 
     144 
     145        $this->fail(); 
     146    } 
     147 
     148    public function itメールアドレスが他レコードのものと重複している状態では更新できない() 
     149    { 
     150        $mapper = Piece_ORM::getMapper('Users'); 
     151        $user = $mapper->findByUserName($this->_foo->userName); 
     152 
     153        $user->email = $this->_bar->email; 
     154 
     155        try { 
     156            $account = new Phwittr_Account(); 
     157            $account->update($user); 
     158        } catch (Phwittr_Account_Exception $e) { 
     159            return; 
     160        } 
     161 
     162        $this->fail(); 
     163    } 
     164 
    73165    public function it基本情報が更新できる() 
    74166    { 
    75         $this->_createUserRecord($this->_foo); 
    76          
    77167        $mapper = Piece_ORM::getMapper('Users'); 
    78168        $user = $mapper->findByUserName($this->_foo->userName); 
    79169 
    80170        $userId = $user->id; 
    81         $user->userName    = $this->_bar->userName; 
    82         $user->email       = $this->_bar->email; 
    83         $user->privateFlag = $this->_bar->flag; 
     171        $user->userName    = $this->_baz->userName; 
     172        $user->email       = $this->_baz->email; 
     173        $user->privateFlag = $this->_baz->flag; 
    84174 
    85175        $account = new Phwittr_Account(); 
     
    88178        $newUser = $mapper->findById($userId); 
    89179 
    90         $this->spec($newUser->userName)->should->be($this->_bar->userName); 
    91         $this->spec($newUser->email)->should->be($this->_bar->email); 
    92         $this->spec($newUser->privateFlag)->should->be($this->_bar->flag); 
    93     } 
    94  
    95     public function it情報更新の際、変更後のユーザ名が重複しないかを事前に確認する() 
    96     { 
    97         $this->_createUserRecord($this->_foo); 
    98  
    99         $mapper = Piece_ORM::getMapper('Users'); 
    100         $user = $mapper->findByUserName($this->_foo->userName); 
    101  
    102         $this->spec(Phwittr_Account::confirmNewUserName($user->id, 'NewUserName') 
    103                     )->should->beTrue(); 
    104     } 
    105  
    106     public function it事前確認における変更後のユーザ名が重複していれば例外発生() 
    107     { 
    108         $this->_createUserRecord($this->_foo); 
    109         $this->_createUserRecord($this->_bar); 
    110  
    111         $mapper = Piece_ORM::getMapper('Users'); 
    112         $user = $mapper->findByUserName($this->_foo->userName); 
    113  
    114         try { 
    115             Phwittr_Account::confirmNewUserName($user->id, $this->_bar->userName); 
    116         } catch (Phwittr_Account_Exception $e) { 
    117             return; 
    118         } 
    119  
    120         $this->fail(); 
    121     } 
    122  
    123     public function it情報更新の際、変更後のメールアドレスが重複しないかを事前に確認する() 
    124     { 
    125         $this->_createUserRecord($this->_foo); 
    126  
    127         $mapper = Piece_ORM::getMapper('Users'); 
    128         $user = $mapper->findByUserName($this->_foo->userName); 
    129  
    130         $this->spec(Phwittr_Account::confirmNewEmail($user->id, 'new@example.com') 
    131                     )->should->beTrue(); 
    132     } 
    133  
    134     public function it事前確認における変更後のメールアドレスが重複していれば例外発生() 
    135     { 
    136         $this->_createUserRecord($this->_foo); 
    137         $this->_createUserRecord($this->_bar); 
    138  
    139         $mapper = Piece_ORM::getMapper('Users'); 
    140         $user = $mapper->findByUserName($this->_foo->userName); 
    141  
    142         try { 
    143             Phwittr_Account::confirmNewEmail($user->id, $this->_bar->email); 
    144         } catch (Phwittr_Account_Exception $e) { 
    145             return; 
    146         } 
    147  
    148         $this->fail(); 
    149     } 
    150  
    151     public function itユーザ名が他レコードのものと重複している状態では更新できない() 
    152     { 
    153         $this->_createUserRecord($this->_foo); 
    154         $this->_createUserRecord($this->_bar); 
    155          
    156         $mapper = Piece_ORM::getMapper('Users'); 
    157         $user = $mapper->findByUserName($this->_foo->userName); 
    158  
    159         $user->userName = $this->_bar->userName; 
    160  
    161         try { 
    162             $account = new Phwittr_Account(); 
    163             $account->update($user); 
    164         } catch (Phwittr_Account_Exception $e) { 
    165             return; 
    166         } 
    167  
    168         $this->fail(); 
    169     } 
    170  
    171     public function itメールアドレスが他レコードのものと重複している状態では更新できない() 
    172     { 
    173         $this->_createUserRecord($this->_foo); 
    174         $this->_createUserRecord($this->_bar); 
    175          
    176         $mapper = Piece_ORM::getMapper('Users'); 
    177         $user = $mapper->findByUserName($this->_foo->userName); 
    178  
    179         $user->email = $this->_bar->email; 
    180  
    181         try { 
    182             $account = new Phwittr_Account(); 
    183             $account->update($user); 
    184         } catch (Phwittr_Account_Exception $e) { 
    185             return; 
    186         } 
    187  
    188         $this->fail(); 
    189     } 
    190  
    191     public function itパスワードは個別で更新() 
    192     { 
    193         $this->_createUserRecord($this->_foo); 
    194          
     180        $this->spec($newUser->userName)->should->be($this->_baz->userName); 
     181        $this->spec($newUser->email)->should->be($this->_baz->email); 
     182        $this->spec($newUser->privateFlag)->should->be($this->_baz->flag); 
     183    } 
     184 
     185    public function itパスワードは個別で更新する() 
     186    { 
    195187        $mapper = Piece_ORM::getMapper('Users'); 
    196188        $user = $mapper->findByUserName($this->_foo->userName); 
     
    212204        $image = $this->_sampleDirectory . '/' . $this->_sampleImage; 
    213205 
    214         $this->_createUserRecord($this->_foo); 
    215          
    216206        $mapper = Piece_ORM::getMapper('Users'); 
    217207        $user = $mapper->findByUserName($this->_foo->userName);