Changeset 54760
- Timestamp:
- 11/07/2022 05:45:29 PM (2 years ago)
- Location:
- trunk/tests/phpunit/tests/multisite
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r54757 r54760 442 442 443 443 /** 444 * @ticket 27952445 */446 public function test_posts_count() {447 self::factory()->post->create();448 $post2 = self::factory()->post->create();449 $this->assertSame( 2, get_site()->post_count );450 451 wp_delete_post( $post2 );452 $this->assertSame( 1, get_site()->post_count );453 }454 455 /**456 444 * @ticket 26410 457 445 */ -
trunk/tests/phpunit/tests/multisite/updatePostsCount.php
r52207 r54760 3 3 if ( is_multisite() ) : 4 4 /** 5 * Test update_posts_count() get called via filters of WP_Site in multisite.5 * Test that update_posts_count() gets called via default filters on multisite. 6 6 * 7 7 * @group ms-site 8 8 * @group multisite 9 9 * 10 * @covers :: _update_posts_count_on_delete10 * @covers ::update_posts_count 11 11 */ 12 class Tests_ update_posts_count_on_deleteextends WP_UnitTestCase {12 class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase { 13 13 14 14 /** 15 * Test that the posts count is updated correctly when a posts are added and deleted. 15 * Tests that posts count is updated correctly when posts are added or deleted. 16 * 17 * @ticket 27952 16 18 * @ticket 53443 19 * 20 * @covers ::_update_posts_count_on_transition_post_status 21 * @covers ::_update_posts_count_on_delete 17 22 */ 18 public function test_update_posts_count_on_delete() { 23 public function test_update_posts_count() { 24 $original_post_count = (int) get_site()->post_count; 19 25 20 $blog_id = self::factory()->blog->create(); 21 switch_to_blog( $blog_id ); 26 $post_id = self::factory()->post->create(); 22 27 23 $current_post_count = (int) get_option( 'post_count' ); 24 25 $post_id = self::factory()->post->create( 26 array( 27 'post_type' => 'post', 28 'post_author' => '1', 29 'post_date' => '2012-10-23 19:34:42', 30 'post_status' => 'publish', 31 ) 32 ); 33 34 /** 35 * Check that add_action( 'deleted_post', '_update_posts_count_on_delete' ) is called when a post is created. 36 * Check that _update_posts_count_on_transition_post_status() is called on that filter which then calls 37 * update_posts_count to update the count. 28 /* 29 * Check that posts count is updated when a post is created: 30 * add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ); 31 * 32 * Check that _update_posts_count_on_transition_post_status() is called on that filter, 33 * which then calls update_posts_count() to update the count. 38 34 */ 39 $this->assert Equals( $current_post_count + 1, (int) get_option( 'post_count' ), 'post added' );35 $this->assertSame( $original_post_count + 1, get_site()->post_count, 'Post count should be incremented by 1.' ); 40 36 41 37 wp_delete_post( $post_id ); 42 38 43 /** 44 * Check that add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ) 45 * is called when a post is deleted. 46 * Check that _update_posts_count_on_delete() is called on that filter which then calls update_posts_count 47 * to update the count. 39 /* 40 * Check that posts count is updated when a post is deleted: 41 * add_action( 'deleted_post', '_update_posts_count_on_delete' ); 42 * 43 * Check that _update_posts_count_on_delete() is called on that filter, 44 * which then calls update_posts_count() to update the count. 48 45 */ 49 $this->assertEquals( $current_post_count, (int) get_option( 'post_count' ), 'post deleted' ); 50 51 restore_current_blog(); 52 46 $this->assertSame( $original_post_count, get_site()->post_count, 'Post count should match the original count.' ); 53 47 } 54 48 }
Note: See TracChangeset
for help on using the changeset viewer.