WordPress.org

Make WordPress Core

Changeset 510 in tests


Ignore:
Timestamp:
02/01/2012 11:07:35 PM (6 years ago)
Author:
convissor
Message:

Make sure we have a user object before trying to do anything with it, avoiding misdirection in later assertions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user_capabilities.php

    r407 r510  
    4747        $id = $this->_make_user('administrator');
    4848        $user = new WP_User($id);
     49        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    4950
    5051        // make sure the role name is correct
     
    6162        $id = $this->_make_user('editor');
    6263        $user = new WP_User($id);
     64        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    6365
    6466        // make sure the role name is correct
     
    8082        $id = $this->_make_user('author');
    8183        $user = new WP_User($id);
     84        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    8285
    8386        // make sure the role name is correct
     
    99102        $id = $this->_make_user('contributor');
    100103        $user = new WP_User($id);
     104        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    101105
    102106        // make sure the role name is correct
     
    118122        $id = $this->_make_user('subscriber');
    119123        $user = new WP_User($id);
     124        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    120125
    121126        // make sure the role name is correct
     
    137142        $id = $this->_make_user(rand_str());
    138143        $user = new WP_User($id);
     144        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    139145
    140146        // user has no role and no capabilities
     
    148154        $id = $this->_make_user('subscriber');
    149155        $user = new WP_User($id);
     156        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    150157        $user->add_role('contributor');
    151158
     
    153160        $user = NULL;
    154161        $user = new WP_User($id);
     162        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    155163
    156164        // user should have two roles now
     
    181189
    182190        $user = new WP_User($id);
     191        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    183192
    184193        $this->assertEquals(array($role_name), $user->roles);
     
    209218
    210219        $user = new WP_User($id);
     220        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    211221
    212222        $this->assertEquals(array($role_name), $user->roles);
     
    249259
    250260        $user = new WP_User($id);
     261        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    251262        $this->assertEquals(array($role_name), $user->roles);
    252263
     
    286297
    287298        $user = new WP_User($id);
     299        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    288300        $this->assertEquals(array($role_name), $user->roles);
    289301
     
    312324        // user 1 has an extra capability
    313325        $user_1 = new WP_User($id_1);
     326        $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1");
    314327        $user_1->add_cap('publish_posts');
    315328
    316329        // re-fetch both users from the db
    317330        $user_1 = new WP_User($id_1);
     331        $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1");
    318332        $user_2 = new WP_User($id_2);
     333        $this->assertInstanceOf('WP_User', $user_2, "Problem getting user $id_2");
    319334
    320335        // make sure they're both still contributors
     
    346361        // user 1 has an extra capability
    347362        $user_1 = new WP_User($id_1);
     363        $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1");
    348364        $user_1->add_cap('publish_posts');
    349365
     
    353369        // re-fetch both users from the db
    354370        $user_1 = new WP_User($id_1);
     371        $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id_1");
    355372        $user_2 = new WP_User($id_2);
     373        $this->assertInstanceOf('WP_User', $user_2, "Problem getting user $id_2");
    356374
    357375        // make sure they're both still contributors
     
    371389        $id = $this->_make_user('author');
    372390        $user = new WP_User($id);
     391        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    373392
    374393        // author = user level 2
     
    393412        $id = $this->_make_user('author');
    394413        $user = new WP_User($id);
     414        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    395415
    396416        // add some extra capabilities
     
    400420        // re-fetch
    401421        $user = new WP_User($id);
     422        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    402423
    403424        $this->assertTrue($user->has_cap('make_coffee'));
     
    409430        // re-fetch
    410431        $user = new WP_User($id);
     432        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    411433
    412434        // capabilities for the author role should be gone
     
    435457        // the author of the post
    436458        $author = new WP_User($this->author->ID);
     459        $this->assertInstanceOf('WP_User', $author, "Problem getting user " . $this->author->ID);
    437460        $author->set_role('author');
    438461
     
    494517        // the author of the page
    495518        $author = new WP_User($this->author->ID);
     519        $this->assertInstanceOf('WP_User', $author, "Problem getting user " . $this->author->ID);
    496520        $author->set_role('author');
    497521
     
    527551        $id = $this->_make_user('author');
    528552        $user = new WP_User($id);
     553        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    529554
    530555        global $wpdb;
     
    535560
    536561        $user = new WP_User($id);
     562        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id");
    537563
    538564        // check a few of the main capabilities
     
    568594        // regular users
    569595        $user = new WP_User($id[0]);
     596        $this->assertInstanceOf('WP_User', $user, "Problem getting user $id[0]");
    570597        update_usermeta($id[0], $user->cap_key, array('administrator' => true));
    571598        update_usermeta($id[1], $user->cap_key, array('editor' => true));
     
    585612        // test each user's role and capabilities, and make sure the usermeta data is what we expect
    586613        $user_0 = new WP_User($id[0]);
     614        $this->assertInstanceOf('WP_User', $user_0, "Problem getting user $id[0]");
    587615        $this->assertEquals(array('administrator'), $user_0->roles);
    588616        $this->assertTrue($user_0->has_cap('switch_themes'));
     
    594622
    595623        $user_1 = new WP_User($id[1]);
     624        $this->assertInstanceOf('WP_User', $user_1, "Problem getting user $id[1]");
    596625        $this->assertEquals(array('editor'), $user_1->roles);
    597626        $this->assertTrue($user_1->has_cap('moderate_comments'));
     
    606635
    607636        $user_2 = new WP_User($id[2]);
     637        $this->assertInstanceOf('WP_User', $user_2, "Problem getting user $id[2]");
    608638        $this->assertEquals(array('subscriber'), $user_2->roles);
    609639        $this->assertTrue($user_2->has_cap('read'));
     
    617647        // user 3 has two roles
    618648        $user_3 = new WP_User($id[3]);
     649        $this->assertInstanceOf('WP_User', $user_3, "Problem getting user $id[3]");
    619650        $this->assertEquals(array('contributor', 'author'), $user_3->roles);
    620651        $this->assertTrue($user_3->has_cap('edit_posts'));
     
    630661        // user 4 is a subscriber with some extra per-user caps
    631662        $user_4 = new WP_User($id[4]);
     663        $this->assertInstanceOf('WP_User', $user_4, "Problem getting user $id[4]");
    632664        $this->assertEquals(array('subscriber'), $user_4->roles);
    633665        $this->assertTrue($user_4->has_cap('read'));
Note: See TracChangeset for help on using the changeset viewer.