WordPress.org

Make WordPress Core

Changeset 609 in tests


Ignore:
Timestamp:
04/05/12 19:50:33 (2 years ago)
Author:
markjaquith
Message:

"new WP_User()" will always produce a WP_User instance, so let's actually test the object that was returned. We should consider an WP_User::exists() for 3.5.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user_capabilities.php

    r608 r609  
    4848        $id = $this->_make_user('administrator'); 
    4949        $user = new WP_User($id); 
    50         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     50        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    5151 
    5252        // make sure the role name is correct 
     
    6363        $id = $this->_make_user('editor'); 
    6464        $user = new WP_User($id); 
    65         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     65        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    6666 
    6767        // make sure the role name is correct 
     
    8383        $id = $this->_make_user('author'); 
    8484        $user = new WP_User($id); 
    85         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     85        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    8686 
    8787        // make sure the role name is correct 
     
    103103        $id = $this->_make_user('contributor'); 
    104104        $user = new WP_User($id); 
    105         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     105        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    106106 
    107107        // make sure the role name is correct 
     
    123123        $id = $this->_make_user('subscriber'); 
    124124        $user = new WP_User($id); 
    125         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     125        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    126126 
    127127        // make sure the role name is correct 
     
    143143        $id = $this->_make_user(rand_str()); 
    144144        $user = new WP_User($id); 
    145         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     145        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    146146 
    147147        // user has no role and no capabilities 
     
    155155        $id = $this->_make_user('subscriber'); 
    156156        $user = new WP_User($id); 
    157         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     157        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    158158        $user->add_role('contributor'); 
    159159 
     
    161161        $user = NULL; 
    162162        $user = new WP_User($id); 
    163         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     163        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    164164 
    165165        // user should have two roles now 
     
    190190 
    191191        $user = new WP_User($id); 
    192         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     192        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    193193 
    194194        $this->assertEquals(array($role_name), $user->roles); 
     
    219219 
    220220        $user = new WP_User($id); 
    221         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     221        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    222222 
    223223        $this->assertEquals(array($role_name), $user->roles); 
     
    260260 
    261261        $user = new WP_User($id); 
    262         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     262        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    263263        $this->assertEquals(array($role_name), $user->roles); 
    264264 
     
    298298 
    299299        $user = new WP_User($id); 
    300         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     300        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    301301        $this->assertEquals(array($role_name), $user->roles); 
    302302 
     
    325325        // user 1 has an extra capability 
    326326        $user_1 = new WP_User($id_1); 
    327         $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1"); 
     327        $this->assertInternalType('object', $user_1->data, "Problem getting user $id_1"); 
    328328        $user_1->add_cap('publish_posts'); 
    329329 
    330330        // re-fetch both users from the db 
    331331        $user_1 = new WP_User($id_1); 
    332         $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1"); 
     332        $this->assertInternalType('object', $user_1->data, "Problem getting user $id_1"); 
    333333        $user_2 = new WP_User($id_2); 
    334         $this->assertInstanceOf('WP_User', $user_2, "Problem getting user $id_2"); 
     334        $this->assertInternalType('object', $user_2->data, "Problem getting user $id_2"); 
    335335 
    336336        // make sure they're both still contributors 
     
    362362        // user 1 has an extra capability 
    363363        $user_1 = new WP_User($id_1); 
    364         $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1"); 
     364        $this->assertInternalType('object', $user_1->data, "Problem getting user $id_1"); 
    365365        $user_1->add_cap('publish_posts'); 
    366366 
     
    370370        // re-fetch both users from the db 
    371371        $user_1 = new WP_User($id_1); 
    372         $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1"); 
     372        $this->assertInternalType('object', $user_1->data, "Problem getting user $id_1"); 
    373373        $user_2 = new WP_User($id_2); 
    374         $this->assertInstanceOf('WP_User', $user_2, "Problem getting user $id_2"); 
     374        $this->assertInternalType('object', $user_2->data, "Problem getting user $id_2"); 
    375375 
    376376        // make sure they're both still contributors 
     
    390390        $id = $this->_make_user('author'); 
    391391        $user = new WP_User($id); 
    392         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     392        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    393393 
    394394        // author = user level 2 
     
    413413        $id = $this->_make_user('author'); 
    414414        $user = new WP_User($id); 
    415         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     415        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    416416 
    417417        // add some extra capabilities 
     
    421421        // re-fetch 
    422422        $user = new WP_User($id); 
    423         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     423        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    424424 
    425425        $this->assertTrue($user->has_cap('make_coffee')); 
     
    431431        // re-fetch 
    432432        $user = new WP_User($id); 
    433         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     433        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    434434 
    435435        // capabilities for the author role should be gone 
     
    460460 
    461461        // the author of the post 
    462         $this->assertThat($author->data, $this->isType('object')); 
     462        $this->assertInternalType('object', $author->data, "Problem getting user $author->ID"); 
    463463 
    464464        // add some other users 
     
    519519        // the author of the page 
    520520        $author = new WP_User($this->author->ID); 
    521         $this->assertInstanceOf('WP_User', $author, "Problem getting user " . $this->author->ID); 
     521        $this->assertInternalType('object', $author->data, "Problem getting user " . $this->author->ID); 
    522522        $author->set_role('author'); 
    523523 
     
    553553        $id = $this->_make_user('author'); 
    554554        $user = new WP_User($id); 
    555         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     555        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    556556 
    557557        global $wpdb; 
     
    562562 
    563563        $user = new WP_User($id); 
    564         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id"); 
     564        $this->assertInternalType('object', $user->data, "Problem getting user $id"); 
    565565 
    566566        // check a few of the main capabilities 
     
    596596        // regular users 
    597597        $user = new WP_User($id[0]); 
    598         $this->assertInstanceOf('WP_User', $user, "Problem getting user $id[0]"); 
     598        $this->assertInternalType('object', $user->data, "Problem getting user $id[0]"); 
    599599        update_usermeta($id[0], $user->cap_key, array('administrator' => true)); 
    600600        update_usermeta($id[1], $user->cap_key, array('editor' => true)); 
     
    614614        // test each user's role and capabilities, and make sure the usermeta data is what we expect 
    615615        $user_0 = new WP_User($id[0]); 
    616         $this->assertInstanceOf('WP_User', $user_0, "Problem getting user $id[0]"); 
     616        $this->assertInternalType('object', $user_0->data, "Problem getting user $id[0]"); 
    617617        $this->assertEquals(array('administrator'), $user_0->roles); 
    618618        $this->assertTrue($user_0->has_cap('switch_themes')); 
     
    624624 
    625625        $user_1 = new WP_User($id[1]); 
    626         $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id[1]"); 
     626        $this->assertInternalType('object', $user_1->data, "Problem getting user $id[1]"); 
    627627        $this->assertEquals(array('editor'), $user_1->roles); 
    628628        $this->assertTrue($user_1->has_cap('moderate_comments')); 
     
    637637 
    638638        $user_2 = new WP_User($id[2]); 
    639         $this->assertInstanceOf('WP_User', $user_2, "Problem getting user $id[2]"); 
     639        $this->assertInternalType('object', $user_2->data, "Problem getting user $id[2]"); 
    640640        $this->assertEquals(array('subscriber'), $user_2->roles); 
    641641        $this->assertTrue($user_2->has_cap('read')); 
     
    649649        // user 3 has two roles 
    650650        $user_3 = new WP_User($id[3]); 
    651         $this->assertInstanceOf('WP_User', $user_3, "Problem getting user $id[3]"); 
     651        $this->assertInternalType('object', $user_3->data, "Problem getting user $id[3]"); 
    652652        $this->assertEquals(array('contributor', 'author'), $user_3->roles); 
    653653        $this->assertTrue($user_3->has_cap('edit_posts')); 
     
    663663        // user 4 is a subscriber with some extra per-user caps 
    664664        $user_4 = new WP_User($id[4]); 
    665         $this->assertInstanceOf('WP_User', $user_4, "Problem getting user $id[4]"); 
     665        $this->assertInternalType('object', $user_4->data, "Problem getting user $id[4]"); 
    666666        $this->assertEquals(array('subscriber'), $user_4->roles); 
    667667        $this->assertTrue($user_4->has_cap('read')); 
Note: See TracChangeset for help on using the changeset viewer.