WordPress.org

Make WordPress Core

Changeset 476 in tests


Ignore:
Timestamp:
11/07/2011 11:03:57 PM (7 years ago)
Author:
duck_
Message:

get_blogs_of_user() and is_user_member_of_blog() tests for single site. Logged out / non-existent user tests for MS. See #WP19160.

Location:
wp-testcase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_ms.php

    r462 r476  
    7676        global $current_site;
    7777
     78        // Logged out users don't have blogs.
     79        $this->assertFalse( get_blogs_of_user( 0 ) );
     80
    7881        $user1_id = $this->_make_user('administrator');
    7982
     
    9598        $this->assertEquals ( $blog_ids, $blogs_of_user );
    9699
     100        // Non-existent users don't have blogs.
     101        wpmu_delete_user( $user1_id );
     102        $this->assertFalse( get_blogs_of_user( $user1_id ) );
     103
    97104        foreach ( $blog_ids as $blog_id )
    98105            wpmu_delete_blog( $blog_id );
     
    157164            $this->assertFalse( is_user_member_of_blog( $user1_id, $blog_id ) );
    158165        }
     166
     167        wpmu_delete_user( $user1_id );
     168        $this->assertFalse( is_user_member_of_blog( $user1_id ) );
    159169
    160170        wp_set_current_user( $old_current );
  • wp-testcase/test_user.php

    r449 r476  
    294294            $this->assertEquals( $value, $user->get( $key ), $key );
    295295    }
     296
     297    function test_get_blogs_of_user() {
     298        // Logged out users don't have blogs.
     299        $this->assertFalse( get_blogs_of_user( 0 ) );
     300
     301        $user_id = $this->_make_user( 'subscriber' );
     302        $blogs = get_blogs_of_user( $user_id );
     303        $this->assertEquals( array( 1 ), array_keys( $blogs ) );
     304
     305        // Non-existent users don't have blogs.
     306        wp_delete_user( $user_id );
     307        $this->assertFalse( get_blogs_of_user( $user_id ) );
     308    }
     309
     310    function test_is_user_member_of_blog() {
     311        $old_current = get_current_user_id();
     312
     313        $user_id = $this->_make_user( 'subscriber' );
     314        wp_set_current_user( $user_id );
     315
     316        $this->assertTrue( is_user_member_of_blog() );
     317        $this->assertTrue( is_user_member_of_blog( 0, 0 ) );
     318        $this->assertTrue( is_user_member_of_blog( 0, get_current_blog_id() ) );
     319        $this->assertTrue( is_user_member_of_blog( $user_id ) );
     320        $this->assertTrue( is_user_member_of_blog( $user_id, get_current_blog_id() ) );
     321
     322        wp_delete_user( $user_id );
     323        $this->assertFalse( is_user_member_of_blog( $user_id ) );
     324        $this->assertFalse( is_user_member_of_blog( $user_id, get_current_blog_id() ) );
     325
     326        wp_set_current_user( $old_current );
     327    }
    296328}
    297329
Note: See TracChangeset for help on using the changeset viewer.