WordPress.org

Make WordPress Core

Ticket #29996: 29996.diff

File 29996.diff, 3.1 KB (added by jeremyfelt, 7 years ago)
  • tests/phpunit/tests/user/multisite.php

     
    4040                $this->assertEquals( $user2->ID, $post->post_author );
    4141        }
    4242
     43        /**
     44         * Test
     45         */
    4346        function test_get_blogs_of_user() {
    44                 // Logged out users don't have blogs.
    45                 $this->assertEquals( array(), get_blogs_of_user( 0 ) );
    46 
    4747                $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    48                 $blog_ids = $this->factory->blog->create_many( 10, array( 'user_id' => $user1_id ) );
    49 
    50                 foreach ( $blog_ids as $blog_id )
    51                         $this->assertInternalType( 'int', $blog_id );
     48                $blog_ids = $this->factory->blog->create_many( 8, array( 'user_id' => $user1_id ) );
    5249
    5350                $blogs_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
    5451                sort( $blogs_of_user );
    55                 $this->assertEquals ( array_merge( array( 1 ), $blog_ids), $blogs_of_user );
     52
     53                // User should be a member of the created sites and the network's initial site.
     54                $this->assertEquals( array_merge( array( 1 ), $blog_ids ), $blogs_of_user );
    5655
    5756                $this->assertTrue( remove_user_from_blog( $user1_id, 1 ) );
     57                $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[2] ) );
     58                $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[4] ) );
     59                $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[6] ) );
     60
     61                unset( $blog_ids[2] );
     62                unset( $blog_ids[4] );
     63                unset( $blog_ids[6] );
     64                sort( $blog_ids );
     65
     66                $blogs_of_user = get_blogs_of_user( $user1_id, false );
     67                $blog_ids_of_user = array_keys( $blogs_of_user );
     68                sort( $blog_ids_of_user );
    5869
    59                 $blogs_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
    60                 sort( $blogs_of_user );
    61                 $this->assertEquals ( $blog_ids, $blogs_of_user );
     70                // User should now be a member of the remaining sites, minus 1,2,4 and 6.
     71                $this->assertEquals( $blog_ids, $blog_ids_of_user );
    6272
    63                 foreach ( get_blogs_of_user( $user1_id, false ) as $blog ) {
     73                foreach ( $blogs_of_user as $blog_id => $blog ) {
    6474                        $this->assertTrue( isset( $blog->userblog_id ) );
     75                        $this->assertEquals( $blog_id, $blog->userblog_id );
    6576                        $this->assertTrue( isset( $blog->blogname ) );
    6677                        $this->assertTrue( isset( $blog->domain ) );
    6778                        $this->assertTrue( isset( $blog->path ) );
     
    7182                        $this->assertTrue( isset( $blog->spam ) );
    7283                        $this->assertTrue( isset( $blog->deleted ) );
    7384                }
    74 
    75                 // Non-existent users don't have blogs.
    76                 wpmu_delete_user( $user1_id );
    77                 $user = new WP_User( $user1_id );
    78                 $this->assertFalse( $user->exists(), 'WP_User->exists' );
    79                 $this->assertEquals( array(), get_blogs_of_user( $user1_id ) );
    8085        }
    8186
    8287        /**
  • tests/phpunit/tests/user.php

     
    375375                        wpmu_delete_user( $user_id );
    376376                else
    377377                        wp_delete_user( $user_id );
     378
     379                $user = new WP_User( $user_id );
     380                $this->assertFalse( $user->exists(), 'WP_User->exists' );
    378381                $this->assertEquals( array(), get_blogs_of_user( $user_id ) );
    379382        }
    380383