Changeset 14839

Show
Ignore:
Timestamp:
06/29/08 18:05:08 (5 years ago)
Author:
kumatch
Message:

Reviewed.

Files:
1 modified

Legend:

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

    r14838 r14839  
    1111 */ 
    1212 
    13 require_once dirname(__FILE__). '/SpecCommon.php'; 
    14 require_once 'Phwittr/Config.php'; 
    15 require_once 'Phwittr/User.php'; 
     13require_once dirname(__FILE__). '/../SpecCommon.php'; 
     14require_once 'Phwittr/Self.php'; 
    1615 
    1716// {{{ Describeフォロー 
     
    5251     */ 
    5352 
    54     public function it他のユーザをフレンドに追加できる() 
     53    public function beforeAll() 
    5554    { 
     55        parent::beforeAll(); 
     56 
    5657        $this->_createUserRecord($this->_foo); 
    5758        $this->_createUserRecord($this->_bar); 
     59        $this->_createUserRecord($this->_baz); 
    5860 
    5961        $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); 
    6265 
    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); 
    6572 
    6673        $mapper = Piece_ORM::getMapper('Followers'); 
    67         $followers = $mapper->findAllByUserId($fooUser->id); 
     74        $followers = $mapper->findAllByUserId($this->_foo->id); 
    6875 
    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); 
    7378    } 
    7479 
    75     public function itフレンドを削除できる() 
     80    public function itフレンドにいるユーザのidを指定して削除すると、フレンドからいなくなる() 
    7681    { 
    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); 
    8883 
    8984        $mapper = Piece_ORM::getMapper('Followers'); 
    90         $followers = $mapper->findAllByUserId($fooUser->id); 
    91  
     85        $followers = $mapper->findAllByUserId($this->_foo->id); 
    9286        $this->spec(count($followers))->should->be(0); 
    9387    } 
    9488 
    95     public function it自分をフレンドに追加しようとすると例外発生() 
     89    public function it自分をフォローしようとすると例外が発生する() 
    9690    { 
    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  
    10491        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) { 
    10794            return; 
    10895        } 
     
    11198    } 
    11299 
    113     public function it既にフレンドのユーザを再び追加しようとすると例外発生() 
     100    public function it既にフレンドのユーザをフォローしようとすると例外が発生する() 
    114101    { 
    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); 
    124103 
    125104        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) { 
    128107            return; 
    129108        } 
     
    132111    } 
    133112 
    134     public function it存在しないユーザを追加しようとすると例外発生() 
     113    public function it存在しないユーザをフォローしようとすると例外が発生する() 
    135114    { 
    136115        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) { 
    145118            return; 
    146119        } 
     
    149122    } 
    150123 
    151     public function it自分をフレンドから削除しようとすると例外発生() 
     124    public function it自分をフレンドから削除しようとすると例外が発生する() 
    152125    { 
    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  
    160126        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) { 
    163129            return; 
    164130        } 
     
    167133    } 
    168134 
    169     public function it関係ないユーザをフレンドから削除しようとすると例外発生() 
     135    public function it関係ないユーザをフレンドから削除しようとすると例外が発生する() 
    170136    { 
    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  
    180137        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) { 
    183140            return; 
    184141        } 
     
    187144    } 
    188145 
    189     public function it存在しないユーザをフレンドから削除しようとすると例外発生() 
     146    public function it存在しないユーザをフレンドから削除しようとすると例外が発生する() 
    190147    { 
    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  
    198148        try { 
    199             $user->removeFriend(100); 
    200         } catch (Phwittr_User_Exception $e) { 
     149            $this->_self->removeFriend(100); 
     150        } catch (Phwittr_Self_Exception $e) { 
    201151            return; 
    202152        } 
     
    207157    public function it対象ユーザが既にフレンド済みならば、フレンド確認結果は真() 
    208158    { 
    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(); 
    222160    } 
    223161 
    224162    public function it対象ユーザがフレンドでなければ、フレンド確認結果は偽() 
    225163    { 
    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(); 
    427165    } 
    428166