Changeset 12825 for events

Show
Ignore:
Timestamp:
05/30/08 00:16:02 (5 years ago)
Author:
kumatch
Message:

- improved spec platform.

Location:
events/phpframework/piece_framework/trunk/specs/Phwittr
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/piece_framework/trunk/specs/Phwittr/AccountSpec.php

    r12820 r12825  
    77 * @package    Phwittr_PieceFramework 
    88 * @copyright  2008 KUMAKURA Yousuke All rights reserved. 
    9  * @version    SVN: $Id:$ 
     9 * @version    SVN: $Id$ 
    1010 * @since      File available since Release 0.1.0 
    1111 */ 
    1212 
     13require_once dirname(__FILE__) . '/SpecCommon.php'; 
    1314require_once 'Phwittr/Config.php'; 
    1415require_once 'Phwittr/Account.php'; 
     
    2425 * @since      Class available since Release 0.1.0 
    2526 */ 
    26 class Describeアカウント情報 extends PHPSpec_Context 
     27class Describeアカウント情報 extends Phwittr_SpecCommon 
    2728{ 
    2829 
     
    5152     */ 
    5253 
    53     public function beforeAll() 
    54     { 
    55         Phwittr_Config::configurePieceORM('phwittr_test'); 
    56         $this->_cacheDirectory = dirname(__FILE__) . '/../../cache/orm'; 
    57         $this->after(); 
    58  
    59         $this->_userName = 'foo'; 
    60         $this->_email    = 'foo@example.com'; 
    61         $this->_password = 'foopassword'; 
    62         $this->_flag = 1; 
    63  
    64         $this->_userName2 = 'bar'; 
    65         $this->_email2    = 'bar@example.com'; 
    66         $this->_password2 = 'barpassword'; 
    67         $this->_flag2 = 1; 
    68     } 
    69  
    70     public function before() 
    71     { 
    72         Phwittr_Config::configurePieceORM('phwittr_test'); 
    73     } 
    74  
    75     public function after() 
    76     { 
    77         $mapper = Piece_ORM::getMapper('Users'); 
    78         $mapper->executeQuery("truncate users"); 
    79  
    80         $GLOBALS['PIECE_ORM_Configured'] = false; 
    81         Piece_ORM_Context::clear(); 
    82         Piece_ORM_Mapper_Factory::clearInstances(); 
    83  
    84         $cache = new Cache_Lite_File(array('cacheDir' => "{$this->_cacheDirectory}/", 
    85                                            'masterFile' => '', 
    86                                            'automaticSerialization' => true, 
    87                                            'errorHandlingAPIBreak' => true) 
    88                                      ); 
    89         $cache->clean(); 
    90     } 
    91  
    9254    public function it基本情報が更新できる() 
    9355    { 
    94         $this->_createUserRecord(); 
     56        $this->_createFooUserRecord(); 
    9557         
    96         $userName = 'bar'; 
    97         $email = 'bar@example.com'; 
    98         $privateFlag = '1'; 
    99  
    10058        $mapper = Piece_ORM::getMapper('Users'); 
    101         $user = $mapper->findByUserName($this->_userName); 
     59        $user = $mapper->findByUserName($this->_foo->userName); 
    10260 
    10361        $userId = $user->id; 
    104  
    105         $user->userName = $userName; 
    106         $user->email = $email; 
    107         $user->privateFlag = $privateFlag; 
     62        $user->userName    = $this->_bar->userName; 
     63        $user->email       = $this->_bar->email; 
     64        $user->privateFlag = $this->_bar->flag; 
    10865 
    10966        $account = new Phwittr_Account(); 
     
    11269        $newUser = $mapper->findById($userId); 
    11370 
    114         $this->spec($newUser->userName)->should->be($userName); 
    115         $this->spec($newUser->email)->should->be($email); 
    116         $this->spec($newUser->privateFlag)->should->be($privateFlag); 
     71        $this->spec($newUser->userName)->should->be($this->_bar->userName); 
     72        $this->spec($newUser->email)->should->be($this->_bar->email); 
     73        $this->spec($newUser->privateFlag)->should->be($this->_bar->flag); 
    11774    } 
    11875 
    11976    public function itユーザ名が他レコードのものと重複している状態では更新できない() 
    12077    { 
    121         $this->_createUserRecord(); 
    122         $this->_createUser2Record(); 
     78        $this->_createFooUserRecord(); 
     79        $this->_createBarUserRecord(); 
    12380         
    12481        $mapper = Piece_ORM::getMapper('Users'); 
    125         $user = $mapper->findByUserName($this->_userName); 
     82        $user = $mapper->findByUserName($this->_foo->userName); 
    12683 
    127         $user->userName = $this->_userName2; 
     84        $user->userName = $this->_bar->userName; 
    12885 
    12986        try { 
     
    13996    public function itメールアドレスが他レコードのものと重複している状態では更新できない() 
    14097    { 
    141         $this->_createUserRecord(); 
    142         $this->_createUser2Record(); 
     98        $this->_createFooUserRecord(); 
     99        $this->_createBarUserRecord(); 
    143100         
    144101        $mapper = Piece_ORM::getMapper('Users'); 
    145         $user = $mapper->findByUserName($this->_userName); 
     102        $user = $mapper->findByUserName($this->_foo->userName); 
    146103 
    147         $user->email = $this->_email2; 
     104        $user->email = $this->_bar->email; 
    148105 
    149106        try { 
     
    159116    public function itパスワードは個別で更新() 
    160117    { 
    161         $this->_createUserRecord(); 
     118        $this->_createFooUserRecord(); 
    162119         
    163120        $mapper = Piece_ORM::getMapper('Users'); 
    164         $user = $mapper->findByUserName($this->_userName); 
     121        $user = $mapper->findByUserName($this->_foo->userName); 
    165122 
    166123        $userId = $user->id; 
     
    173130 
    174131        $this->spec($newUser->password)->should->be(sha1($password)); 
    175         $this->spec($newUser->userName)->should->be($this->_userName); 
     132        $this->spec($newUser->userName)->should->be($this->_foo->userName); 
    176133    } 
    177134 
     
    193150     */ 
    194151 
    195     private function _createUserRecord() 
    196     { 
    197         $user = Piece_ORM::createObject('Users'); 
    198         $user->userName = $this->_userName; 
    199         $user->email = $this->_email; 
    200         $user->password = sha1($this->_password); 
    201         $user->registrationKey = sha1('example'); 
    202  
    203         $mapper = Piece_ORM::getMapper('Users'); 
    204         $mapper->insert($user); 
    205  
    206         $user->registrationFlag = $this->_flag; 
    207         $mapper->update($user); 
    208     } 
    209  
    210     private function _createUser2Record() 
    211     { 
    212         $user = Piece_ORM::createObject('Users'); 
    213         $user->userName = $this->_userName2; 
    214         $user->email = $this->_email2; 
    215         $user->password = sha1($this->_password2); 
    216         $user->registrationKey = sha1('example2'); 
    217  
    218         $mapper = Piece_ORM::getMapper('Users'); 
    219         $mapper->insert($user); 
    220  
    221         $user->registrationFlag = $this->_flag2; 
    222         $mapper->update($user); 
    223     } 
    224  
    225152    /**#@-*/ 
    226153 
  • events/phpframework/piece_framework/trunk/specs/Phwittr/AuthenticationSpec.php

    r12817 r12825  
    77 * @package    Phwittr_PieceFramework 
    88 * @copyright  2008 KUMAKURA Yousuke All rights reserved. 
    9  * @version    SVN: $Id:$ 
     9 * @version    SVN: $Id$ 
    1010 * @since      File available since Release 0.1.0 
    1111 */ 
    1212 
     13require_once dirname(__FILE__) . '/SpecCommon.php'; 
    1314require_once 'Phwittr/Config.php'; 
    1415require_once 'Phwittr/Authentication.php'; 
     
    2425 * @since      Class available since Release 0.1.0 
    2526 */ 
    26 class Describe認証 extends PHPSpec_Context 
     27class Describe認証 extends Phwittr_SpecCommon 
    2728{ 
    2829 
     
    5152     */ 
    5253 
    53     public function beforeAll() 
    54     { 
    55         Phwittr_Config::configurePieceORM('phwittr_test'); 
    56         $this->_cacheDirectory = dirname(__FILE__) . '/../../cache/orm'; 
    57         $this->after(); 
    58  
    59         $this->_userName = 'foo'; 
    60         $this->_email    = 'foo@example.com'; 
    61         $this->_password = 'foopassword'; 
    62         $this->_flag = 1; 
    63     } 
    64  
    65     public function before() 
    66     { 
    67         Phwittr_Config::configurePieceORM('phwittr_test'); 
    68     } 
    69  
    70     public function after() 
    71     { 
    72         $mapper = Piece_ORM::getMapper('Users'); 
    73         $mapper->executeQuery("truncate users"); 
    74  
    75         $GLOBALS['PIECE_ORM_Configured'] = false; 
    76         Piece_ORM_Context::clear(); 
    77         Piece_ORM_Mapper_Factory::clearInstances(); 
    78  
    79         $cache = new Cache_Lite_File(array('cacheDir' => "{$this->_cacheDirectory}/", 
    80                                            'masterFile' => '', 
    81                                            'automaticSerialization' => true, 
    82                                            'errorHandlingAPIBreak' => true) 
    83                                      ); 
    84         $cache->clean(); 
    85     } 
    86  
    8754    public function it認証はユーザ名とパスワードで行う() 
    8855    { 
    89         $this->_createUserRecord(); 
     56        $this->_createFooUserRecord(); 
    9057 
    9158        $authenticator = new Phwittr_Authentication(); 
    92         $result = $authenticator->authenticate($this->_userName, $this->_password); 
     59        $result = $authenticator->authenticate($this->_foo->userName, 
     60                                               $this->_foo->password 
     61                                               ); 
    9362 
    9463        $this->spec($result)->should->beTrue(); 
     
    9766    public function it認証はメールアドレスとパスワードでも行える() 
    9867    { 
    99         $this->_createUserRecord(); 
     68        $this->_createFooUserRecord(); 
    10069 
    10170        $authenticator = new Phwittr_Authentication(); 
    102         $result = $authenticator->authenticate($this->_email, $this->_password); 
     71        $result = $authenticator->authenticate($this->_foo->email, 
     72                                               $this->_foo->password 
     73                                               ); 
    10374 
    10475        $this->spec($result)->should->beTrue(); 
     
    10778    public function it間違った情報では認証は認められない() 
    10879    { 
    109         $this->_createUserRecord(); 
     80        $this->_createFooUserRecord(); 
    11081 
    11182        $authenticator = new Phwittr_Authentication(); 
     
    11384        $this->spec($authenticator->authenticate('dummy', 'dummy'))->should->beFalse(); 
    11485        $this->spec($authenticator->authenticate('dummy@example.com', 'dummy'))->should->beFalse(); 
    115         $this->spec($authenticator->authenticate($this->_userName, 'dummy'))->should->beFalse(); 
    116         $this->spec($authenticator->authenticate($this->_email, 'dummy'))->should->beFalse(); 
    117         $this->spec($authenticator->authenticate('dummy', $this->_password))->should->beFalse(); 
    118         $this->spec($authenticator->authenticate('dummy@example.com', $this->_password))->should->beFalse(); 
     86        $this->spec($authenticator->authenticate($this->_foo->userName, 'dummy'))->should->beFalse(); 
     87        $this->spec($authenticator->authenticate($this->_foo->email, 'dummy'))->should->beFalse(); 
     88        $this->spec($authenticator->authenticate('dummy', $this->_foo->password))->should->beFalse(); 
     89        $this->spec($authenticator->authenticate('dummy@example.com', $this->_foo->password))->should->beFalse(); 
    11990    } 
    12091 
    12192    public function it仮登録状態のユーザの認証は認められない() 
    12293    { 
    123         $this->_flag = 0; 
    124         $this->_createUserRecord(); 
    125         $this->_flag = 1; 
     94        $this->_foo->flag = 0; 
     95        $this->_createFooUserRecord(); 
     96        $this->_foo->flag = 1; 
    12697 
    12798        $authenticator = new Phwittr_Authentication(); 
    128         $result1 = $authenticator->authenticate($this->_userName, $this->_password); 
    129         $result2 = $authenticator->authenticate($this->_email, $this->_password); 
     99        $result1 = $authenticator->authenticate($this->_foo->userName, 
     100                                                $this->_foo->password 
     101                                                ); 
     102        $result2 = $authenticator->authenticate($this->_foo->email, 
     103                                                $this->_foo->password 
     104                                                ); 
    130105 
    131106        $this->spec($result1)->should->beFalse(); 
     
    135110    public function it認証後にユーザ情報が取得できる() 
    136111    { 
    137         $this->_createUserRecord(); 
     112        $this->_createFooUserRecord(); 
    138113 
    139114        $authenticator = new Phwittr_Authentication(); 
    140         $authenticator->authenticate($this->_userName, $this->_password); 
     115        $authenticator->authenticate($this->_foo->userName, 
     116                                     $this->_foo->password 
     117                                     ); 
    141118        $user = $authenticator->getAuthenticatedUser(); 
    142119 
    143         $this->spec($user->userName)->should->be($this->_userName); 
    144         $this->spec($user->email)->should->be($this->_email); 
     120        $this->spec($user->userName)->should->be($this->_foo->userName); 
     121        $this->spec($user->email)->should->be($this->_foo->email); 
    145122    } 
    146123 
    147124    public function it認証前にユーザ情報を取得しても空() 
    148125    { 
    149         $this->_createUserRecord(); 
     126        $this->_createFooUserRecord(); 
    150127 
    151128        $authenticator = new Phwittr_Authentication(); 
     
    157134    public function it認証に失敗した後にユーザ情報を取得しても空() 
    158135    { 
    159         $this->_createUserRecord(); 
     136        $this->_createFooUserRecord(); 
    160137 
    161138        $authenticator = new Phwittr_Authentication(); 
     
    178155     */ 
    179156 
    180     private function _createUserRecord() 
    181     { 
    182         $user = Piece_ORM::createObject('Users'); 
    183         $user->userName = $this->_userName; 
    184         $user->email = $this->_email; 
    185         $user->password = sha1($this->_password); 
    186         $user->registrationKey = sha1('example'); 
    187  
    188         $mapper = Piece_ORM::getMapper('Users'); 
    189         $mapper->insert($user); 
    190  
    191         $user->registrationFlag = $this->_flag; 
    192         $mapper->update($user); 
    193     } 
    194  
    195157    /**#@-*/ 
    196158 
  • events/phpframework/piece_framework/trunk/specs/Phwittr/SignupSpec.php

    r12645 r12825  
    77 * @package    Phwittr_PieceFramework 
    88 * @copyright  2008 KUMAKURA Yousuke All rights reserved. 
    9  * @version    SVN: $Id:$ 
     9 * @version    SVN: $Id$ 
    1010 * @since      File available since Release 0.1.0 
    1111 */ 
    1212 
     13require_once dirname(__FILE__) . '/SpecCommon.php'; 
    1314require_once 'Phwittr/Config.php'; 
    1415require_once 'Phwittr/Signup.php'; 
     
    2425 * @since      Class available since Release 0.1.0 
    2526 */ 
    26 class Describe登録 extends PHPSpec_Context 
     27class Describe登録 extends Phwittr_SpecCommon 
    2728{ 
    2829 
     
    5152     */ 
    5253 
    53     public function beforeAll() 
    54     { 
    55         Phwittr_Config::configurePieceORM('phwittr_test'); 
    56         $this->_cacheDirectory = dirname(__FILE__) . '/../../cache/orm'; 
    57         $this->after(); 
    58  
    59         $this->_userName = 'foo'; 
    60         $this->_email    = 'foo@example.com'; 
    61         $this->_password = 'foopassword'; 
    62         $this->_key = sha1('foo'); 
    63     } 
    64  
    65     public function before() 
    66     { 
    67         Phwittr_Config::configurePieceORM('phwittr_test'); 
    68     } 
    69  
    70     public function after() 
    71     { 
    72         $mapper = Piece_ORM::getMapper('Users'); 
    73         $mapper->executeQuery("truncate users"); 
    74  
    75         $GLOBALS['PIECE_ORM_Configured'] = false; 
    76         Piece_ORM_Context::clear(); 
    77         Piece_ORM_Mapper_Factory::clearInstances(); 
    78  
    79         $cache = new Cache_Lite_File(array('cacheDir' => "{$this->_cacheDirectory}/", 
    80                                            'masterFile' => '', 
    81                                            'automaticSerialization' => true, 
    82                                            'errorHandlingAPIBreak' => true) 
    83                                      ); 
    84         $cache->clean(); 
    85     } 
    86  
    8754    public function it仮登録処理を行うと認証キーが発行される() 
    8855    { 
    8956        $signup = new Phwittr_Signup(); 
    90         $key = $signup->preregister($this->_userName, 
    91                                     $this->_email, 
    92                                     $this->_password 
     57        $key = $signup->preregister($this->_foo->userName, 
     58                                    $this->_foo->email, 
     59                                    $this->_foo->password 
    9360                                    ); 
    9461 
     
    9663 
    9764        $mapper = Piece_ORM::getMapper('Users'); 
    98         $user = $mapper->findByUserName('foo'); 
     65        $user = $mapper->findByUserName($this->_foo->userName); 
    9966 
    100         $this->spec($user->userName)->should->be($this->_userName); 
    101         $this->spec($user->email)->should->be($this->_email); 
    102         $this->spec($user->password)->should->be(sha1($this->_password)); 
     67        $this->spec($user->userName)->should->be($this->_foo->userName); 
     68        $this->spec($user->email)->should->be($this->_foo->email); 
     69        $this->spec($user->password)->should->be(sha1($this->_foo->password)); 
    10370        $this->spec($user->registrationFlag)->should->be(0); 
    10471        $this->spec($user->registrationKey)->should->be($key); 
     
    10774    public function it認証キーを渡すと登録が完了する() 
    10875    { 
    109         $this->_createUserRecord(); 
     76        $this->_foo->flag = 0; 
     77        $this->_createFooUserRecord(); 
    11078 
    11179        $signup = new Phwittr_Signup(); 
    112         $result = $signup->register($this->_key); 
     80        $result = $signup->register($this->_foo->key); 
    11381 
    11482        $this->spec($result)->should->be(1); 
    11583 
    11684        $mapper = Piece_ORM::getMapper('Users'); 
    117         $user = $mapper->findByUserName('foo'); 
     85        $user = $mapper->findByUserName($this->_foo->userName); 
    11886 
    119         $this->spec($user->userName)->should->be($this->_userName); 
    120         $this->spec($user->email)->should->be($this->_email); 
    121         $this->spec($user->password)->should->be(sha1($this->_password)); 
     87        $this->spec($user->userName)->should->be($this->_foo->userName); 
     88        $this->spec($user->email)->should->be($this->_foo->email); 
     89        $this->spec($user->password)->should->be(sha1($this->_foo->password)); 
    12290        $this->spec($user->registrationFlag)->should->be(1); 
    12391    } 
     
    12694    { 
    12795        $signup = new Phwittr_Signup(); 
    128         $result = $signup->isAvailableUserName($this->_userName); 
     96        $result = $signup->isAvailableUserName($this->_foo->userName); 
    12997 
    13098        $this->spec($result)->should->beTrue(); 
     
    133101    public function itユーザ名が重複していればユーザ名の利用は許可されない() 
    134102    { 
    135         $this->_createUserRecord(); 
     103        $this->_createFooUserRecord(); 
    136104 
    137105        $signup = new Phwittr_Signup(); 
    138         $result = $signup->isAvailableUserName($this->_userName); 
     106        $result = $signup->isAvailableUserName($this->_foo->userName); 
    139107 
    140108        $this->spec($result)->should->beFalse(); 
     
    143111    public function itユーザ名が重複しているにも関わらず仮登録処理を行うと、処理は中断される() 
    144112    { 
    145         $this->_createUserRecord(); 
     113        $this->_createFooUserRecord(); 
    146114 
    147115        try { 
    148116            $signup = new Phwittr_Signup(); 
    149             $result = $signup->preregister($this->_userName, 
    150                                            $this->_email, 
    151                                            $this->_password 
     117            $result = $signup->preregister($this->_foo->userName, 
     118                                           $this->_foo->email, 
     119                                           $this->_foo->password 
    152120                                           ); 
    153121        } catch (Phwittr_Exception $e) { 
     
    171139     */ 
    172140 
    173     private function _createUserRecord() 
    174     { 
    175         $user = Piece_ORM::createObject('Users'); 
    176         $user->userName = $this->_userName; 
    177         $user->email = $this->_email; 
    178         $user->password = sha1($this->_password); 
    179         $user->registrationKey = $this->_key; 
    180  
    181         $mapper = Piece_ORM::getMapper('Users'); 
    182         $mapper->insert($user); 
    183     } 
    184  
    185141    /**#@-*/ 
    186142