WordPress.org

Make WordPress Core

Ticket #29996: 29996.2.diff

File 29996.2.diff, 4.0 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 the returned data from get_blogs_of_user()
     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 ) );
     48                $blog_ids = $this->factory->blog->create_many( 8, array( 'user_id' => $user1_id ) );
    4949
    50                 foreach ( $blog_ids as $blog_id )
    51                         $this->assertInternalType( 'int', $blog_id );
     50                // All sites are new and not marked as spam, archived, or deleted.
     51                $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id ) );
    5252
    53                 $blogs_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
    54                 sort( $blogs_of_user );
    55                 $this->assertEquals ( array_merge( array( 1 ), $blog_ids), $blogs_of_user );
     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 ), $blog_ids_of_user );
    5655
    5756                $this->assertTrue( remove_user_from_blog( $user1_id, 1 ) );
    58 
    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 );
    62 
    63                 foreach ( get_blogs_of_user( $user1_id, false ) as $blog ) {
     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
     68                // Each site retrieved should match the expected structure.
     69                foreach ( $blogs_of_user as $blog_id => $blog ) {
     70                        $this->assertEquals( $blog_id, $blog->userblog_id );
    6471                        $this->assertTrue( isset( $blog->userblog_id ) );
    6572                        $this->assertTrue( isset( $blog->blogname ) );
    6673                        $this->assertTrue( isset( $blog->domain ) );
     
    7279                        $this->assertTrue( isset( $blog->deleted ) );
    7380                }
    7481
    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 ) );
     82                // The user should now be a member of the remaining sites - minus 1,2,4 and 6.
     83                $blog_ids_of_user = array_keys( $blogs_of_user );
     84                $this->assertEquals( $blog_ids, $blog_ids_of_user );
     85
     86                update_blog_details( $blog_ids[0], array( 'spam' => 1 ) );
     87                update_blog_details( $blog_ids[1], array( 'archived' => 1 ) );
     88                update_blog_details( $blog_ids[2], array( 'deleted' => 1 ) );
     89
     90                // Passing true as the second parameter should retrieve ALL sites, including those just marked.
     91                $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id, true ) );
     92                $this->assertEquals( $blog_ids, $blog_ids_of_user );
     93
     94                unset( $blog_ids[0] );
     95                unset( $blog_ids[1] );
     96                unset( $blog_ids[2] );
     97                sort( $blog_ids );
     98
     99                // Passing false (also the default) as the second parameter should retrieve only good sites.
     100                $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
     101                $this->assertEquals( $blog_ids, $blog_ids_of_user );
    80102        }
    81103
    82104        /**
  • 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