WordPress.org

Make WordPress Core

Changeset 619 in tests


Ignore:
Timestamp:
04/06/2012 07:28:45 PM (9 years ago)
Author:
markjaquith
Message:

Use the WP_User::exists() method to check for a valid WP_User object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user_capabilities.php

    r611 r619  
    4848        $id = $this->_make_user('administrator');
    4949        $user = new WP_User($id);
    50         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     50        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     65        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     85        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     105        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     125        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     145        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     157        $this->assertTrue($user->exists(), "Problem getting user $id");
    158158        $user->add_role('contributor');
    159159
     
    161161        $user = NULL;
    162162        $user = new WP_User($id);
    163         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     163        $this->assertTrue($user->exists(), "Problem getting user $id");
    164164
    165165        // user should have two roles now
     
    190190
    191191        $user = new WP_User($id);
    192         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     192        $this->assertTrue($user->exists(), "Problem getting user $id");
    193193
    194194        $this->assertEquals(array($role_name), $user->roles);
     
    219219
    220220        $user = new WP_User($id);
    221         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     221        $this->assertTrue($user->exists(), "Problem getting user $id");
    222222
    223223        $this->assertEquals(array($role_name), $user->roles);
     
    260260
    261261        $user = new WP_User($id);
    262         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     262        $this->assertTrue($user->exists(), "Problem getting user $id");
    263263        $this->assertEquals(array($role_name), $user->roles);
    264264
     
    298298
    299299        $user = new WP_User($id);
    300         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     300        $this->assertTrue($user->exists(), "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->assertInternalType('object', $user_1->data, "Problem getting user $id_1");
     327        $this->assertTrue($user_1->exists(), "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->assertInternalType('object', $user_1->data, "Problem getting user $id_1");
     332        $this->assertTrue($user_1->exists(), "Problem getting user $id_1");
    333333        $user_2 = new WP_User($id_2);
    334         $this->assertInternalType('object', $user_2->data, "Problem getting user $id_2");
     334        $this->assertTrue($user_2->exists(), "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->assertInternalType('object', $user_1->data, "Problem getting user $id_1");
     364        $this->assertTrue($user_1->exists(), "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->assertInternalType('object', $user_1->data, "Problem getting user $id_1");
     372        $this->assertTrue($user_1->exists(), "Problem getting user $id_1");
    373373        $user_2 = new WP_User($id_2);
    374         $this->assertInternalType('object', $user_2->data, "Problem getting user $id_2");
     374        $this->assertTrue($user_2->exists(), "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->assertInternalType('object', $user->data, "Problem getting user $id");
     392        $this->assertTrue($user->exists(), "Problem getting user $id");
    393393
    394394        // author = user level 2
     
    413413        $id = $this->_make_user('author');
    414414        $user = new WP_User($id);
    415         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     415        $this->assertTrue($user->exists(), "Problem getting user $id");
    416416
    417417        // add some extra capabilities
     
    421421        // re-fetch
    422422        $user = new WP_User($id);
    423         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     423        $this->assertTrue($user->exists(), "Problem getting user $id");
    424424
    425425        $this->assertTrue($user->has_cap('make_coffee'));
     
    431431        // re-fetch
    432432        $user = new WP_User($id);
    433         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     433        $this->assertTrue($user->exists(), "Problem getting user $id");
    434434
    435435        // capabilities for the author role should be gone
     
    460460
    461461        // the author of the post
    462         $this->assertInternalType('object', $author->data, "Problem getting user $author->ID");
     462        $this->assertTrue($author->exists(), "Problem getting user $author->ID");
    463463
    464464        // add some other users
     
    521521
    522522        // the author of the page
    523         $this->assertInternalType('object', $author->data, "Problem getting user " . $author->ID);
     523        $this->assertTrue($author->exists(), "Problem getting user " . $author->ID);
    524524
    525525        // add some other users
     
    554554        $id = $this->_make_user('author');
    555555        $user = new WP_User($id);
    556         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     556        $this->assertTrue($user->exists(), "Problem getting user $id");
    557557
    558558        global $wpdb;
     
    563563
    564564        $user = new WP_User($id);
    565         $this->assertInternalType('object', $user->data, "Problem getting user $id");
     565        $this->assertTrue($user->exists(), "Problem getting user $id");
    566566
    567567        // check a few of the main capabilities
     
    597597        // regular users
    598598        $user = new WP_User($id[0]);
    599         $this->assertInternalType('object', $user->data, "Problem getting user $id[0]");
     599        $this->assertTrue($user->exists(), "Problem getting user $id[0]");
    600600        update_usermeta($id[0], $user->cap_key, array('administrator' => true));
    601601        update_usermeta($id[1], $user->cap_key, array('editor' => true));
     
    615615        // test each user's role and capabilities, and make sure the usermeta data is what we expect
    616616        $user_0 = new WP_User($id[0]);
    617         $this->assertInternalType('object', $user_0->data, "Problem getting user $id[0]");
     617        $this->assertTrue($user_0->exists(), "Problem getting user $id[0]");
    618618        $this->assertEquals(array('administrator'), $user_0->roles);
    619619        $this->assertTrue($user_0->has_cap('switch_themes'));
     
    625625
    626626        $user_1 = new WP_User($id[1]);
    627         $this->assertInternalType('object', $user_1->data, "Problem getting user $id[1]");
     627        $this->assertTrue($user_1->exists(), "Problem getting user $id[1]");
    628628        $this->assertEquals(array('editor'), $user_1->roles);
    629629        $this->assertTrue($user_1->has_cap('moderate_comments'));
     
    638638
    639639        $user_2 = new WP_User($id[2]);
    640         $this->assertInternalType('object', $user_2->data, "Problem getting user $id[2]");
     640        $this->assertTrue($user_2->exists(), "Problem getting user $id[2]");
    641641        $this->assertEquals(array('subscriber'), $user_2->roles);
    642642        $this->assertTrue($user_2->has_cap('read'));
     
    650650        // user 3 has two roles
    651651        $user_3 = new WP_User($id[3]);
    652         $this->assertInternalType('object', $user_3->data, "Problem getting user $id[3]");
     652        $this->assertTrue($user_3->exists(), "Problem getting user $id[3]");
    653653        $this->assertEquals(array('contributor', 'author'), $user_3->roles);
    654654        $this->assertTrue($user_3->has_cap('edit_posts'));
     
    664664        // user 4 is a subscriber with some extra per-user caps
    665665        $user_4 = new WP_User($id[4]);
    666         $this->assertInternalType('object', $user_4->data, "Problem getting user $id[4]");
     666        $this->assertTrue($user_4->exists(), "Problem getting user $id[4]");
    667667        $this->assertEquals(array('subscriber'), $user_4->roles);
    668668        $this->assertTrue($user_4->has_cap('read'));
Note: See TracChangeset for help on using the changeset viewer.