mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
This combines the newer test for `update_posts_count()` located in its own file with the pre-existing one from `tests/multisite/site.php`, which was essentially testing the same thing in a similar way. Includes: * Renaming the test class per the [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization naming conventions]. * Adjusting comments per the documentation standards. * Updating `@covers` tags for accuracy. * Removing unnecessary blog switching. * Using `assertSame()` to check the value type. Follow-up to [28835], [29667], [52207]. See #57023, #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@54760 602fd350-edb4-49c9-b593-d223f7449a82
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
if ( is_multisite() ) :
|
|
/**
|
|
* Test that update_posts_count() gets called via default filters on multisite.
|
|
*
|
|
* @group ms-site
|
|
* @group multisite
|
|
*
|
|
* @covers ::update_posts_count
|
|
*/
|
|
class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Tests that posts count is updated correctly when posts are added or deleted.
|
|
*
|
|
* @ticket 27952
|
|
* @ticket 53443
|
|
*
|
|
* @covers ::_update_posts_count_on_transition_post_status
|
|
* @covers ::_update_posts_count_on_delete
|
|
*/
|
|
public function test_update_posts_count() {
|
|
$original_post_count = (int) get_site()->post_count;
|
|
|
|
$post_id = self::factory()->post->create();
|
|
|
|
/*
|
|
* Check that posts count is updated when a post is created:
|
|
* add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
|
|
*
|
|
* 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->assertSame( $original_post_count + 1, get_site()->post_count, 'Post count should be incremented by 1.' );
|
|
|
|
wp_delete_post( $post_id );
|
|
|
|
/*
|
|
* Check that posts count is updated when a post is deleted:
|
|
* add_action( 'deleted_post', '_update_posts_count_on_delete' );
|
|
*
|
|
* Check that _update_posts_count_on_delete() is called on that filter,
|
|
* which then calls update_posts_count() to update the count.
|
|
*/
|
|
$this->assertSame( $original_post_count, get_site()->post_count, 'Post count should match the original count.' );
|
|
}
|
|
}
|
|
|
|
endif;
|