WordPress.org

Make WordPress Core

Changeset 1174 in tests


Ignore:
Timestamp:
12/27/2012 03:10:37 PM (5 years ago)
Author:
nacin
Message:

Unit tests for wp_publish_post(). Ensure that:

  • A future-dated post is forcibly moved to publish when wp_publish_post() is called.
  • A post should not get filtered by kses when wp_publish_post() is called.

see #22944.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/post.php

    r1040 r1174  
    521521        $this->assertEquals( 'publish', $post->post_status );
    522522    }
     523
     524    /**
     525     * @ticket 22944
     526     */
     527    function test_wp_insert_post_and_wp_publish_post_with_future_date() {
     528        $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 );
     529        $post_id = $this->factory->post->create( array(
     530            'post_status' => 'publish',
     531            'post_date' => $future_date,
     532        ) );
     533
     534        $post = get_post( $post_id );
     535        $this->assertEquals( 'future', $post->post_status );
     536        $this->assertEquals( $future_date, $post->post_date );
     537
     538        wp_publish_post( $post_id );
     539        $post = get_post( $post_id );
     540
     541        $this->assertEquals( 'publish', $post->post_status );
     542        $this->assertEquals( $future_date, $post->post_date );
     543    }
     544
     545    /**
     546     * @ticket 22944
     547     */
     548    function test_publish_post_with_content_filtering() {
     549        kses_remove_filters();
     550
     551        $post_id = wp_insert_post( array( 'post_title' => '<script>Test</script>' ) );
     552        $post = get_post( $post_id );
     553        $this->assertEquals( '<script>Test</script>', $post->post_title );
     554        $this->assertEquals( 'draft', $post->post_status );
     555
     556        kses_init_filters();
     557
     558        wp_update_post( array( 'ID' => $post->ID, 'post_status' => 'publish' ) );
     559        $post = get_post( $post->ID );
     560        $this->assertEquals( 'Test', $post->post_title );
     561
     562        kses_remove_filters();
     563    }
     564
     565    /**
     566     * @ticket 22944
     567     */
     568    function test_wp_publish_post_and_avoid_content_filtering() {
     569        kses_remove_filters();
     570
     571        $post_id = wp_insert_post( array( 'post_title' => '<script>Test</script>' ) );
     572        $post = get_post( $post_id );
     573        $this->assertEquals( '<script>Test</script>', $post->post_title );
     574        $this->assertEquals( 'draft', $post->post_status );
     575
     576        kses_init_filters();
     577
     578        wp_publish_post( $post->ID );
     579        $post = get_post( $post->ID );
     580        $this->assertEquals( '<script>Test</script>', $post->post_title );
     581
     582        kses_remove_filters();
     583    }
    523584}
Note: See TracChangeset for help on using the changeset viewer.