Make WordPress Core


Ignore:
Timestamp:
04/09/2025 01:29:39 PM (19 months 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/wpCountSites.php

    r54726 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * @group ms-required
     5 * @group ms-site
     6 * @group multisite
     7 */
     8class Tests_Multisite_wpCountSites extends WP_UnitTestCase {
    49
    510        /**
    6          * @group ms-site
    7          * @group multisite
     11         * @ticket 37392
    812         */
    9         class Tests_Multisite_wpCountSites extends WP_UnitTestCase {
     13        public function test_wp_count_sites() {
     14                // Create a random number of sites with each status.
     15                $site_ids = array(
     16                        'public'   => self::factory()->blog->create_many(
     17                                random_int( 0, 5 ),
     18                                array(
     19                                        'public' => 1,
     20                                )
     21                        ),
     22                        'archived' => self::factory()->blog->create_many(
     23                                random_int( 0, 5 ),
     24                                array(
     25                                        'public'   => 0,
     26                                        'archived' => 1,
     27                                )
     28                        ),
     29                        'mature'   => self::factory()->blog->create_many(
     30                                random_int( 0, 5 ),
     31                                array(
     32                                        'public' => 0,
     33                                        'mature' => 1,
     34                                )
     35                        ),
     36                        'spam'     => self::factory()->blog->create_many(
     37                                random_int( 0, 5 ),
     38                                array(
     39                                        'public' => 0,
     40                                        'spam'   => 1,
     41                                )
     42                        ),
     43                        'deleted'  => self::factory()->blog->create_many(
     44                                random_int( 0, 5 ),
     45                                array(
     46                                        'public'  => 0,
     47                                        'deleted' => 1,
     48                                )
     49                        ),
     50                );
    1051
    11                 /**
    12                  * @ticket 37392
    13                  */
    14                 public function test_wp_count_sites() {
    15                         // Create a random number of sites with each status.
    16                         $site_ids = array(
    17                                 'public'   => self::factory()->blog->create_many(
    18                                         random_int( 0, 5 ),
    19                                         array(
    20                                                 'public' => 1,
    21                                         )
    22                                 ),
    23                                 'archived' => self::factory()->blog->create_many(
    24                                         random_int( 0, 5 ),
    25                                         array(
    26                                                 'public'   => 0,
    27                                                 'archived' => 1,
    28                                         )
    29                                 ),
    30                                 'mature'   => self::factory()->blog->create_many(
    31                                         random_int( 0, 5 ),
    32                                         array(
    33                                                 'public' => 0,
    34                                                 'mature' => 1,
    35                                         )
    36                                 ),
    37                                 'spam'     => self::factory()->blog->create_many(
    38                                         random_int( 0, 5 ),
    39                                         array(
    40                                                 'public' => 0,
    41                                                 'spam'   => 1,
    42                                         )
    43                                 ),
    44                                 'deleted'  => self::factory()->blog->create_many(
    45                                         random_int( 0, 5 ),
    46                                         array(
    47                                                 'public'  => 0,
    48                                                 'deleted' => 1,
    49                                         )
    50                                 ),
    51                         );
     52                $counts = wp_count_sites();
    5253
    53                         $counts = wp_count_sites();
     54                $counts_by_status = array_map( 'count', $site_ids );
     55                $expected         = array_merge(
     56                        array( 'all' => array_sum( $counts_by_status ) ),
     57                        $counts_by_status
     58                );
     59                // Add 1 to all & public for the main site.
     60                $expected['all']    += 1;
     61                $expected['public'] += 1;
    5462
    55                         $counts_by_status = array_map( 'count', $site_ids );
    56                         $expected         = array_merge(
    57                                 array( 'all' => array_sum( $counts_by_status ) ),
    58                                 $counts_by_status
    59                         );
    60                         // Add 1 to all & public for the main site.
    61                         $expected['all']    += 1;
    62                         $expected['public'] += 1;
    63 
    64                         $this->assertSame( $expected, $counts );
    65                 }
     63                $this->assertSame( $expected, $counts );
    6664        }
    67 
    68 endif;
     65}
Note: See TracChangeset for help on using the changeset viewer.