From d5fe7bcf45496014c0ea7513667b4091353ae41b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 26 Jul 2022 14:28:57 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@53783 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post.php | 110 -------------------- tests/phpunit/tests/post/wpPublishPost.php | 114 +++++++++++++++++++++ 2 files changed, 114 insertions(+), 110 deletions(-) diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 74613567a6..6f2641e9f9 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -595,116 +595,6 @@ class Tests_Post extends WP_UnitTestCase { $this->assertSame( $expected, get_permalink( $post_id ) ); } - public function test_wp_publish_post() { - $draft_id = self::factory()->post->create( - array( - 'post_status' => 'draft', - ) - ); - - $post = get_post( $draft_id ); - $this->assertSame( 'draft', $post->post_status ); - - wp_publish_post( $draft_id ); - - $post = get_post( $draft_id ); - $this->assertSame( 'publish', $post->post_status ); - } - - /** - * @ticket 22944 - */ - public function test_wp_insert_post_and_wp_publish_post_with_future_date() { - $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 ); - $post_id = self::factory()->post->create( - array( - 'post_status' => 'publish', - 'post_date' => $future_date, - ) - ); - - $post = get_post( $post_id ); - $this->assertSame( 'future', $post->post_status ); - $this->assertSame( $future_date, $post->post_date ); - - wp_publish_post( $post_id ); - - $post = get_post( $post_id ); - $this->assertSame( 'publish', $post->post_status ); - $this->assertSame( $future_date, $post->post_date ); - } - - /** - * @ticket 48145 - */ - public function test_wp_insert_post_should_default_to_publish_if_post_date_is_within_59_seconds_from_current_time() { - $future_date = gmdate( 'Y-m-d H:i:s', time() + 59 ); - $post_id = self::factory()->post->create( - array( - 'post_date' => $future_date, - ) - ); - - $post = get_post( $post_id ); - $this->assertSame( 'publish', $post->post_status ); - $this->assertSame( $future_date, $post->post_date ); - } - - /** - * @ticket 22944 - */ - public function test_publish_post_with_content_filtering() { - kses_remove_filters(); - - $post_id = wp_insert_post( - array( - 'post_title' => '', - ) - ); - $post = get_post( $post_id ); - $this->assertSame( '', $post->post_title ); - $this->assertSame( 'draft', $post->post_status ); - - kses_init_filters(); - - wp_update_post( - array( - 'ID' => $post->ID, - 'post_status' => 'publish', - ) - ); - - kses_remove_filters(); - - $post = get_post( $post->ID ); - $this->assertSame( 'Test', $post->post_title ); - } - - /** - * @ticket 22944 - */ - public function test_wp_publish_post_and_avoid_content_filtering() { - kses_remove_filters(); - - $post_id = wp_insert_post( - array( - 'post_title' => '', - ) - ); - $post = get_post( $post_id ); - $this->assertSame( '', $post->post_title ); - $this->assertSame( 'draft', $post->post_status ); - - kses_init_filters(); - - wp_publish_post( $post->ID ); - - kses_remove_filters(); - - $post = get_post( $post->ID ); - $this->assertSame( '', $post->post_title ); - } - /** * @ticket 23708 */ diff --git a/tests/phpunit/tests/post/wpPublishPost.php b/tests/phpunit/tests/post/wpPublishPost.php index 609ae7570a..a8c0227b0c 100644 --- a/tests/phpunit/tests/post/wpPublishPost.php +++ b/tests/phpunit/tests/post/wpPublishPost.php @@ -2,6 +2,7 @@ /** * @group post + * @covers ::wp_publish_post */ class Tests_Post_wpPublishPost extends WP_UnitTestCase { @@ -21,6 +22,119 @@ class Tests_Post_wpPublishPost extends WP_UnitTestCase { self::$auto_draft_id = $factory->post->create( array( 'post_status' => 'auto-draft' ) ); } + public function test_wp_publish_post() { + $draft_id = self::factory()->post->create( + array( + 'post_status' => 'draft', + ) + ); + + $post = get_post( $draft_id ); + $this->assertSame( 'draft', $post->post_status ); + + wp_publish_post( $draft_id ); + + $post = get_post( $draft_id ); + $this->assertSame( 'publish', $post->post_status ); + } + + /** + * @ticket 22944 + * @covers ::wp_insert_post + */ + public function test_wp_insert_post_and_wp_publish_post_with_future_date() { + $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 ); + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + 'post_date' => $future_date, + ) + ); + + $post = get_post( $post_id ); + $this->assertSame( 'future', $post->post_status ); + $this->assertSame( $future_date, $post->post_date ); + + wp_publish_post( $post_id ); + + $post = get_post( $post_id ); + $this->assertSame( 'publish', $post->post_status ); + $this->assertSame( $future_date, $post->post_date ); + } + + /** + * @ticket 48145 + * @covers ::wp_insert_post + */ + public function test_wp_insert_post_should_default_to_publish_if_post_date_is_within_59_seconds_from_current_time() { + $future_date = gmdate( 'Y-m-d H:i:s', time() + 59 ); + $post_id = self::factory()->post->create( + array( + 'post_date' => $future_date, + ) + ); + + $post = get_post( $post_id ); + $this->assertSame( 'publish', $post->post_status ); + $this->assertSame( $future_date, $post->post_date ); + } + + /** + * @ticket 22944 + * @covers ::wp_update_post + */ + public function test_wp_update_post_with_content_filtering() { + kses_remove_filters(); + + $post_id = wp_insert_post( + array( + 'post_title' => '', + ) + ); + $post = get_post( $post_id ); + $this->assertSame( '', $post->post_title ); + $this->assertSame( 'draft', $post->post_status ); + + kses_init_filters(); + + wp_update_post( + array( + 'ID' => $post->ID, + 'post_status' => 'publish', + ) + ); + + kses_remove_filters(); + + $post = get_post( $post->ID ); + $this->assertSame( 'Test', $post->post_title ); + } + + /** + * @ticket 22944 + */ + public function test_wp_publish_post_and_avoid_content_filtering() { + kses_remove_filters(); + + $post_id = wp_insert_post( + array( + 'post_title' => '', + ) + ); + $post = get_post( $post_id ); + $this->assertSame( '', $post->post_title ); + $this->assertSame( 'draft', $post->post_status ); + + kses_init_filters(); + + wp_publish_post( $post->ID ); + + kses_remove_filters(); + + $post = get_post( $post->ID ); + $this->assertSame( '', $post->post_title ); + } + /** * Ensure wp_publish_post does not add default category in error. *