- Timestamp:
- 04/09/2025 01:29:39 PM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/updatePostsCount.php
r55419 r60148 1 1 <?php 2 2 3 if ( is_multisite() ) : 3 /** 4 * Test that update_posts_count() gets called via default filters on multisite. 5 * 6 * @group ms-required 7 * @group ms-site 8 * @group multisite 9 * 10 * @covers ::update_posts_count 11 */ 12 class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase { 13 4 14 /** 5 * Test that update_posts_count() gets called via default filters on multisite.15 * Tests that posts count is updated correctly when posts are added or deleted. 6 16 * 7 * @ group ms-site8 * @ group multisite17 * @ticket 27952 18 * @ticket 53443 9 19 * 10 * @covers ::update_posts_count 20 * @covers ::_update_posts_count_on_transition_post_status 21 * @covers ::_update_posts_count_on_delete 11 22 */ 12 class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase { 23 public function test_update_posts_count() { 24 $blog_id = self::factory()->blog->create(); 25 switch_to_blog( $blog_id ); 13 26 14 /** 15 * Tests that posts count is updated correctly when posts are added or deleted. 27 $original_post_count = (int) get_site()->post_count; 28 29 $post_id = self::factory()->post->create(); 30 31 $post_count_after_creating = get_site()->post_count; 32 33 wp_delete_post( $post_id, true ); 34 35 $post_count_after_deleting = get_site()->post_count; 36 37 restore_current_blog(); 38 39 /* 40 * Check that posts count is updated when a post is created: 41 * add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ); 16 42 * 17 * @ticket 27952 18 * @ticket 53443 43 * Check that _update_posts_count_on_transition_post_status() is called on that filter, 44 * which then calls update_posts_count() to update the count. 45 */ 46 $this->assertSame( $original_post_count + 1, $post_count_after_creating, 'Post count should be incremented by 1.' ); 47 48 /* 49 * Check that posts count is updated when a post is deleted: 50 * add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 ); 19 51 * 20 * @covers ::_update_posts_count_on_transition_post_status21 * @covers ::_update_posts_count_on_delete52 * Check that _update_posts_count_on_delete() is called on that filter, 53 * which then calls update_posts_count() to update the count. 22 54 */ 23 public function test_update_posts_count() { 24 $blog_id = self::factory()->blog->create(); 25 switch_to_blog( $blog_id ); 26 27 $original_post_count = (int) get_site()->post_count; 28 29 $post_id = self::factory()->post->create(); 30 31 $post_count_after_creating = get_site()->post_count; 32 33 wp_delete_post( $post_id, true ); 34 35 $post_count_after_deleting = get_site()->post_count; 36 37 restore_current_blog(); 38 39 /* 40 * Check that posts count is updated when a post is created: 41 * add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ); 42 * 43 * Check that _update_posts_count_on_transition_post_status() is called on that filter, 44 * which then calls update_posts_count() to update the count. 45 */ 46 $this->assertSame( $original_post_count + 1, $post_count_after_creating, 'Post count should be incremented by 1.' ); 47 48 /* 49 * Check that posts count is updated when a post is deleted: 50 * add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 ); 51 * 52 * Check that _update_posts_count_on_delete() is called on that filter, 53 * which then calls update_posts_count() to update the count. 54 */ 55 $this->assertSame( $original_post_count, $post_count_after_deleting, 'Post count should match the original count.' ); 56 } 55 $this->assertSame( $original_post_count, $post_count_after_deleting, 'Post count should match the original count.' ); 57 56 } 58 59 endif; 57 }
Note: See TracChangeset
for help on using the changeset viewer.