mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Previously, the `post_count` option value was not decremented when a post was deleted. This change moves the `_update_posts_count_on_delete` action from `delete_post` hook to `after_delete_post` to ensure the deletion is taken into account. Props henry.wright, pbearne, audrasjb. Fixes #53443. git-svn-id: https://develop.svn.wordpress.org/trunk@52207 602fd350-edb4-49c9-b593-d223f7449a82
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
if ( is_multisite() ) :
|
|
/**
|
|
* Test update_posts_count() get called via filters of WP_Site in multisite.
|
|
*
|
|
* @group ms-site
|
|
* @group multisite
|
|
*
|
|
* @covers ::_update_posts_count_on_delete
|
|
*/
|
|
class Tests_update_posts_count_on_delete extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Test that the posts count is updated correctly when a posts are added and deleted.
|
|
* @ticket 53443
|
|
*/
|
|
public function test_update_posts_count_on_delete() {
|
|
|
|
$blog_id = self::factory()->blog->create();
|
|
switch_to_blog( $blog_id );
|
|
|
|
$current_post_count = (int) get_option( 'post_count' );
|
|
|
|
$post_id = self::factory()->post->create(
|
|
array(
|
|
'post_type' => 'post',
|
|
'post_author' => '1',
|
|
'post_date' => '2012-10-23 19:34:42',
|
|
'post_status' => 'publish',
|
|
)
|
|
);
|
|
|
|
/**
|
|
* Check that add_action( 'deleted_post', '_update_posts_count_on_delete' ) is called when a post is created.
|
|
* Check that _update_posts_count_on_transition_post_status() is called on that filter which then calls
|
|
* update_posts_count to update the count.
|
|
*/
|
|
$this->assertEquals( $current_post_count + 1, (int) get_option( 'post_count' ), 'post added' );
|
|
|
|
wp_delete_post( $post_id );
|
|
|
|
/**
|
|
* Check that add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 )
|
|
* is called when a post is deleted.
|
|
* Check that _update_posts_count_on_delete() is called on that filter which then calls update_posts_count
|
|
* to update the count.
|
|
*/
|
|
$this->assertEquals( $current_post_count, (int) get_option( 'post_count' ), 'post deleted' );
|
|
|
|
restore_current_blog();
|
|
|
|
}
|
|
}
|
|
|
|
endif;
|