WordPress.org

Make WordPress Core

Changeset 712 in tests


Ignore:
Timestamp:
05/08/12 17:02:39 (2 years ago)
Author:
ryan
Message:

Test wp_delete_user() and make sure it honors the delete_with_user post type flag. see #WP16358

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user.php

    r696 r712  
    440440        wp_delete_post( $post_id, true ); 
    441441    } 
     442 
     443    function test_delete_user() { 
     444        $user_id = $this->_make_user('author'); 
     445        $user = new WP_User( $user_id ); 
     446 
     447        $post = array( 
     448            'post_author' => $user_id, 
     449            'post_status' => 'publish', 
     450            'post_content' => rand_str(), 
     451            'post_title' => rand_str(), 
     452            'post_type' => 'post', 
     453        ); 
     454 
     455        // insert a post and make sure the ID is ok 
     456        $post_id = wp_insert_post($post); 
     457        $this->assertTrue(is_numeric($post_id)); 
     458        $this->assertTrue($post_id > 0); 
     459 
     460        $post = get_post( $post_id ); 
     461        $this->assertEquals( $post_id, $post->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' => 'nav_menu_item', 
     469        ); 
     470 
     471        // insert a post and make sure the ID is ok 
     472        $nav_id = wp_insert_post($post); 
     473        $this->assertTrue(is_numeric($nav_id)); 
     474        $this->assertTrue($nav_id > 0); 
     475 
     476        $post = get_post( $nav_id ); 
     477        $this->assertEquals( $nav_id, $post->ID ); 
     478 
     479        wp_delete_user( $user_id ); 
     480        $user = new WP_User( $user_id ); 
     481        $this->assertFalse( $user->exists() ); 
     482 
     483        $this->assertNotNull( get_post( $post_id ) ); 
     484        $this->assertEquals( 'trash', get_post( $post_id )->post_status ); 
     485        // nav_menu_item is delete_with_user = false so the nav post should remain published. 
     486        $this->assertNotNull( get_post( $nav_id ) ); 
     487        $this->assertEquals( 'publish', get_post( $nav_id )->post_status ); 
     488        wp_delete_post( $nav_id, true ); 
     489        $this->assertNull( get_post( $nav_id ) ); 
     490        wp_delete_post( $post_id, true ); 
     491        $this->assertNull( get_post( $post_id ) ); 
     492    } 
    442493} 
    443494 
Note: See TracChangeset for help on using the changeset viewer.