WordPress.org

Make WordPress Core

Changeset 795 in tests


Ignore:
Timestamp:
06/30/2012 07:39:26 PM (7 years ago)
Author:
nacin
Message:

Remove tests for a patch on #WP5540. (The ticket got closed as wontfix.)

File:
1 edited

Legend:

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

    r794 r795  
    572572    }
    573573
    574     function test_upgrade() {
    575         // only relevant with this patch
    576         $this->knownWPBug(5540);
    577 
    578         if ( !is_callable('upgrade_user_roles') )
    579             $this->markTestSkipped('depends on patch #5540');
    580 
    581         global $wpdb, $blog_id;
    582 
    583         // make some users with old style usermeta roles and caps
    584         $id = array();
    585         for ($i=0; $i<5; $i++) {
    586             $id[$i] = $this->factory->user->create( array( 'role' => '' ) );
    587             $wpdb->query("DELETE FROM {$wpdb->user_role} WHERE user_id = {$id[$i]}");
    588         }
    589 
    590         // regular users
    591         $user = new WP_User($id[0]);
    592         $this->assertTrue($user->exists(), "Problem getting user $id[0]");
    593         update_usermeta($id[0], $user->cap_key, array('administrator' => true));
    594         update_usermeta($id[1], $user->cap_key, array('editor' => true));
    595         update_usermeta($id[2], $user->cap_key, array('subscriber' => true));
    596         // a user with 2 roles
    597         update_usermeta($id[3], $user->cap_key, array('contributor' => true, 'author' => true));
    598         // a user with per-user capabilities
    599         update_usermeta($id[4], $user->cap_key, array('subscriber' => true, 'edit_posts' => true, 'upload_files' => true));
    600 
    601         upgrade_user_roles($wpdb->prefix, $blog_id);
    602 
    603         // make sure the upgrade did insert user_role rows
    604         foreach ( $id as $user_id ) {
    605             $this->assertTrue( $wpdb->get_row("SELECT user_role_id FROM {$wpdb->user_role} WHERE user_id = {$user_id}") > 0 );
    606         }
    607 
    608         // test each user's role and capabilities, and make sure the usermeta data is what we expect
    609         $user_0 = new WP_User($id[0]);
    610         $this->assertTrue($user_0->exists(), "Problem getting user $id[0]");
    611         $this->assertEquals(array('administrator'), $user_0->roles);
    612         $this->assertTrue($user_0->has_cap('switch_themes'));
    613         $this->assertTrue($user_0->has_cap('edit_users'));
    614         $this->assertTrue($user_0->has_cap('manage_options'));
    615         $this->assertTrue($user_0->has_cap('level_10'));
    616         $old_caps = get_usermeta($id[0], $user_0->cap_key);
    617         $this->assertEquals( array(), $old_caps );
    618 
    619         $user_1 = new WP_User($id[1]);
    620         $this->assertTrue($user_1->exists(), "Problem getting user $id[1]");
    621         $this->assertEquals(array('editor'), $user_1->roles);
    622         $this->assertTrue($user_1->has_cap('moderate_comments'));
    623         $this->assertTrue($user_1->has_cap('manage_categories'));
    624         $this->assertTrue($user_1->has_cap('upload_files'));
    625         $this->assertTrue($user_1->has_cap('level_7'));
    626         $this->assertFalse($user_1->has_cap('switch_themes'));
    627         $this->assertFalse($user_1->has_cap('edit_users'));
    628         $this->assertFalse($user_1->has_cap('level_8'));
    629         $old_caps = get_usermeta($id[1], $user_1->cap_key);
    630         $this->assertEquals( array(), $old_caps );
    631 
    632         $user_2 = new WP_User($id[2]);
    633         $this->assertTrue($user_2->exists(), "Problem getting user $id[2]");
    634         $this->assertEquals(array('subscriber'), $user_2->roles);
    635         $this->assertTrue($user_2->has_cap('read'));
    636         $this->assertTrue($user_2->has_cap('level_0'));
    637         $this->assertFalse($user_2->has_cap('upload_files'));
    638         $this->assertFalse($user_2->has_cap('edit_posts'));
    639         $this->assertFalse($user_2->has_cap('level_1'));
    640         $old_caps = get_usermeta($id[2], $user_2->cap_key);
    641         $this->assertEquals( array(), $old_caps );
    642 
    643         // user 3 has two roles
    644         $user_3 = new WP_User($id[3]);
    645         $this->assertTrue($user_3->exists(), "Problem getting user $id[3]");
    646         $this->assertEquals(array('contributor', 'author'), $user_3->roles);
    647         $this->assertTrue($user_3->has_cap('edit_posts'));
    648         $this->assertTrue($user_3->has_cap('edit_published_posts'));
    649         $this->assertTrue($user_3->has_cap('upload_files'));
    650         $this->assertTrue($user_3->has_cap('level_2'));
    651         $this->assertFalse($user_3->has_cap('moderate_comments'));
    652         $this->assertFalse($user_3->has_cap('manage_categories'));
    653         $this->assertFalse($user_3->has_cap('level_3'));
    654         $old_caps = get_usermeta($id[3], $user_3->cap_key);
    655         $this->assertEquals( array(), $old_caps );
    656 
    657         // user 4 is a subscriber with some extra per-user caps
    658         $user_4 = new WP_User($id[4]);
    659         $this->assertTrue($user_4->exists(), "Problem getting user $id[4]");
    660         $this->assertEquals(array('subscriber'), $user_4->roles);
    661         $this->assertTrue($user_4->has_cap('read'));
    662         $this->assertTrue($user_4->has_cap('level_0'));
    663         $this->assertFalse($user_4->has_cap('edit_users'));
    664         $this->assertFalse($user_4->has_cap('level_1'));
    665         // extra caps
    666         $this->assertTrue($user_4->has_cap('edit_posts'));
    667         $this->assertTrue($user_4->has_cap('upload_files'));
    668         // the extra caps should still be stored in usermeta
    669         $old_caps = get_usermeta($id[4], $user_4->cap_key);
    670         $this->assertEquals( array('edit_posts' => true, 'upload_files' => true), $old_caps );
    671 
    672         // quick test for get_users_of_blog
    673         $users = get_users_of_blog();
    674         #dmp('orig users', $this->orig_users);
    675         #dmp('now users', $users);
    676         $this->assertEquals( 5, count($users) - count($this->orig_users) );
    677 
    678         #dmp('get_roles_with_cap edit_posts', get_roles_with_cap('edit_posts'));
    679         #dmp('get_users_of_blog', get_users_of_blog());
    680         #dmp('get_users_with_cap edit_posts', get_users_with_cap('edit_posts'));
    681     }
    682 
    683574    function _test_generate_role_thingy() {
    684575        global $wp_roles;
Note: See TracChangeset for help on using the changeset viewer.