WordPress.org

Make WordPress Core

Changeset 794 in tests


Ignore:
Timestamp:
06/30/12 19:38:48 (22 months ago)
Author:
nacin
Message:

Port test_user_capabilities.php. fixes #68.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-testcase/test_user_capabilities.php

    r675 r794  
    33// Test roles and capabilities via the WP_User class 
    44 
    5 class WPTestUserCapabilities extends _WPEmptyBlog { 
     5/** 
     6 * @group user 
     7 * @group capabilities 
     8 */ 
     9class WPTestUserCapabilities extends WP_UnitTestCase { 
    610    var $user_ids = array(); 
    711 
     
    913        parent::setUp(); 
    1014        // keep track of users we create 
    11         $this->user_ids = array(); 
    1215        $this->_flush_roles(); 
    1316 
    1417        $this->orig_users = get_users_of_blog(); 
    15     } 
    16  
    17     function tearDown() { 
    18         parent::tearDown(); 
    19         // delete any users that were created during tests 
    20         $this->_destroy_users(); 
    2118    } 
    2219 
     
    2623        unset($GLOBALS['wp_user_roles']); 
    2724        global $wp_roles; 
    28         $wp_roles->_init(); 
     25        if ( is_object( $wp_roles ) ) 
     26            $wp_roles->_init(); 
    2927    } 
    3028 
     
    4442 
    4543    function test_user_administrator() { 
    46         $id = $this->_make_user('administrator'); 
     44        $id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 
    4745        $user = new WP_User($id); 
    4846        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    5957 
    6058    function test_user_editor() { 
    61         $id = $this->_make_user('editor'); 
     59        $id = $this->factory->user->create( array( 'role' => 'editor' ) ); 
    6260        $user = new WP_User($id); 
    6361        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    7977 
    8078    function test_user_author() { 
    81         $id = $this->_make_user('author'); 
     79        $id = $this->factory->user->create( array( 'role' => 'author' ) ); 
    8280        $user = new WP_User($id); 
    8381        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    9997 
    10098    function test_user_contributor() { 
    101         $id = $this->_make_user('contributor'); 
     99        $id = $this->factory->user->create( array( 'role' => 'contributor' ) ); 
    102100        $user = new WP_User($id); 
    103101        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    119117 
    120118    function test_user_subscriber() { 
    121         $id = $this->_make_user('subscriber'); 
     119        $id = $this->factory->user->create( array( 'role' => 'subscriber' ) ); 
    122120        $user = new WP_User($id); 
    123121        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    139137    function test_bogus_role() { 
    140138        _disable_wp_die(); 
    141         $id = $this->_make_user(rand_str()); 
     139        $id = $this->factory->user->create( array( 'role' => rand_str() ) ); 
    142140        $user = new WP_User($id); 
    143141        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    151149    // a user with multiple roles 
    152150    function test_user_subscriber_contributor() { 
    153         $id = $this->_make_user('subscriber'); 
     151        $id = $this->factory->user->create( array( 'role' => 'subscriber' ) ); 
    154152        $user = new WP_User($id); 
    155153        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    185183        $this->assertTrue($wp_roles->is_role($role_name)); 
    186184 
    187         $id = $this->_make_user($role_name); 
     185        $id = $this->factory->user->create( array( 'role' => $role_name ) ); 
    188186 
    189187        $user = new WP_User($id); 
     
    214212        $this->assertTrue($wp_roles->is_role($role_name)); 
    215213 
    216         $id = $this->_make_user($role_name); 
     214        $id = $this->factory->user->create( array( 'role' => $role_name ) ); 
    217215 
    218216        $user = new WP_User($id); 
     
    251249 
    252250        // assign a user to that role 
    253         $id = $this->_make_user($role_name); 
     251        $id = $this->factory->user->create( array( 'role' => $role_name ) ); 
    254252 
    255253        // now add a cap to the role 
     
    289287 
    290288        // assign a user to that role 
    291         $id = $this->_make_user($role_name); 
     289        $id = $this->factory->user->create( array( 'role' => $role_name ) ); 
    292290 
    293291        // now remove a cap from the role 
     
    318316 
    319317        // there are two contributors 
    320         $id_1 = $this->_make_user('contributor'); 
    321         $id_2 = $this->_make_user('contributor'); 
     318        $id_1 = $this->factory->user->create( array( 'role' => 'contributor' ) ); 
     319        $id_2 = $this->factory->user->create( array( 'role' => 'contributor' ) ); 
    322320 
    323321        // user 1 has an extra capability 
     
    355353 
    356354        // there are two contributors 
    357         $id_1 = $this->_make_user('contributor'); 
    358         $id_2 = $this->_make_user('contributor'); 
     355        $id_1 = $this->factory->user->create( array( 'role' => 'contributor' ) ); 
     356        $id_2 = $this->factory->user->create( array( 'role' => 'contributor' ) ); 
    359357 
    360358        // user 1 has an extra capability 
     
    386384 
    387385        // user starts as an author 
    388         $id = $this->_make_user('author'); 
     386        $id = $this->factory->user->create( array( 'role' => 'author' ) ); 
    389387        $user = new WP_User($id); 
    390388        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    409407    function test_user_remove_all_caps() { 
    410408        // user starts as an author 
    411         $id = $this->_make_user('author'); 
     409        $id = $this->factory->user->create( array( 'role' => 'author' ) ); 
    412410        $user = new WP_User($id); 
    413411        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    451449 
    452450        // Make our author 
    453         $author = new WP_User($this->_make_user('author'));      
    454  
    455         // make a [pst 
    456         $this->_insert_quick_posts(1, 'post', array( 'post_author' => $author->ID ) ); 
    457         $post = end($this->post_ids); 
     451        $author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); 
     452 
     453        // make a post 
     454        $post = $this->factory->post->create( array( 'post_author' => $author->ID, 'post_type' => 'post' ) ); 
    458455 
    459456        // the author of the post 
     
    461458 
    462459        // add some other users 
    463         $admin = new WP_User($this->_make_user('administrator')); 
    464         $author_2 = new WP_User($this->_make_user('author')); 
    465         $editor = new WP_User($this->_make_user('editor')); 
    466         $contributor = new WP_User($this->_make_user('contributor')); 
     460        $admin = new WP_User( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 
     461        $author_2 = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); 
     462        $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) ); 
     463        $contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) ); 
    467464 
    468465        // administrators, editors and the post owner can edit it 
     
    512509 
    513510        // Make our author 
    514         $author = new WP_User($this->_make_user('author'));      
     511        $author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); 
    515512 
    516513        // make a page 
    517         $this->_insert_quick_pages(1, array( 'post_author' => $author->ID ) ); 
    518         $page = end($this->post_ids); 
     514        $page = $this->factory->post->create( array( 'post_author' => $author->ID, 'post_type' => 'page' ) ); 
    519515 
    520516        // the author of the page 
     
    522518 
    523519        // add some other users 
    524         $admin = new WP_User($this->_make_user('administrator')); 
    525         $author_2 = new WP_User($this->_make_user('author')); 
    526         $editor = new WP_User($this->_make_user('editor')); 
    527         $contributor = new WP_User($this->_make_user('contributor')); 
     520        $admin = new WP_User( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 
     521        $author_2 = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); 
     522        $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) ); 
     523        $contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) ); 
    528524 
    529525        // administrators, editors and the post owner can edit it 
     
    550546        // make sure an old style usermeta capabilities entry is still recognized by the new code 
    551547 
    552         $id = $this->_make_user('author'); 
     548        $id = $this->factory->user->create( array( 'role' => 'author' ) ); 
    553549        $user = new WP_User($id); 
    554550        $this->assertTrue($user->exists(), "Problem getting user $id"); 
     
    577573 
    578574    function test_upgrade() { 
    579  
    580575        // only relevant with this patch 
    581576        $this->knownWPBug(5540); 
     
    589584        $id = array(); 
    590585        for ($i=0; $i<5; $i++) { 
    591             $id[$i] = $this->_make_user(''); 
     586            $id[$i] = $this->factory->user->create( array( 'role' => '' ) ); 
    592587            $wpdb->query("DELETE FROM {$wpdb->user_role} WHERE user_id = {$id[$i]}"); 
    593588        } 
Note: See TracChangeset for help on using the changeset viewer.