Make WordPress Core


Ignore:
Timestamp:
08/27/2015 08:01:37 PM (9 years ago)
Author:
johnbillion
Message:

Improve the efficiency of is_user_member_of_blog() by removing its use of get_blogs_of_user(). Adds additional tests.

Fixes #32472
Props BinaryKitten, sammybeats, johnbillion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/multisite.php

    r33143 r33771  
    142142
    143143        $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     144        $user2_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    144145
    145146        $old_current = get_current_user_id();
     147
     148        $this->assertSame( 0, $old_current );
     149
     150        // test for "get current user" when not logged in
     151        $this->assertFalse( is_user_member_of_blog() );
     152
    146153        wp_set_current_user( $user1_id );
    147154
     
    155162        foreach ( $blog_ids as $blog_id ) {
    156163            $this->assertInternalType( 'int', $blog_id );
     164
     165            // Current user gets added to new blogs
    157166            $this->assertTrue( is_user_member_of_blog( $user1_id, $blog_id ) );
     167            // Other users should not
     168            $this->assertFalse( is_user_member_of_blog( $user2_id, $blog_id ) );
     169
     170            switch_to_blog( $blog_id );
     171
     172            $this->assertTrue( is_user_member_of_blog( $user1_id ) );
     173            $this->assertFalse( is_user_member_of_blog( $user2_id ) );
     174
     175            // Remove user 1 from blog
    158176            $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
     177
     178            // Add user 2 to blog
     179            $this->assertTrue( add_user_to_blog( $blog_id, $user2_id, 'subscriber' ) );
     180
     181            $this->assertFalse( is_user_member_of_blog( $user1_id ) );
     182            $this->assertTrue( is_user_member_of_blog( $user2_id ) );
     183
     184            restore_current_blog();
     185
    159186            $this->assertFalse( is_user_member_of_blog( $user1_id, $blog_id ) );
     187            $this->assertTrue( is_user_member_of_blog( $user2_id, $blog_id ) );
    160188        }
    161189
    162190        wpmu_delete_user( $user1_id );
    163191        $user = new WP_User( $user1_id );
    164         $this->assertFalse( $user->exists(), 'WP_User->exists' );
    165         $this->assertFalse( is_user_member_of_blog( $user1_id ), 'is_user_member_of_blog' );
     192        $this->assertFalse( $user->exists() );
     193        $this->assertFalse( is_user_member_of_blog( $user1_id ) );
    166194
    167195        wp_set_current_user( $old_current );
Note: See TracChangeset for help on using the changeset viewer.