| 132 | | $fooCount = 0; |
| 133 | | $barCount = 0; |
| 134 | | $bazCount = 0; |
| 135 | | foreach ($userStatuses as $userStatus) { |
| 136 | | if ($userStatus->userId == $fooUser->id) { |
| 137 | | ++$fooCount; |
| 138 | | } elseif ($userStatus->userId == $barUser->id) { |
| 139 | | ++$barCount; |
| 140 | | } elseif ($userStatus->userId == $bazUser->id) { |
| 141 | | ++$bazCount; |
| 142 | | } |
| 143 | | } |
| 144 | | |
| 145 | | $this->spec($fooCount)->should->be(1); |
| 146 | | $this->spec($barCount)->should->be(3); |
| 147 | | $this->spec($bazCount)->should->be(2); |
| 148 | | } |
| 149 | | |
| 150 | | public function itArchiveは自身の発言リスト() |
| 151 | | { |
| 152 | | $this->_createUserRecord($this->_foo); |
| 153 | | $this->_createUserRecord($this->_bar); |
| 154 | | $this->_createUserRecord($this->_baz); |
| 155 | | |
| 156 | | $mapper = Piece_ORM::getMapper('Users'); |
| 157 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 158 | | $barUser = $mapper->findByUserName($this->_bar->userName); |
| 159 | | $bazUser = $mapper->findByUserName($this->_baz->userName); |
| 160 | | |
| 161 | | $this->_createStatusRecord($fooUser->id, null, 'foo1'); |
| 162 | | $this->_createStatusRecord($fooUser->id, null, 'foo2'); |
| 163 | | $this->_createStatusRecord($fooUser->id, null, 'foo3'); |
| 164 | | $this->_createStatusRecord($fooUser->id, null, 'foo4'); |
| 165 | | $this->_createStatusRecord($barUser->id, null, 'bar1'); |
| 166 | | $this->_createStatusRecord($barUser->id, null, 'bar2'); |
| 167 | | $this->_createStatusRecord($barUser->id, null, 'bar3'); |
| 168 | | $this->_createStatusRecord($barUser->id, null, 'bar4'); |
| 169 | | $this->_createStatusRecord($bazUser->id, null, 'baz1'); |
| 170 | | $this->_createStatusRecord($bazUser->id, null, 'baz2'); |
| 171 | | $this->_createStatusRecord($bazUser->id, null, 'baz3'); |
| 172 | | $this->_createStatusRecord($bazUser->id, null, 'baz4'); |
| 173 | | |
| 174 | | $status = new Phwittr_Status($fooUser->userName, $fooUser->id); |
| 175 | | $userStatuses = $status->listArchives(); |
| 176 | | $this->spec(count($userStatuses))->should->be(4); |
| 177 | | |
| 178 | | $fooCount = 0; |
| 179 | | foreach ($userStatuses as $userStatus) { |
| 180 | | if ($userStatus->userId == $fooUser->id) { |
| 181 | | ++$fooCount; |
| 182 | | } |
| 183 | | } |
| 184 | | |
| 185 | | $this->spec($fooCount)->should->be(4); |
| 186 | | } |
| 187 | | |
| 188 | | public function itPublicTimelineは公開しているユーザすべての発言リスト() |
| 189 | | { |
| 190 | | $this->_createUserRecord($this->_foo); |
| 191 | | $this->_createUserRecord($this->_bar); |
| 192 | | $this->_createUserRecord($this->_baz); |
| 193 | | |
| 194 | | $mapper = Piece_ORM::getMapper('Users'); |
| 195 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 196 | | $barUser = $mapper->findByUserName($this->_bar->userName); |
| 197 | | $bazUser = $mapper->findByUserName($this->_baz->userName); |
| 198 | | |
| 199 | | $bazUser->privateFlag = 1; |
| 200 | | $mapper->update($bazUser); |
| 201 | | |
| 202 | | $this->_createStatusRecord($fooUser->id, null, 'foo1'); |
| 203 | | $this->_createStatusRecord($fooUser->id, null, 'foo2'); |
| 204 | | $this->_createStatusRecord($fooUser->id, null, 'foo3'); |
| 205 | | $this->_createStatusRecord($fooUser->id, null, 'foo4'); |
| 206 | | $this->_createStatusRecord($barUser->id, null, 'bar1'); |
| 207 | | $this->_createStatusRecord($barUser->id, null, 'bar2'); |
| 208 | | $this->_createStatusRecord($barUser->id, null, 'bar3'); |
| 209 | | $this->_createStatusRecord($barUser->id, null, 'bar4'); |
| 210 | | $this->_createStatusRecord($bazUser->id, null, 'baz1'); |
| 211 | | $this->_createStatusRecord($bazUser->id, null, 'baz2'); |
| 212 | | $this->_createStatusRecord($bazUser->id, null, 'baz3'); |
| 213 | | $this->_createStatusRecord($bazUser->id, null, 'baz4'); |
| 214 | | |
| 215 | | $status = new Phwittr_Status($fooUser->userName, $fooUser->id); |
| 216 | | $userStatuses = $status->listPublicTimeline(); |
| 217 | | $this->spec(count($userStatuses))->should->be(8); |
| 218 | | |
| 219 | | $fooCount = 0; |
| 220 | | $barCount = 0; |
| 221 | | $bazCount = 0; |
| 222 | | foreach ($userStatuses as $userStatus) { |
| 223 | | if ($userStatus->userId == $fooUser->id) { |
| 224 | | ++$fooCount; |
| 225 | | } elseif ($userStatus->userId == $barUser->id) { |
| 226 | | ++$barCount; |
| 227 | | } elseif ($userStatus->userId == $bazUser->id) { |
| 228 | | ++$bazCount; |
| 229 | | } |
| 230 | | } |
| 231 | | |
| 232 | | $this->spec($fooCount)->should->be(4); |
| 233 | | $this->spec($barCount)->should->be(4); |
| 234 | | $this->spec($bazCount)->should->be(0); |
| 235 | | } |
| 236 | | |
| 237 | | public function it対象ユーザの発言リストが取得できる() |
| 238 | | { |
| 239 | | $this->_createUserRecord($this->_foo); |
| 240 | | $this->_createUserRecord($this->_bar); |
| 241 | | |
| 242 | | $mapper = Piece_ORM::getMapper('Users'); |
| 243 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 244 | | $barUser = $mapper->findByUserName($this->_bar->userName); |
| 245 | | |
| 246 | | $this->_createStatusRecord($barUser->id, null, 'bar1'); |
| 247 | | $this->_createStatusRecord($barUser->id, null, 'bar2'); |
| 248 | | $this->_createStatusRecord($barUser->id, null, 'bar3'); |
| 249 | | $this->_createStatusRecord($barUser->id, null, 'bar4'); |
| 250 | | |
| 251 | | $status = new Phwittr_Status($barUser->userName); |
| 252 | | $userStatuses = $status->listArchives(); |
| 253 | | |
| 254 | | $this->spec(count($userStatuses))->should->be(4); |
| 255 | | |
| 256 | | $barCount = 0; |
| 257 | | foreach ($userStatuses as $userStatus) { |
| 258 | | if ($userStatus->userId == $barUser->id) { |
| 259 | | ++$barCount; |
| 260 | | } |
| 261 | | } |
| 262 | | |
| 263 | | $this->spec($barCount)->should->be(4); |
| 264 | | } |
| 265 | | |
| 266 | | public function it該当ユーザのステータスidを指定することで個別に発言を取得できる() |
| 267 | | { |
| 268 | | $this->_createUserRecord($this->_foo); |
| 269 | | |
| 270 | | $mapper = Piece_ORM::getMapper('Users'); |
| 271 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 272 | | |
| 273 | | $this->_createStatusRecord($fooUser->id, null, 'foo1'); |
| 274 | | |
| 275 | | $status = new Phwittr_Status($fooUser->userName); |
| 276 | | |
| 277 | | $fooStatus1 = $status->findStatus(1); |
| 278 | | |
| 279 | | $this->spec($fooStatus1->userId)->should->be($fooUser->id); |
| 280 | | $this->spec($fooStatus1->userName)->should->be($fooUser->userName); |
| 281 | | $this->spec($fooStatus1->comment)->should->be('foo1'); |
| 282 | | } |
| 283 | | |
| 284 | | public function it該当ユーザに対して異なるステータスidを指定して個別発言を取得しようとすると例外発生() |
| 285 | | { |
| 286 | | $this->_createUserRecord($this->_foo); |
| 287 | | |
| 288 | | $mapper = Piece_ORM::getMapper('Users'); |
| 289 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 290 | | |
| 291 | | $this->_createStatusRecord($fooUser->id, null, 'foo1'); |
| 292 | | |
| 293 | | $status = new Phwittr_Status($fooUser->userName); |
| 294 | | |
| 295 | | try { |
| 296 | | $fooStatus1 = $status->findStatus(2); |
| 297 | | } catch (Phwittr_Status_Exception $e) { |
| 298 | | if ($e->getCode() === PHWITTR_STATUS_EXCEPTION_NOT_FOUND) { |
| 299 | | return; |
| 300 | | } |
| 301 | | } |
| 302 | | |
| 303 | | $this->fail(); |
| 304 | | } |
| 305 | | |
| 306 | | public function itプライベートの人の発言はフォローユーザにしか表示されない() |
| 307 | | { |
| 308 | | $this->_createUserRecord($this->_foo); |
| 309 | | $this->_createUserRecord($this->_bar); |
| 310 | | $this->_createUserRecord($this->_baz); |
| 311 | | |
| 312 | | $mapper = Piece_ORM::getMapper('Users'); |
| 313 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 314 | | $barUser = $mapper->findByUserName($this->_bar->userName); |
| 315 | | $bazUser = $mapper->findByUserName($this->_baz->userName); |
| 316 | | |
| 317 | | $barUser->privateFlag = 1; |
| 318 | | $mapper->update($barUser); |
| 319 | | |
| 320 | | $this->_createFollowerRecord($fooUser->id, $barUser->id); |
| 321 | | |
| 322 | | $this->_createStatusRecord($barUser->id, null, 'bar1'); |
| 323 | | $this->_createStatusRecord($barUser->id, null, 'bar2'); |
| 324 | | $this->_createStatusRecord($barUser->id, null, 'bar3'); |
| 325 | | $this->_createStatusRecord($barUser->id, null, 'bar4'); |
| 326 | | |
| 327 | | $statusForFoo = new Phwittr_Status($fooUser->userName, $fooUser->id); |
| 328 | | $statusForBaz = new Phwittr_Status($bazUser->userName, $bazUser->id); |
| 329 | | |
| 330 | | $userStatusesForFoo = $statusForFoo->listByFollowers(); |
| 331 | | $userStatusesForBaz = $statusForBaz->listByFollowers(); |
| 332 | | |
| 333 | | $this->spec(count($userStatusesForFoo))->should->be(4); |
| 334 | | $this->spec(count($userStatusesForBaz))->should->be(0); |
| 335 | | |
| 336 | | $barCount = 0; |
| 337 | | foreach ($userStatusesForFoo as $userStatus) { |
| 338 | | if ($userStatus->userId == $barUser->id) { |
| 339 | | ++$barCount; |
| 340 | | } |
| 341 | | } |
| 342 | | |
| 343 | | $this->spec($barCount)->should->be(4); |
| 344 | | } |
| 345 | | |
| 346 | | public function itプライベートユーザの発言リストをフレンドは取得できる() |
| 347 | | { |
| 348 | | $this->_createUserRecord($this->_foo); |
| 349 | | $this->_createUserRecord($this->_bar); |
| 350 | | |
| 351 | | $mapper = Piece_ORM::getMapper('Users'); |
| 352 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 353 | | $barUser = $mapper->findByUserName($this->_bar->userName); |
| 354 | | |
| 355 | | $this->_createStatusRecord($barUser->id, null, 'bar1'); |
| 356 | | $this->_createStatusRecord($barUser->id, null, 'bar2'); |
| 357 | | $this->_createStatusRecord($barUser->id, null, 'bar3'); |
| 358 | | $this->_createStatusRecord($barUser->id, null, 'bar4'); |
| 359 | | |
| 360 | | $status = new Phwittr_Status($barUser->userName, $fooUser->id); |
| 361 | | $userStatuses = $status->listArchives(); |
| 362 | | |
| 363 | | $this->spec(count($userStatuses))->should->be(4); |
| 364 | | |
| 365 | | $barCount = 0; |
| 366 | | foreach ($userStatuses as $userStatus) { |
| 367 | | if ($userStatus->userId == $barUser->id) { |
| 368 | | ++$barCount; |
| 369 | | } |
| 370 | | } |
| 371 | | |
| 372 | | $this->spec($barCount)->should->be(4); |
| 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 | | |
| 382 | | $fooUser->privateFlag = 1; |
| 383 | | $mapper->update($fooUser); |
| 384 | | |
| 385 | | $this->_createStatusRecord($fooUser->id, null, 'foo1'); |
| 386 | | $this->_createStatusRecord($fooUser->id, null, 'foo2'); |
| 387 | | $this->_createStatusRecord($fooUser->id, null, 'foo3'); |
| 388 | | $this->_createStatusRecord($fooUser->id, null, 'foo4'); |
| 389 | | |
| 390 | | $status = new Phwittr_Status($fooUser->userName, $fooUser->id); |
| 391 | | |
| 392 | | $userStatuses = $status->listArchives(); |
| 393 | | |
| 394 | | $this->spec(count($userStatuses))->should->be(4); |
| 395 | | |
| 396 | | $fooCount = 0; |
| 397 | | foreach ($userStatuses as $userStatus) { |
| 398 | | if ($userStatus->userId == $fooUser->id) { |
| 399 | | ++$fooCount; |
| 400 | | } |
| 401 | | } |
| 402 | | |
| 403 | | $this->spec($fooCount)->should->be(4); |
| 404 | | } |
| 405 | | |
| 406 | | public function itプライベートユーザは自身の個別発言も取得できる() |
| 407 | | { |
| 408 | | $this->_createUserRecord($this->_foo); |
| 409 | | |
| 410 | | $mapper = Piece_ORM::getMapper('Users'); |
| 411 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 412 | | |
| 413 | | $fooUser->privateFlag = 1; |
| 414 | | $mapper->update($fooUser); |
| 415 | | |
| 416 | | $this->_createStatusRecord($fooUser->id, null, 'foo1'); |
| 417 | | |
| 418 | | $status = new Phwittr_Status($fooUser->userName, $fooUser->id); |
| 419 | | |
| 420 | | $fooStatus1 = $status->findStatus(1); |
| 421 | | |
| 422 | | $this->spec($fooStatus1->userId)->should->be($fooUser->id); |
| 423 | | $this->spec($fooStatus1->userName)->should->be($fooUser->userName); |
| 424 | | $this->spec($fooStatus1->comment)->should->be('foo1'); |
| 425 | | } |
| 426 | | |
| 427 | | public function itプライベートユーザの発言を非フレンドが取得しようとすると例外発生() |
| 428 | | { |
| 429 | | $this->_createUserRecord($this->_foo); |
| 430 | | $this->_createUserRecord($this->_bar); |
| 431 | | |
| 432 | | $mapper = Piece_ORM::getMapper('Users'); |
| 433 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 434 | | $barUser = $mapper->findByUserName($this->_bar->userName); |
| 435 | | |
| 436 | | $barUser->privateFlag = 1; |
| 437 | | $mapper->update($barUser); |
| 438 | | |
| 439 | | $this->_createFollowerRecord($fooUser->id, $barUser->id); |
| 440 | | |
| 441 | | $this->_createStatusRecord($barUser->id, null, 'bar1'); |
| 442 | | |
| 443 | | try { |
| 444 | | $barStatusForFoo = new Phwittr_Status($barUser->userName, $fooUser->id); |
| 445 | | } catch (Phwittr_Status_Exception $e) { |
| 446 | | $this->fail(); |
| 447 | | } |
| 448 | | |
| 449 | | try { |
| 450 | | $barStatusForGuest = new Phwittr_Status($barUser->userName); |
| 451 | | } catch (Phwittr_Status_Exception $e) { |
| 452 | | if ($e->getCode() === PHWITTR_STATUS_EXCEPTION_FORBIDDEN) { |
| 453 | | return; |
| 454 | | } |
| 455 | | } |
| 456 | | |
| 457 | | $this->fail(); |
| 458 | | } |
| 459 | | |
| 460 | | public function it存在しないユーザのステータスは参照できない() |
| 461 | | { |
| 462 | | try { |
| 463 | | $status = new Phwittr_Status('example', 1); |
| 464 | | } catch (Phwittr_Status_Exception $e) { |
| 465 | | if ($e->getCode() === PHWITTR_STATUS_EXCEPTION_NOT_FOUND) { |
| 466 | | return; |
| 467 | | } |
| 468 | | } |
| 469 | | |
| 470 | | $this->fail(); |
| 471 | | } |
| 472 | | |
| 473 | | public function itゲストのステータスなどない() |
| 474 | | { |
| 475 | | try { |
| 476 | | $status = new Phwittr_Status(''); |
| 477 | | } catch (Phwittr_Exception $e) { |
| 478 | | return; |
| 479 | | } |
| 480 | | |
| 481 | | $this->fail(); |
| 482 | | } |
| 483 | | |
| 484 | | public function it表示される発言リストは、通常は最新20件() |
| 485 | | { |
| 486 | | $this->_createUserRecord($this->_foo); |
| 487 | | |
| 488 | | $mapper = Piece_ORM::getMapper('Users'); |
| 489 | | $fooUser = $mapper->findByUserName($this->_foo->userName); |
| 490 | | |
| 491 | | for ($i = 0; $i < 100; ++$i) { |
| 492 | | $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); |
| 493 | | } |
| 494 | | |
| 495 | | $status = new Phwittr_Status($fooUser->userName, $fooUser->id); |
| 496 | | $userStatuses = $status->listByFollowers(); |
| 497 | | |
| 498 | | $this->spec(count($userStatuses))->should->be(20); |
| 499 | | for ($i = 0; $i < 20; ++$i) { |
| 500 | | $number = 100 - $i; |
| 501 | | $this->spec($userStatuses[$i]->comment)->should->be("foo$number"); |
| | 98 | $this->spec($statusList[$i]->statusId)->should->be(101 - $i); |
| | 99 | $this->spec($statusList[$i]->comment)->should->be("foo{$number}"); |
| | 100 | $this->spec($statusList[$i]->userId)->should->be(1); |
| | 101 | $this->spec($statusList[$i]->userName)->should->be('foo'); |
| | 102 | $this->spec(preg_match('/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $statusList[$i]->createdAt))->should->be(1); |
| | 103 | $this->spec($statusList[$i]->image)->should->be('foo.jpg'); |