Ticket #16358: 16358-unit-tests.diff

File 16358-unit-tests.diff, 1.6 KB (added by ryan, 13 months ago)
  • wp-testcase/test_user.php

     
    439439 
    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->assertNull( get_post( $post_id ) ); 
     484                // nav_menu_item is delete_with_user = false so the nav post should remain. 
     485                $this->assertNotNull( get_post( $nav_id ) ); 
     486                wp_delete_post( $nav_id, true ); 
     487                $this->assertNull( get_post( $nav_id ) ); 
     488        } 
    442489} 
    443490 
    444491?>