Make WordPress Core


Ignore:
Timestamp:
09/11/2015 01:39:52 AM (9 years ago)
Author:
boonebgorges
Message:

Move wp_delete_user() tests to their own file.

See #33800.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3/tests/phpunit/tests/user.php

    r33115 r34031  
    336336
    337337    /**
    338      * Test that usermeta cache is cleared after user deletion.
    339      *
    340      * @ticket 19500
    341      */
    342     function test_get_blogs_of_user() {
    343         // Logged out users don't have blogs.
    344         $this->assertEquals( array(), get_blogs_of_user( 0 ) );
    345 
    346         $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
    347         $blogs = get_blogs_of_user( $user_id );
    348         $this->assertEquals( array( 1 ), array_keys( $blogs ) );
    349 
    350         // Non-existent users don't have blogs.
    351         if ( is_multisite() )
    352             wpmu_delete_user( $user_id );
    353         else
    354             wp_delete_user( $user_id );
    355 
    356         $user = new WP_User( $user_id );
    357         $this->assertFalse( $user->exists(), 'WP_User->exists' );
    358         $this->assertEquals( array(), get_blogs_of_user( $user_id ) );
    359     }
    360 
    361     /**
    362      * Test that usermeta cache is cleared after user deletion.
    363      *
    364      * @ticket 19500
    365      */
    366     function test_is_user_member_of_blog() {
    367         $old_current = get_current_user_id();
    368 
    369         $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
    370         wp_set_current_user( $user_id );
    371 
    372         $this->assertTrue( is_user_member_of_blog() );
    373         $this->assertTrue( is_user_member_of_blog( 0, 0 ) );
    374         $this->assertTrue( is_user_member_of_blog( 0, get_current_blog_id() ) );
    375         $this->assertTrue( is_user_member_of_blog( $user_id ) );
    376         $this->assertTrue( is_user_member_of_blog( $user_id, get_current_blog_id() ) );
    377 
    378         // Will only remove the user from the current site in multisite; this is desired
    379         // and will achieve the desired effect with is_user_member_of_blog().
    380         wp_delete_user( $user_id );
    381 
    382         $this->assertFalse( is_user_member_of_blog( $user_id ) );
    383         $this->assertFalse( is_user_member_of_blog( $user_id, get_current_blog_id() ) );
    384 
    385         wp_set_current_user( $old_current );
    386     }
    387 
    388     /**
    389338     * ticket 19595
    390339     */
     
    457406    }
    458407
    459     function test_delete_user() {
    460         $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    461         $user = new WP_User( $user_id );
    462 
    463         $post = array(
    464             'post_author' => $user_id,
    465             'post_status' => 'publish',
    466             'post_content' => rand_str(),
    467             'post_title' => rand_str(),
    468             'post_type' => 'post',
    469         );
    470 
    471         // insert a post and make sure the ID is ok
    472         $post_id = wp_insert_post($post);
    473         $this->assertTrue(is_numeric($post_id));
    474         $this->assertTrue($post_id > 0);
    475 
    476         $post = get_post( $post_id );
    477         $this->assertEquals( $post_id, $post->ID );
    478 
    479         $post = array(
    480             'post_author' => $user_id,
    481             'post_status' => 'publish',
    482             'post_content' => rand_str(),
    483             'post_title' => rand_str(),
    484             'post_type' => 'nav_menu_item',
    485         );
    486 
    487         // insert a post and make sure the ID is ok
    488         $nav_id = wp_insert_post($post);
    489         $this->assertTrue(is_numeric($nav_id));
    490         $this->assertTrue($nav_id > 0);
    491 
    492         $post = get_post( $nav_id );
    493         $this->assertEquals( $nav_id, $post->ID );
    494 
    495         wp_delete_user( $user_id );
    496         $user = new WP_User( $user_id );
    497         if ( is_multisite() )
    498             $this->assertTrue( $user->exists() );
    499         else
    500             $this->assertFalse( $user->exists() );
    501 
    502         $this->assertNotNull( get_post( $post_id ) );
    503         $this->assertEquals( 'trash', get_post( $post_id )->post_status );
    504         // nav_menu_item is delete_with_user = false so the nav post should remain published.
    505         $this->assertNotNull( get_post( $nav_id ) );
    506         $this->assertEquals( 'publish', get_post( $nav_id )->post_status );
    507         wp_delete_post( $nav_id, true );
    508         $this->assertNull( get_post( $nav_id ) );
    509         wp_delete_post( $post_id, true );
    510         $this->assertNull( get_post( $post_id ) );
    511     }
    512 
    513408    /**
    514409     * @ticket 13317
     
    549444        $user = WP_User::get_data_by( 'id', 99999 );
    550445        $this->assertEquals( false, $user );
    551     }
    552 
    553     /**
    554      * @ticket 20447
    555      */
    556     function test_wp_delete_user_reassignment_clears_post_caches() {
    557         $user_id   = $this->factory->user->create();
    558         $reassign  = $this->factory->user->create();
    559         $post_id   = $this->factory->post->create( array( 'post_author' => $user_id ) );
    560 
    561         get_post( $post_id ); // Ensure this post is in the cache.
    562 
    563         wp_delete_user( $user_id, $reassign );
    564 
    565         $post = get_post( $post_id );
    566         $this->assertEquals( $reassign, $post->post_author );
    567446    }
    568447
Note: See TracChangeset for help on using the changeset viewer.