Make WordPress Core


Ignore:
Timestamp:
07/26/2022 02:28:57 PM (4 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.