Make WordPress Core

Changeset 10 in tests


Ignore:
Timestamp:
09/20/2007 01:23:35 AM (17 years ago)
Author:
tellyworth
Message:

more capabilities tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user_capabilities.php

    r4 r10  
    4242
    4343    // test the default roles
     44
    4445    function test_user_administrator() {
    4546        $id = $this->_make_user('administrator');
     
    130131    }
    131132
     133    // a role that doesn't exist
     134    function test_bogus_role() {
     135        $id = $this->_make_user(rand_str());
     136        $user = new WP_User($id);
    132137
     138        // user has no role and no capabilities
     139        $this->assertEquals(array(), $user->roles);
     140        $this->assertFalse($user->has_cap('level_0'));
     141    }
     142
     143    // a user with multiple roles
     144    function test_user_subscriber_contributor() {
     145        $id = $this->_make_user('subscriber');
     146        $user = new WP_User($id);
     147        $user->add_role('contributor');
     148       
     149        // nuke and re-fetch the object to make sure it was stored
     150        $user = NULL;
     151        $user = new WP_User($id);
     152
     153        // user should have two roles now
     154        $this->assertEquals(array('subscriber', 'contributor'), $user->roles);
     155
     156        // with contributor capabilities
     157        $this->assertTrue($user->has_cap('edit_posts'));
     158        $this->assertTrue($user->has_cap('read'));
     159        $this->assertTrue($user->has_cap('level_1'));
     160        $this->assertTrue($user->has_cap('level_0'));
     161
     162        // but not these
     163        $this->assertFalse($user->has_cap('upload_files'));
     164        $this->assertFalse($user->has_cap('edit_published_posts'));
     165        $this->assertFalse($user->has_cap('level_2'));
     166    }
    133167}
    134168
Note: See TracChangeset for help on using the changeset viewer.