Changeset 14839 for events/phpframework
- Timestamp:
- 06/29/08 18:05:08 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/piece_framework/trunk/specs/Phwittr/Self/FollowingSpec.php
r14838 r14839 11 11 */ 12 12 13 require_once dirname(__FILE__). '/SpecCommon.php'; 14 require_once 'Phwittr/Config.php'; 15 require_once 'Phwittr/User.php'; 13 require_once dirname(__FILE__). '/../SpecCommon.php'; 14 require_once 'Phwittr/Self.php'; 16 15 17 16 // {{{ Describeフォロー … … 52 51 */ 53 52 54 public function it他のユーザをフレンドに追加できる()53 public function beforeAll() 55 54 { 55 parent::beforeAll(); 56 56 57 $this->_createUserRecord($this->_foo); 57 58 $this->_createUserRecord($this->_bar); 59 $this->_createUserRecord($this->_baz); 58 60 59 61 $mapper = Piece_ORM::getMapper('Users'); 60 $fooUser = $mapper->findByUserName($this->_foo->userName); 61 $barUser = $mapper->findByUserName($this->_bar->userName); 62 $this->_foo = $mapper->findByUserName($this->_foo->userName); 63 $this->_bar = $mapper->findByUserName($this->_bar->userName); 64 $this->_baz = $mapper->findByUserName($this->_baz->userName); 62 65 63 $user = new Phwittr_User($fooUser->userName); 64 $user->addFriend($barUser->id); 66 $this->_self = new Phwittr_Self($this->_foo->id); 67 } 68 69 public function itユーザidを指定してフォローすると、フレンドに加わる() 70 { 71 $this->_self->follow($this->_bar->id); 65 72 66 73 $mapper = Piece_ORM::getMapper('Followers'); 67 $followers = $mapper->findAllByUserId($ fooUser->id);74 $followers = $mapper->findAllByUserId($this->_foo->id); 68 75 69 foreach ($followers as $follower) { 70 $this->spec($follower->userId)->should->be($fooUser->id); 71 $this->spec($follower->followId)->should->be($barUser->id); 72 } 76 $this->spec($followers[0]->userId)->should->be($this->_foo->id); 77 $this->spec($followers[0]->followId)->should->be($this->_bar->id); 73 78 } 74 79 75 public function itフレンド を削除できる()80 public function itフレンドにいるユーザのidを指定して削除すると、フレンドからいなくなる() 76 81 { 77 $this->_createUserRecord($this->_foo); 78 $this->_createUserRecord($this->_bar); 79 80 $mapper = Piece_ORM::getMapper('Users'); 81 $fooUser = $mapper->findByUserName($this->_foo->userName); 82 $barUser = $mapper->findByUserName($this->_bar->userName); 83 84 $this->_createFollowerRecord($fooUser->id, $barUser->id); 85 86 $user = new Phwittr_User($fooUser->userName); 87 $user->removeFriend($barUser->id); 82 $this->_self->removeFriend($this->_bar->id); 88 83 89 84 $mapper = Piece_ORM::getMapper('Followers'); 90 $followers = $mapper->findAllByUserId($fooUser->id); 91 85 $followers = $mapper->findAllByUserId($this->_foo->id); 92 86 $this->spec(count($followers))->should->be(0); 93 87 } 94 88 95 public function it自分をフ レンドに追加しようとすると例外発生()89 public function it自分をフォローしようとすると例外が発生する() 96 90 { 97 $this->_createUserRecord($this->_foo);98 99 $mapper = Piece_ORM::getMapper('Users');100 $fooUser = $mapper->findByUserName($this->_foo->userName);101 102 $user = new Phwittr_User($fooUser->userName);103 104 91 try { 105 $ user->addFriend($fooUser->id);106 } catch (Phwittr_ User_Exception $e) {92 $this->_self->follow($this->_foo->id); 93 } catch (Phwittr_Self_Exception $e) { 107 94 return; 108 95 } … … 111 98 } 112 99 113 public function it既にフレンドのユーザを 再び追加しようとすると例外発生()100 public function it既にフレンドのユーザをフォローしようとすると例外が発生する() 114 101 { 115 $this->_createUserRecord($this->_foo); 116 $this->_createUserRecord($this->_bar); 117 118 $mapper = Piece_ORM::getMapper('Users'); 119 $fooUser = $mapper->findByUserName($this->_foo->userName); 120 $barUser = $mapper->findByUserName($this->_bar->userName); 121 122 $user = new Phwittr_User($fooUser->userName); 123 $user->addFriend($barUser->id); 102 $this->_self->follow($this->_bar->id); 124 103 125 104 try { 126 $ user->addFriend($barUser->id);127 } catch (Phwittr_ User_Exception $e) {105 $this->_self->follow($this->_bar->id); 106 } catch (Phwittr_Self_Exception $e) { 128 107 return; 129 108 } … … 132 111 } 133 112 134 public function it存在しないユーザを 追加しようとすると例外発生()113 public function it存在しないユーザをフォローしようとすると例外が発生する() 135 114 { 136 115 try { 137 $this->_createUserRecord($this->_foo); 138 139 $mapper = Piece_ORM::getMapper('Users'); 140 $fooUser = $mapper->findByUserName($this->_foo->userName); 141 142 $following = new Phwittr_User($fooUser->userName); 143 $following->addFriend(100); 144 } catch (Phwittr_User_Exception $e) { 116 $this->_self->follow(100); 117 } catch (Phwittr_Self_Exception $e) { 145 118 return; 146 119 } … … 149 122 } 150 123 151 public function it自分をフレンドから削除しようとすると例外 発生()124 public function it自分をフレンドから削除しようとすると例外が発生する() 152 125 { 153 $this->_createUserRecord($this->_foo);154 155 $mapper = Piece_ORM::getMapper('Users');156 $fooUser = $mapper->findByUserName($this->_foo->userName);157 158 $user = new Phwittr_User($fooUser->userName);159 160 126 try { 161 $ user->removeFriend($fooUser->id);162 } catch (Phwittr_ User_Exception $e) {127 $this->_self->removeFriend($this->_foo->id); 128 } catch (Phwittr_Self_Exception $e) { 163 129 return; 164 130 } … … 167 133 } 168 134 169 public function it関係ないユーザをフレンドから削除しようとすると例外 発生()135 public function it関係ないユーザをフレンドから削除しようとすると例外が発生する() 170 136 { 171 $this->_createUserRecord($this->_foo);172 $this->_createUserRecord($this->_bar);173 174 $mapper = Piece_ORM::getMapper('Users');175 $fooUser = $mapper->findByUserName($this->_foo->userName);176 $barUser = $mapper->findByUserName($this->_bar->userName);177 178 $user = new Phwittr_User($fooUser->userName);179 180 137 try { 181 $ user->removeFriend($barUser->id);182 } catch (Phwittr_ User_Exception $e) {138 $this->_self->removeFriend($this->_baz->id); 139 } catch (Phwittr_Self_Exception $e) { 183 140 return; 184 141 } … … 187 144 } 188 145 189 public function it存在しないユーザをフレンドから削除しようとすると例外 発生()146 public function it存在しないユーザをフレンドから削除しようとすると例外が発生する() 190 147 { 191 $this->_createUserRecord($this->_foo);192 193 $mapper = Piece_ORM::getMapper('Users');194 $fooUser = $mapper->findByUserName($this->_foo->userName);195 196 $user = new Phwittr_User($fooUser->userName);197 198 148 try { 199 $ user->removeFriend(100);200 } catch (Phwittr_ User_Exception $e) {149 $this->_self->removeFriend(100); 150 } catch (Phwittr_Self_Exception $e) { 201 151 return; 202 152 } … … 207 157 public function it対象ユーザが既にフレンド済みならば、フレンド確認結果は真() 208 158 { 209 $this->_createUserRecord($this->_foo); 210 $this->_createUserRecord($this->_bar); 211 212 $mapper = Piece_ORM::getMapper('Users'); 213 $fooUser = $mapper->findByUserName($this->_foo->userName); 214 $barUser = $mapper->findByUserName($this->_bar->userName); 215 216 $this->_createFollowerRecord($fooUser->id, $barUser->id); 217 218 $user = new Phwittr_User($fooUser->userName); 219 $result = $user->isFriend($barUser->id); 220 221 $this->spec($result)->should->beTrue(); 159 $this->spec($this->_self->isFriend($this->_bar->id))->should->beTrue(); 222 160 } 223 161 224 162 public function it対象ユーザがフレンドでなければ、フレンド確認結果は偽() 225 163 { 226 $this->_createUserRecord($this->_foo); 227 $this->_createUserRecord($this->_bar); 228 229 $mapper = Piece_ORM::getMapper('Users'); 230 $fooUser = $mapper->findByUserName($this->_foo->userName); 231 $barUser = $mapper->findByUserName($this->_bar->userName); 232 233 $user = new Phwittr_User($fooUser->userName); 234 $result = $user->isFriend($barUser->id); 235 236 $this->spec($result)->should->beFalse(); 237 } 238 239 public function it自身のフレンドをリスト化できる() 240 { 241 $this->_createUserRecord($this->_foo); 242 $this->_createUserRecord($this->_bar); 243 $this->_createUserRecord($this->_baz); 244 245 $mapper = Piece_ORM::getMapper('Users'); 246 $fooUser = $mapper->findByUserName($this->_foo->userName); 247 $barUser = $mapper->findByUserName($this->_bar->userName); 248 $bazUser = $mapper->findByUserName($this->_baz->userName); 249 250 $this->_createFollowerRecord($fooUser->id, $barUser->id); 251 $this->_createFollowerRecord($fooUser->id, $bazUser->id); 252 253 $user = new Phwittr_User($fooUser->userName); 254 $friendList = $user->listFriends(); 255 256 $this->spec(count($friendList))->should->be(2); 257 $this->spec($friendList[0]->id)->should->be($barUser->id); 258 $this->spec($friendList[0]->userName)->should->be($this->_bar->userName); 259 $this->spec($friendList[1]->id)->should->be($bazUser->id); 260 $this->spec($friendList[1]->userName)->should->be($this->_baz->userName); 261 } 262 263 public function it自身をフォローしているユーザをリスト化できる() 264 { 265 $this->_createUserRecord($this->_foo); 266 $this->_createUserRecord($this->_bar); 267 $this->_createUserRecord($this->_baz); 268 269 $mapper = Piece_ORM::getMapper('Users'); 270 $fooUser = $mapper->findByUserName($this->_foo->userName); 271 $barUser = $mapper->findByUserName($this->_bar->userName); 272 $bazUser = $mapper->findByUserName($this->_baz->userName); 273 274 $this->_createFollowerRecord($barUser->id, $fooUser->id); 275 $this->_createFollowerRecord($bazUser->id, $fooUser->id); 276 277 $user = new Phwittr_User($fooUser->userName); 278 $followerList = $user->listFollowers(); 279 280 $this->spec(count($followerList))->should->be(2); 281 $this->spec($followerList[0]->id)->should->be($barUser->id); 282 $this->spec($followerList[0]->userName)->should->be($this->_bar->userName); 283 $this->spec($followerList[1]->id)->should->be($bazUser->id); 284 $this->spec($followerList[1]->userName)->should->be($this->_baz->userName); 285 } 286 287 public function itユーザのリスト化すると、通常は古いユーザからの20件() 288 { 289 $this->_createUserRecord($this->_foo); 290 291 $mapper = Piece_ORM::getMapper('Users'); 292 $fooUser = $mapper->findByUserName($this->_foo->userName); 293 $user = new Phwittr_User($fooUser->userName); 294 295 for ($i < 0; $i < 100; ++$i) { 296 $basename = sprintf('user%d', $i); 297 298 $mockUser = new stdClass(); 299 $mockUser->userName = $basename; 300 $mockUser->email = "{$basename}@example.com"; 301 $mockUser->password = sha1($basename); 302 $mockUser->registrationKey = 1; 303 $mockId = $this->_createUserRecord($mockUser); 304 $user->addFriend($mockId); 305 } 306 307 $friendList = $user->listFriends(); 308 309 $this->spec(count($friendList))->should->be(20); 310 311 $count = 0; 312 foreach ($friendList as $friend) { 313 $this->spec($friend->userName)->should->be("user{$count}"); 314 ++$count; 315 } 316 } 317 318 public function it表示されるユーザリスト20件のページが指定できる() 319 { 320 $this->_createUserRecord($this->_foo); 321 322 $mapper = Piece_ORM::getMapper('Users'); 323 $fooUser = $mapper->findByUserName($this->_foo->userName); 324 $user = new Phwittr_User($fooUser->userName); 325 326 for ($i < 0; $i < 100; ++$i) { 327 $basename = sprintf('user%d', $i); 328 329 $mockUser = new stdClass(); 330 $mockUser->userName = $basename; 331 $mockUser->email = "{$basename}@example.com"; 332 $mockUser->password = sha1($basename); 333 $mockUser->registrationKey = 1; 334 $mockId = $this->_createUserRecord($mockUser); 335 $user->addFriend($mockId); 336 } 337 338 $page = 3; 339 $friendList = $user->listFriends($page); 340 341 $this->spec(count($friendList))->should->be(20); 342 343 $count = 40; 344 foreach ($friendList as $friend) { 345 $this->spec($friend->userName)->should->be("user{$count}"); 346 ++$count; 347 } 348 } 349 350 public function itユーザリスト取得直後、次ページがあるかどうかを知れる() 351 { 352 $this->_createUserRecord($this->_foo); 353 354 $mapper = Piece_ORM::getMapper('Users'); 355 $fooUser = $mapper->findByUserName($this->_foo->userName); 356 $user = new Phwittr_User($fooUser->userName); 357 358 for ($i < 0; $i < 30; ++$i) { 359 $basename = sprintf('user%d', $i); 360 361 $mockUser = new stdClass(); 362 $mockUser->userName = $basename; 363 $mockUser->email = "{$basename}@example.com"; 364 $mockUser->password = sha1($basename); 365 $mockUser->registrationKey = 1; 366 $mockId = $this->_createUserRecord($mockUser); 367 $user->addFriend($mockId); 368 } 369 370 $friendList = $user->listFriends(); 371 372 $this->spec($user->hasNestPage())->should->beTrue(); 373 } 374 375 public function itユーザリストの最後のページを取得すれば、これ以上古いページはない() 376 { 377 $this->_createUserRecord($this->_foo); 378 379 $mapper = Piece_ORM::getMapper('Users'); 380 $fooUser = $mapper->findByUserName($this->_foo->userName); 381 $user = new Phwittr_User($fooUser->userName); 382 383 for ($i < 0; $i < 10; ++$i) { 384 $basename = sprintf('user%d', $i); 385 386 $mockUser = new stdClass(); 387 $mockUser->userName = $basename; 388 $mockUser->email = "{$basename}@example.com"; 389 $mockUser->password = sha1($basename); 390 $mockUser->registrationKey = 1; 391 $mockId = $this->_createUserRecord($mockUser); 392 $user->addFriend($mockId); 393 } 394 395 $friendList = $user->listFriends(); 396 397 $this->spec($user->hasNestPage())->should->beFalse(); 398 } 399 400 public function itユーザリスト取得を行っていなければ、古いページがあるかどうかは知れずに例外が発生する() 401 { 402 $this->_createUserRecord($this->_foo); 403 404 $mapper = Piece_ORM::getMapper('Users'); 405 $fooUser = $mapper->findByUserName($this->_foo->userName); 406 $user = new Phwittr_User($fooUser->userName); 407 408 for ($i < 0; $i < 10; ++$i) { 409 $basename = sprintf('user%d', $i); 410 411 $mockUser = new stdClass(); 412 $mockUser->userName = $basename; 413 $mockUser->email = "{$basename}@example.com"; 414 $mockUser->password = sha1($basename); 415 $mockUser->registrationKey = 1; 416 $mockId = $this->_createUserRecord($mockUser); 417 $user->addFriend($mockId); 418 } 419 420 try { 421 $user->hasNestPage(); 422 } catch (Phwittr_User_Exception $e) { 423 return; 424 } 425 426 $this->fail(); 164 $this->spec($this->_self->isFriend($this->_baz->id))->should->beFalse(); 427 165 } 428 166
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)