Make WordPress Core


Ignore:
Timestamp:
11/07/2022 08:53:18 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Restore blog switching in update_posts_count() test.

The previous iteration of the test passed when run in isolation but failed when running the whole test suite.

Restoring the switch_to_blog() call allows the test to pass again pending a deeper investigation.

Follow-up to [54760].

See #57023.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/updatePostsCount.php

    r54760 r54762  
    2222         */
    2323        public function test_update_posts_count() {
     24            $blog_id = self::factory()->blog->create();
     25            switch_to_blog( $blog_id );
     26
    2427            $original_post_count = (int) get_site()->post_count;
    2528
    2629            $post_id = self::factory()->post->create();
     30
     31            $post_count_after_creating = get_site()->post_count;
     32
     33            wp_delete_post( $post_id );
     34
     35            $post_count_after_deleting = get_site()->post_count;
     36
     37            restore_current_blog();
    2738
    2839            /*
     
    3344             * which then calls update_posts_count() to update the count.
    3445             */
    35             $this->assertSame( $original_post_count + 1, get_site()->post_count, 'Post count should be incremented by 1.' );
    36 
    37             wp_delete_post( $post_id );
     46            $this->assertSame( $original_post_count + 1, $post_count_after_creating, 'Post count should be incremented by 1.' );
    3847
    3948            /*
     
    4453             * which then calls update_posts_count() to update the count.
    4554             */
    46             $this->assertSame( $original_post_count, get_site()->post_count, 'Post count should match the original count.' );
     55            $this->assertSame( $original_post_count, $post_count_after_deleting, 'Post count should match the original count.' );
    4756        }
    4857    }
Note: See TracChangeset for help on using the changeset viewer.