Make WordPress Core

Changeset 53783


Ignore:
Timestamp:
07/26/2022 02:28:57 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move wp_publish_post() tests to their own file.

Now that there is a separate test class for wp_publish_post() tests, some of the pre-existing tests from the general Tests_Post class can be moved there.

Follow-up to [1039/tests], [1174/tests], [46969], [49000].

See #55652.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r53782 r53783  
    596596    }
    597597
    598     public function test_wp_publish_post() {
    599         $draft_id = self::factory()->post->create(
    600             array(
    601                 'post_status' => 'draft',
    602             )
    603         );
    604 
    605         $post = get_post( $draft_id );
    606         $this->assertSame( 'draft', $post->post_status );
    607 
    608         wp_publish_post( $draft_id );
    609 
    610         $post = get_post( $draft_id );
    611         $this->assertSame( 'publish', $post->post_status );
    612     }
    613 
    614     /**
    615      * @ticket 22944
    616      */
    617     public function test_wp_insert_post_and_wp_publish_post_with_future_date() {
    618         $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 );
    619         $post_id     = self::factory()->post->create(
    620             array(
    621                 'post_status' => 'publish',
    622                 'post_date'   => $future_date,
    623             )
    624         );
    625 
    626         $post = get_post( $post_id );
    627         $this->assertSame( 'future', $post->post_status );
    628         $this->assertSame( $future_date, $post->post_date );
    629 
    630         wp_publish_post( $post_id );
    631 
    632         $post = get_post( $post_id );
    633         $this->assertSame( 'publish', $post->post_status );
    634         $this->assertSame( $future_date, $post->post_date );
    635     }
    636 
    637     /**
    638      * @ticket 48145
    639      */
    640     public function test_wp_insert_post_should_default_to_publish_if_post_date_is_within_59_seconds_from_current_time() {
    641         $future_date = gmdate( 'Y-m-d H:i:s', time() + 59 );
    642         $post_id     = self::factory()->post->create(
    643             array(
    644                 'post_date' => $future_date,
    645             )
    646         );
    647 
    648         $post = get_post( $post_id );
    649         $this->assertSame( 'publish', $post->post_status );
    650         $this->assertSame( $future_date, $post->post_date );
    651     }
    652 
    653     /**
    654      * @ticket 22944
    655      */
    656     public function test_publish_post_with_content_filtering() {
    657         kses_remove_filters();
    658 
    659         $post_id = wp_insert_post(
    660             array(
    661                 'post_title' => '<script>Test</script>',
    662             )
    663         );
    664         $post    = get_post( $post_id );
    665         $this->assertSame( '<script>Test</script>', $post->post_title );
    666         $this->assertSame( 'draft', $post->post_status );
    667 
    668         kses_init_filters();
    669 
    670         wp_update_post(
    671             array(
    672                 'ID'          => $post->ID,
    673                 'post_status' => 'publish',
    674             )
    675         );
    676 
    677         kses_remove_filters();
    678 
    679         $post = get_post( $post->ID );
    680         $this->assertSame( 'Test', $post->post_title );
    681     }
    682 
    683     /**
    684      * @ticket 22944
    685      */
    686     public function test_wp_publish_post_and_avoid_content_filtering() {
    687         kses_remove_filters();
    688 
    689         $post_id = wp_insert_post(
    690             array(
    691                 'post_title' => '<script>Test</script>',
    692             )
    693         );
    694         $post    = get_post( $post_id );
    695         $this->assertSame( '<script>Test</script>', $post->post_title );
    696         $this->assertSame( 'draft', $post->post_status );
    697 
    698         kses_init_filters();
    699 
    700         wp_publish_post( $post->ID );
    701 
    702         kses_remove_filters();
    703 
    704         $post = get_post( $post->ID );
    705         $this->assertSame( '<script>Test</script>', $post->post_title );
    706     }
    707 
    708598    /**
    709599     * @ticket 23708
  • trunk/tests/phpunit/tests/post/wpPublishPost.php

    r52010 r53783  
    33/**
    44 * @group post
     5 * @covers ::wp_publish_post
    56 */
    67class Tests_Post_wpPublishPost extends WP_UnitTestCase {
     
    2021    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    2122        self::$auto_draft_id = $factory->post->create( array( 'post_status' => 'auto-draft' ) );
     23    }
     24
     25    public function test_wp_publish_post() {
     26        $draft_id = self::factory()->post->create(
     27            array(
     28                'post_status' => 'draft',
     29            )
     30        );
     31
     32        $post = get_post( $draft_id );
     33        $this->assertSame( 'draft', $post->post_status );
     34
     35        wp_publish_post( $draft_id );
     36
     37        $post = get_post( $draft_id );
     38        $this->assertSame( 'publish', $post->post_status );
     39    }
     40
     41    /**
     42     * @ticket 22944
     43     * @covers ::wp_insert_post
     44     */
     45    public function test_wp_insert_post_and_wp_publish_post_with_future_date() {
     46        $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 );
     47        $post_id     = self::factory()->post->create(
     48            array(
     49                'post_status' => 'publish',
     50                'post_date'   => $future_date,
     51            )
     52        );
     53
     54        $post = get_post( $post_id );
     55        $this->assertSame( 'future', $post->post_status );
     56        $this->assertSame( $future_date, $post->post_date );
     57
     58        wp_publish_post( $post_id );
     59
     60        $post = get_post( $post_id );
     61        $this->assertSame( 'publish', $post->post_status );
     62        $this->assertSame( $future_date, $post->post_date );
     63    }
     64
     65    /**
     66     * @ticket 48145
     67     * @covers ::wp_insert_post
     68     */
     69    public function test_wp_insert_post_should_default_to_publish_if_post_date_is_within_59_seconds_from_current_time() {
     70        $future_date = gmdate( 'Y-m-d H:i:s', time() + 59 );
     71        $post_id     = self::factory()->post->create(
     72            array(
     73                'post_date' => $future_date,
     74            )
     75        );
     76
     77        $post = get_post( $post_id );
     78        $this->assertSame( 'publish', $post->post_status );
     79        $this->assertSame( $future_date, $post->post_date );
     80    }
     81
     82    /**
     83     * @ticket 22944
     84     * @covers ::wp_update_post
     85     */
     86    public function test_wp_update_post_with_content_filtering() {
     87        kses_remove_filters();
     88
     89        $post_id = wp_insert_post(
     90            array(
     91                'post_title' => '<script>Test</script>',
     92            )
     93        );
     94        $post    = get_post( $post_id );
     95        $this->assertSame( '<script>Test</script>', $post->post_title );
     96        $this->assertSame( 'draft', $post->post_status );
     97
     98        kses_init_filters();
     99
     100        wp_update_post(
     101            array(
     102                'ID'          => $post->ID,
     103                'post_status' => 'publish',
     104            )
     105        );
     106
     107        kses_remove_filters();
     108
     109        $post = get_post( $post->ID );
     110        $this->assertSame( 'Test', $post->post_title );
     111    }
     112
     113    /**
     114     * @ticket 22944
     115     */
     116    public function test_wp_publish_post_and_avoid_content_filtering() {
     117        kses_remove_filters();
     118
     119        $post_id = wp_insert_post(
     120            array(
     121                'post_title' => '<script>Test</script>',
     122            )
     123        );
     124        $post    = get_post( $post_id );
     125        $this->assertSame( '<script>Test</script>', $post->post_title );
     126        $this->assertSame( 'draft', $post->post_status );
     127
     128        kses_init_filters();
     129
     130        wp_publish_post( $post->ID );
     131
     132        kses_remove_filters();
     133
     134        $post = get_post( $post->ID );
     135        $this->assertSame( '<script>Test</script>', $post->post_title );
    22136    }
    23137
Note: See TracChangeset for help on using the changeset viewer.