mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
This commit is contained in:
parent
13e664a412
commit
d5fe7bcf45
@ -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' => '<script>Test</script>',
|
||||
)
|
||||
);
|
||||
$post = get_post( $post_id );
|
||||
$this->assertSame( '<script>Test</script>', $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' => '<script>Test</script>',
|
||||
)
|
||||
);
|
||||
$post = get_post( $post_id );
|
||||
$this->assertSame( '<script>Test</script>', $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( '<script>Test</script>', $post->post_title );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 23708
|
||||
*/
|
||||
|
||||
@ -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' => '<script>Test</script>',
|
||||
)
|
||||
);
|
||||
$post = get_post( $post_id );
|
||||
$this->assertSame( '<script>Test</script>', $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' => '<script>Test</script>',
|
||||
)
|
||||
);
|
||||
$post = get_post( $post_id );
|
||||
$this->assertSame( '<script>Test</script>', $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( '<script>Test</script>', $post->post_title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure wp_publish_post does not add default category in error.
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user