Changeset 14786 for events/phpframework

Show
Ignore:
Timestamp:
06/28/08 22:59:00 (5 years ago)
Author:
kumatch
Message:

Reviewed.

Files:
1 modified

Legend:

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

    r14785 r14786  
    1111 */ 
    1212 
    13 require_once dirname(__FILE__). '/SpecCommon.php'; 
    14 require_once 'Phwittr/Config.php'; 
    15 require_once 'Phwittr/Status.php'; 
     13require_once dirname(__FILE__). '/../SpecCommon.php'; 
     14require_once 'Phwittr/Self.php'; 
    1615 
    17 // {{{ Describeログインユーザ向けに提供される機能 
     16// {{{ Describeログインユーザ向けのホーム 
    1817 
    1918/** 
    20  * StatusFindSpec - ログインユーザ向けに提供される機能に関するSpec 
     19 * StatusFindSpec - ログインユーザ向けのホーム 
    2120 * 
    2221 * @package    Phwittr_PieceFramework 
     
    2524 * @since      Class available since Release 0.1.0 
    2625 */ 
    27 class Describeログインユーザ向けに提供される機能 extends SpecCommon 
     26class Describeログインユーザ向けのホーム extends SpecCommon 
    2827{ 
    2928 
     
    5251     */ 
    5352 
    54     public function it自身のホームはFollowersと自身の発言リスト() 
     53    public function beforeAll() 
    5554    { 
     55        parent::beforeAll(); 
     56 
    5657        $this->_createUserRecord($this->_foo); 
    5758        $this->_createUserRecord($this->_bar); 
     
    5960 
    6061        $mapper = Piece_ORM::getMapper('Users'); 
    61         $fooUser = $mapper->findByUserName($this->_foo->userName); 
    62         $barUser = $mapper->findByUserName($this->_bar->userName); 
    63         $bazUser = $mapper->findByUserName($this->_baz->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); 
    6465 
    65         $this->_createFollowerRecord($fooUser->id, $barUser->id); 
    66         $this->_createFollowerRecord($barUser->id, $fooUser->id); 
    67         $this->_createFollowerRecord($barUser->id, $bazUser->id); 
     66        for ($i = 0; $i < 100; ++$i) { 
     67            $this->_createStatusRecord($this->_foo->id, $i + 2, 
     68                                       sprintf('foo%d', $i), $i 
     69                                       ); 
     70        } 
     71        $this->_createStatusRecord($this->_bar->id, null, 'bar1', 1000); 
     72        $this->_createStatusRecord($this->_baz->id, null, 'baz1', 1001); 
    6873 
    69         $this->_createStatusRecord($fooUser->id, null, 'foo1'); 
    70         $this->_createStatusRecord($fooUser->id, null, 'foo2'); 
    71         $this->_createStatusRecord($fooUser->id, null, 'foo3'); 
    72         $this->_createStatusRecord($fooUser->id, null, 'foo4'); 
    73         $this->_createStatusRecord($barUser->id, null, 'bar1'); 
    74         $this->_createStatusRecord($barUser->id, null, 'bar2'); 
    75         $this->_createStatusRecord($barUser->id, null, 'bar3'); 
    76         $this->_createStatusRecord($barUser->id, null, 'bar4'); 
    77         $this->_createStatusRecord($bazUser->id, null, 'baz1'); 
    78         $this->_createStatusRecord($bazUser->id, null, 'baz2'); 
    79         $this->_createStatusRecord($bazUser->id, null, 'baz3'); 
    80         $this->_createStatusRecord($bazUser->id, null, 'baz4'); 
     74        $this->_createFollowerRecord($this->_foo->id, $this->_bar->id); 
     75        $this->_createFollowerRecord($this->_bar->id, $this->_foo->id); 
     76        $this->_createFollowerRecord($this->_baz->id, $this->_foo->id); 
    8177 
    82         $status = new Phwittr_Status($fooUser->userName, $fooUser->id); 
    83         $userStatuses = $status->listByFollowers(); 
    84         $this->spec(count($userStatuses))->should->be(8); 
    85  
    86         $fooCount = 0; 
    87         $barCount = 0; 
    88         $bazCount = 0; 
    89         foreach ($userStatuses as $userStatus) { 
    90             if ($userStatus->userId == $fooUser->id) { 
    91                 ++$fooCount; 
    92             } elseif ($userStatus->userId == $barUser->id) { 
    93                 ++$barCount; 
    94             } elseif ($userStatus->userId == $bazUser->id) { 
    95                 ++$bazCount; 
    96             } 
    97         } 
    98  
    99         $this->spec($fooCount)->should->be(4); 
    100         $this->spec($barCount)->should->be(4); 
    101         $this->spec($bazCount)->should->be(0); 
     78        $this->_self = new Phwittr_Self($this->_foo->id); 
    10279    } 
    10380 
    104     public function itRepliesは自身への返信リスト() 
     81    public function itリストを取得するとFollowersと自身発言の最新20件で、対象発言が101件ある状態ならば次ページがあることになる() 
    10582    { 
    106         $this->_createUserRecord($this->_foo); 
    107         $this->_createUserRecord($this->_bar); 
    108         $this->_createUserRecord($this->_baz); 
     83        $statusList = $this->_self->listByFollowers(); 
    10984 
    110         $mapper = Piece_ORM::getMapper('Users'); 
    111         $fooUser = $mapper->findByUserName($this->_foo->userName); 
    112         $barUser = $mapper->findByUserName($this->_bar->userName); 
    113         $bazUser = $mapper->findByUserName($this->_baz->userName); 
     85        $this->spec(count($statusList))->should->be(20); 
     86        $this->spec($this->_self->hasNextPage())->should->beTrue(); 
    11487 
    115         $this->_createStatusRecord($fooUser->id, $fooUser->id, 'foo1'); 
    116         $this->_createStatusRecord($fooUser->id, null, 'foo2'); 
    117         $this->_createStatusRecord($fooUser->id, null, 'foo3'); 
    118         $this->_createStatusRecord($fooUser->id, null, 'foo4'); 
    119         $this->_createStatusRecord($barUser->id, $fooUser->id, 'bar1'); 
    120         $this->_createStatusRecord($barUser->id, $fooUser->id, 'bar2'); 
    121         $this->_createStatusRecord($barUser->id, $fooUser->id, 'bar3'); 
    122         $this->_createStatusRecord($barUser->id, null, 'bar4'); 
    123         $this->_createStatusRecord($bazUser->id, $fooUser->id, 'baz1'); 
    124         $this->_createStatusRecord($bazUser->id, $fooUser->id, 'baz2'); 
    125         $this->_createStatusRecord($bazUser->id, null, 'baz3'); 
    126         $this->_createStatusRecord($bazUser->id, null, 'baz4'); 
     88        $this->spec($statusList[0]->statusId)->should->be(101); 
     89        $this->spec($statusList[0]->comment)->should->be('bar1'); 
     90        $this->spec($statusList[0]->userId)->should->be(2); 
     91        $this->spec($statusList[0]->userName)->should->be('bar'); 
     92        $this->spec(preg_match('/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $statusList[0]->createdAt))->should->be(1); 
     93        $this->spec($statusList[0]->image)->should->be('bar.jpg'); 
    12794 
    128         $status = new Phwittr_Status($fooUser->userName, $fooUser->id); 
    129         $userStatuses = $status->listReplies(); 
    130         $this->spec(count($userStatuses))->should->be(6); 
     95        for ($i = 1; $i < 20; ++$i) { 
     96            $number = 100 - $i; 
    13197 
    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'); 
    502104        } 
    503105    } 
    504106 
    505     public function it表示される発言リスト20件のページが指定できる() 
     107    public function it対象発言が101件あるホームリスト2ページ目を取得すると最新21〜40件目が得られ、かつ次ページがある() 
    506108    { 
    507         $this->_createUserRecord($this->_foo); 
     109        $page = 2; 
     110        $statusList = $this->_self->listByFollowers($page); 
    508111 
    509         $mapper = Piece_ORM::getMapper('Users'); 
    510         $fooUser = $mapper->findByUserName($this->_foo->userName); 
     112        $this->spec(count($statusList))->should->be(20); 
     113        $this->spec($this->_self->hasNextPage())->should->beTrue(); 
    511114 
    512         for ($i = 0; $i < 100; ++$i) { 
    513             $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); 
    514         } 
     115        for ($i = 0; $i < 20; ++$i) { 
     116            $number = 80 - $i; 
    515117 
    516         $status = new Phwittr_Status($fooUser->userName, $fooUser->id); 
    517         $userStatuses = $status->listByFollowers(3); 
    518  
    519         $this->spec(count($userStatuses))->should->be(20); 
    520         for ($i = 0; $i < 20; ++$i) { 
    521             $number = 100 - (20 * 2 + $i); 
    522             $this->spec($userStatuses[$i]->comment)->should->be("foo$number"); 
     118            $this->spec($statusList[$i]->statusId)->should->be(81 - $i); 
     119            $this->spec($statusList[$i]->comment)->should->be("foo{$number}"); 
     120            $this->spec($statusList[$i]->userId)->should->be(1); 
     121            $this->spec($statusList[$i]->userName)->should->be('foo'); 
     122            $this->spec(preg_match('/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $statusList[$i]->createdAt))->should->be(1); 
     123            $this->spec($statusList[$i]->image)->should->be('foo.jpg'); 
    523124        } 
    524125    } 
    525126 
    526     public function it発言リスト取得直後、さらに古いページがあるかどうかを知れる() 
     127    public function it対象発言が101件あるホームリスト6ページ目を取得すると101件目が得られ、次ページは存在しないことになる() 
    527128    { 
    528         $this->_createUserRecord($this->_foo); 
     129        $page = 6; 
     130        $statusList = $this->_self->listByFollowers($page); 
    529131 
    530         $mapper = Piece_ORM::getMapper('Users'); 
    531         $fooUser = $mapper->findByUserName($this->_foo->userName); 
     132        $this->spec(count($statusList))->should->be(1); 
     133        $this->spec($this->_self->hasNextPage())->should->beFalse(); 
    532134 
    533         for ($i = 0; $i < 100; ++$i) { 
    534             $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); 
    535         } 
    536  
    537         $status = new Phwittr_Status($fooUser->userName, $fooUser->id); 
    538         $userStatuses = $status->listByFollowers(); 
    539  
    540         $this->spec($status->hasOlderStatus())->should->beTrue(); 
     135        $this->spec($statusList[0]->statusId)->should->be(1); 
     136        $this->spec($statusList[0]->comment)->should->be('foo0'); 
     137        $this->spec($statusList[0]->userId)->should->be(1); 
     138        $this->spec($statusList[0]->userName)->should->be('foo'); 
     139        $this->spec(preg_match('/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $statusList[0]->createdAt))->should->be(1); 
     140        $this->spec($statusList[0]->image)->should->be('foo.jpg'); 
    541141    } 
    542142 
    543     public function it発言リストの最後のページを取得すれば、これ以上古いページはない() 
     143    public function it対象発言が101件あるホームリストに対してありえない100ページ目を取得しようとしても1ページ目を得ることになる() 
    544144    { 
    545         $this->_createUserRecord($this->_foo); 
     145        $page = 100; 
     146        $statusList = $this->_self->listByFollowers($page); 
    546147 
    547         $mapper = Piece_ORM::getMapper('Users'); 
    548         $fooUser = $mapper->findByUserName($this->_foo->userName); 
     148        $this->spec(count($statusList))->should->be(20); 
     149        $this->spec($this->_self->hasNextPage())->should->beTrue(); 
    549150 
    550         for ($i = 0; $i < 100; ++$i) { 
    551             $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); 
     151        $this->spec($statusList[0]->statusId)->should->be(101); 
     152        $this->spec($statusList[0]->comment)->should->be('bar1'); 
     153        $this->spec($statusList[0]->userId)->should->be(2); 
     154        $this->spec($statusList[0]->userName)->should->be('bar'); 
     155        $this->spec(preg_match('/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $statusList[0]->createdAt))->should->be(1); 
     156        $this->spec($statusList[0]->image)->should->be('bar.jpg'); 
     157 
     158        for ($i = 1; $i < 20; ++$i) { 
     159            $number = 100 - $i; 
     160 
     161            $this->spec($statusList[$i]->statusId)->should->be(101 - $i); 
     162            $this->spec($statusList[$i]->comment)->should->be("foo{$number}"); 
     163            $this->spec($statusList[$i]->userId)->should->be(1); 
     164            $this->spec($statusList[$i]->userName)->should->be('foo'); 
     165            $this->spec(preg_match('/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $statusList[$i]->createdAt))->should->be(1); 
     166            $this->spec($statusList[$i]->image)->should->be('foo.jpg'); 
    552167        } 
    553  
    554         $status = new Phwittr_Status($fooUser->userName, $fooUser->id); 
    555         $userStatuses = $status->listByFollowers(5); 
    556  
    557         $this->spec($status->hasOlderStatus())->should->beFalse(); 
    558     } 
    559  
    560     public function it発言リスト取得を行っていなければ、古いページがあるかどうかは知れずに例外が発生する() 
    561     { 
    562         $this->_createUserRecord($this->_foo); 
    563  
    564         $mapper = Piece_ORM::getMapper('Users'); 
    565         $fooUser = $mapper->findByUserName($this->_foo->userName); 
    566  
    567         for ($i = 0; $i < 100; ++$i) { 
    568             $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); 
    569         } 
    570  
    571         $status = new Phwittr_Status($fooUser->userName, $fooUser->id); 
    572  
    573         try { 
    574             $status->hasOlderStatus(); 
    575         } catch (Phwittr_Status_Exception $e) { 
    576             return; 
    577         } 
    578  
    579         $this->fail(); 
    580168    } 
    581169