- Timestamp:
- 05/30/08 00:16:02 (5 years ago)
- Location:
- events/phpframework/piece_framework/trunk/specs/Phwittr
- Files:
-
- 1 added
- 3 modified
-
AccountSpec.php (modified) (8 diffs)
-
AuthenticationSpec.php (modified) (9 diffs)
-
SignupSpec.php (modified) (9 diffs)
-
SpecCommon.php (added)
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/piece_framework/trunk/specs/Phwittr/AccountSpec.php
r12820 r12825 7 7 * @package Phwittr_PieceFramework 8 8 * @copyright 2008 KUMAKURA Yousuke All rights reserved. 9 * @version SVN: $Id :$9 * @version SVN: $Id$ 10 10 * @since File available since Release 0.1.0 11 11 */ 12 12 13 require_once dirname(__FILE__) . '/SpecCommon.php'; 13 14 require_once 'Phwittr/Config.php'; 14 15 require_once 'Phwittr/Account.php'; … … 24 25 * @since Class available since Release 0.1.0 25 26 */ 26 class Describeアカウント情報 extends P HPSpec_Context27 class Describeアカウント情報 extends Phwittr_SpecCommon 27 28 { 28 29 … … 51 52 */ 52 53 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 92 54 public function it基本情報が更新できる() 93 55 { 94 $this->_create UserRecord();56 $this->_createFooUserRecord(); 95 57 96 $userName = 'bar';97 $email = 'bar@example.com';98 $privateFlag = '1';99 100 58 $mapper = Piece_ORM::getMapper('Users'); 101 $user = $mapper->findByUserName($this->_ userName);59 $user = $mapper->findByUserName($this->_foo->userName); 102 60 103 61 $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; 108 65 109 66 $account = new Phwittr_Account(); … … 112 69 $newUser = $mapper->findById($userId); 113 70 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); 117 74 } 118 75 119 76 public function itユーザ名が他レコードのものと重複している状態では更新できない() 120 77 { 121 $this->_create UserRecord();122 $this->_create User2Record();78 $this->_createFooUserRecord(); 79 $this->_createBarUserRecord(); 123 80 124 81 $mapper = Piece_ORM::getMapper('Users'); 125 $user = $mapper->findByUserName($this->_ userName);82 $user = $mapper->findByUserName($this->_foo->userName); 126 83 127 $user->userName = $this->_ userName2;84 $user->userName = $this->_bar->userName; 128 85 129 86 try { … … 139 96 public function itメールアドレスが他レコードのものと重複している状態では更新できない() 140 97 { 141 $this->_create UserRecord();142 $this->_create User2Record();98 $this->_createFooUserRecord(); 99 $this->_createBarUserRecord(); 143 100 144 101 $mapper = Piece_ORM::getMapper('Users'); 145 $user = $mapper->findByUserName($this->_ userName);102 $user = $mapper->findByUserName($this->_foo->userName); 146 103 147 $user->email = $this->_ email2;104 $user->email = $this->_bar->email; 148 105 149 106 try { … … 159 116 public function itパスワードは個別で更新() 160 117 { 161 $this->_create UserRecord();118 $this->_createFooUserRecord(); 162 119 163 120 $mapper = Piece_ORM::getMapper('Users'); 164 $user = $mapper->findByUserName($this->_ userName);121 $user = $mapper->findByUserName($this->_foo->userName); 165 122 166 123 $userId = $user->id; … … 173 130 174 131 $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); 176 133 } 177 134 … … 193 150 */ 194 151 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 225 152 /**#@-*/ 226 153 -
events/phpframework/piece_framework/trunk/specs/Phwittr/AuthenticationSpec.php
r12817 r12825 7 7 * @package Phwittr_PieceFramework 8 8 * @copyright 2008 KUMAKURA Yousuke All rights reserved. 9 * @version SVN: $Id :$9 * @version SVN: $Id$ 10 10 * @since File available since Release 0.1.0 11 11 */ 12 12 13 require_once dirname(__FILE__) . '/SpecCommon.php'; 13 14 require_once 'Phwittr/Config.php'; 14 15 require_once 'Phwittr/Authentication.php'; … … 24 25 * @since Class available since Release 0.1.0 25 26 */ 26 class Describe認証 extends P HPSpec_Context27 class Describe認証 extends Phwittr_SpecCommon 27 28 { 28 29 … … 51 52 */ 52 53 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 87 54 public function it認証はユーザ名とパスワードで行う() 88 55 { 89 $this->_create UserRecord();56 $this->_createFooUserRecord(); 90 57 91 58 $authenticator = new Phwittr_Authentication(); 92 $result = $authenticator->authenticate($this->_userName, $this->_password); 59 $result = $authenticator->authenticate($this->_foo->userName, 60 $this->_foo->password 61 ); 93 62 94 63 $this->spec($result)->should->beTrue(); … … 97 66 public function it認証はメールアドレスとパスワードでも行える() 98 67 { 99 $this->_create UserRecord();68 $this->_createFooUserRecord(); 100 69 101 70 $authenticator = new Phwittr_Authentication(); 102 $result = $authenticator->authenticate($this->_email, $this->_password); 71 $result = $authenticator->authenticate($this->_foo->email, 72 $this->_foo->password 73 ); 103 74 104 75 $this->spec($result)->should->beTrue(); … … 107 78 public function it間違った情報では認証は認められない() 108 79 { 109 $this->_create UserRecord();80 $this->_createFooUserRecord(); 110 81 111 82 $authenticator = new Phwittr_Authentication(); … … 113 84 $this->spec($authenticator->authenticate('dummy', 'dummy'))->should->beFalse(); 114 85 $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(); 119 90 } 120 91 121 92 public function it仮登録状態のユーザの認証は認められない() 122 93 { 123 $this->_f lag = 0;124 $this->_create UserRecord();125 $this->_f lag = 1;94 $this->_foo->flag = 0; 95 $this->_createFooUserRecord(); 96 $this->_foo->flag = 1; 126 97 127 98 $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 ); 130 105 131 106 $this->spec($result1)->should->beFalse(); … … 135 110 public function it認証後にユーザ情報が取得できる() 136 111 { 137 $this->_create UserRecord();112 $this->_createFooUserRecord(); 138 113 139 114 $authenticator = new Phwittr_Authentication(); 140 $authenticator->authenticate($this->_userName, $this->_password); 115 $authenticator->authenticate($this->_foo->userName, 116 $this->_foo->password 117 ); 141 118 $user = $authenticator->getAuthenticatedUser(); 142 119 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); 145 122 } 146 123 147 124 public function it認証前にユーザ情報を取得しても空() 148 125 { 149 $this->_create UserRecord();126 $this->_createFooUserRecord(); 150 127 151 128 $authenticator = new Phwittr_Authentication(); … … 157 134 public function it認証に失敗した後にユーザ情報を取得しても空() 158 135 { 159 $this->_create UserRecord();136 $this->_createFooUserRecord(); 160 137 161 138 $authenticator = new Phwittr_Authentication(); … … 178 155 */ 179 156 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 195 157 /**#@-*/ 196 158 -
events/phpframework/piece_framework/trunk/specs/Phwittr/SignupSpec.php
r12645 r12825 7 7 * @package Phwittr_PieceFramework 8 8 * @copyright 2008 KUMAKURA Yousuke All rights reserved. 9 * @version SVN: $Id :$9 * @version SVN: $Id$ 10 10 * @since File available since Release 0.1.0 11 11 */ 12 12 13 require_once dirname(__FILE__) . '/SpecCommon.php'; 13 14 require_once 'Phwittr/Config.php'; 14 15 require_once 'Phwittr/Signup.php'; … … 24 25 * @since Class available since Release 0.1.0 25 26 */ 26 class Describe登録 extends P HPSpec_Context27 class Describe登録 extends Phwittr_SpecCommon 27 28 { 28 29 … … 51 52 */ 52 53 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 87 54 public function it仮登録処理を行うと認証キーが発行される() 88 55 { 89 56 $signup = new Phwittr_Signup(); 90 $key = $signup->preregister($this->_ userName,91 $this->_ email,92 $this->_ password57 $key = $signup->preregister($this->_foo->userName, 58 $this->_foo->email, 59 $this->_foo->password 93 60 ); 94 61 … … 96 63 97 64 $mapper = Piece_ORM::getMapper('Users'); 98 $user = $mapper->findByUserName( 'foo');65 $user = $mapper->findByUserName($this->_foo->userName); 99 66 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)); 103 70 $this->spec($user->registrationFlag)->should->be(0); 104 71 $this->spec($user->registrationKey)->should->be($key); … … 107 74 public function it認証キーを渡すと登録が完了する() 108 75 { 109 $this->_createUserRecord(); 76 $this->_foo->flag = 0; 77 $this->_createFooUserRecord(); 110 78 111 79 $signup = new Phwittr_Signup(); 112 $result = $signup->register($this->_ key);80 $result = $signup->register($this->_foo->key); 113 81 114 82 $this->spec($result)->should->be(1); 115 83 116 84 $mapper = Piece_ORM::getMapper('Users'); 117 $user = $mapper->findByUserName( 'foo');85 $user = $mapper->findByUserName($this->_foo->userName); 118 86 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)); 122 90 $this->spec($user->registrationFlag)->should->be(1); 123 91 } … … 126 94 { 127 95 $signup = new Phwittr_Signup(); 128 $result = $signup->isAvailableUserName($this->_ userName);96 $result = $signup->isAvailableUserName($this->_foo->userName); 129 97 130 98 $this->spec($result)->should->beTrue(); … … 133 101 public function itユーザ名が重複していればユーザ名の利用は許可されない() 134 102 { 135 $this->_create UserRecord();103 $this->_createFooUserRecord(); 136 104 137 105 $signup = new Phwittr_Signup(); 138 $result = $signup->isAvailableUserName($this->_ userName);106 $result = $signup->isAvailableUserName($this->_foo->userName); 139 107 140 108 $this->spec($result)->should->beFalse(); … … 143 111 public function itユーザ名が重複しているにも関わらず仮登録処理を行うと、処理は中断される() 144 112 { 145 $this->_create UserRecord();113 $this->_createFooUserRecord(); 146 114 147 115 try { 148 116 $signup = new Phwittr_Signup(); 149 $result = $signup->preregister($this->_ userName,150 $this->_ email,151 $this->_ password117 $result = $signup->preregister($this->_foo->userName, 118 $this->_foo->email, 119 $this->_foo->password 152 120 ); 153 121 } catch (Phwittr_Exception $e) { … … 171 139 */ 172 140 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 185 141 /**#@-*/ 186 142
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)