Make WordPress Core


Ignore:
Timestamp:
04/09/2025 01:29:39 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

Tests: Use the ms-required group where appropriate.

This replaces the if ( is_multisite() ) conditional wrapping entire test classes with the ms-required group for more consistency across the test suite.

Follow-up to [40520].

See #63167.

File:
1 edited

Legend:

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

    r55419 r60148  
    11<?php
    22
    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 */
     12class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase {
     13
    414    /**
    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.
    616     *
    7      * @group ms-site
    8      * @group multisite
     17     * @ticket 27952
     18     * @ticket 53443
    919     *
    10      * @covers ::update_posts_count
     20     * @covers ::_update_posts_count_on_transition_post_status
     21     * @covers ::_update_posts_count_on_delete
    1122     */
    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 );
    1326
    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 );
    1642         *
    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 );
    1951         *
    20          * @covers ::_update_posts_count_on_transition_post_status
    21          * @covers ::_update_posts_count_on_delete
     52         * Check that _update_posts_count_on_delete() is called on that filter,
     53         * which then calls update_posts_count() to update the count.
    2254         */
    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.' );
    5756    }
    58 
    59 endif;
     57}
Note: See TracChangeset for help on using the changeset viewer.