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/wpMsSitesListTable.php

    r54215 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * @group admin
     5 * @group ms-required
     6 * @group network-admin
     7 */
     8class Tests_Multisite_wpMsSitesListTable extends WP_UnitTestCase {
     9
     10    protected static $site_ids;
    411
    512    /**
    6      * @group admin
    7      * @group network-admin
     13     * @var WP_MS_Sites_List_Table
    814     */
    9     class Tests_Multisite_wpMsSitesListTable extends WP_UnitTestCase {
    10         protected static $site_ids;
    11 
    12         /**
    13          * @var WP_MS_Sites_List_Table
    14          */
    15         public $table = false;
    16 
    17         public function set_up() {
    18             parent::set_up();
    19             $this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) );
    20         }
    21 
    22         public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    23             self::$site_ids = array(
    24                 'wordpress.org/'          => array(
    25                     'domain' => 'wordpress.org',
    26                     'path'   => '/',
    27                 ),
    28                 'wordpress.org/foo/'      => array(
    29                     'domain' => 'wordpress.org',
    30                     'path'   => '/foo/',
    31                 ),
    32                 'wordpress.org/foo/bar/'  => array(
    33                     'domain' => 'wordpress.org',
    34                     'path'   => '/foo/bar/',
    35                 ),
    36                 'wordpress.org/afoo/'     => array(
    37                     'domain' => 'wordpress.org',
    38                     'path'   => '/afoo/',
    39                 ),
    40                 'make.wordpress.org/'     => array(
    41                     'domain' => 'make.wordpress.org',
    42                     'path'   => '/',
    43                 ),
    44                 'make.wordpress.org/foo/' => array(
    45                     'domain' => 'make.wordpress.org',
    46                     'path'   => '/foo/',
    47                 ),
    48                 'www.w.org/'              => array(
    49                     'domain' => 'www.w.org',
    50                     'path'   => '/',
    51                 ),
    52                 'www.w.org/foo/'          => array(
    53                     'domain' => 'www.w.org',
    54                     'path'   => '/foo/',
    55                 ),
    56                 'www.w.org/foo/bar/'      => array(
    57                     'domain' => 'www.w.org',
    58                     'path'   => '/foo/bar/',
    59                 ),
    60                 'test.example.org/'       => array(
    61                     'domain' => 'test.example.org',
    62                     'path'   => '/',
    63                 ),
    64                 'test2.example.org/'      => array(
    65                     'domain' => 'test2.example.org',
    66                     'path'   => '/',
    67                 ),
    68                 'test3.example.org/zig/'  => array(
    69                     'domain' => 'test3.example.org',
    70                     'path'   => '/zig/',
    71                 ),
    72                 'atest.example.org/'      => array(
    73                     'domain' => 'atest.example.org',
    74                     'path'   => '/',
    75                 ),
    76             );
    77 
    78             foreach ( self::$site_ids as &$id ) {
    79                 $id = $factory->blog->create( $id );
    80             }
    81             unset( $id );
    82         }
    83 
    84         public static function wpTearDownAfterClass() {
    85             foreach ( self::$site_ids as $site_id ) {
    86                 wp_delete_site( $site_id );
    87             }
    88         }
    89 
    90         public function test_ms_sites_list_table_default_items() {
    91             $this->table->prepare_items();
    92 
    93             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    94             $items = array_map( 'intval', $items );
    95 
    96             $this->assertSameSets( array( 1 ) + self::$site_ids, $items );
    97         }
    98 
    99         public function test_ms_sites_list_table_subdirectory_path_search_items() {
    100             if ( is_subdomain_install() ) {
    101                 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
    102             }
    103 
    104             $_REQUEST['s'] = 'foo';
    105 
    106             $this->table->prepare_items();
    107 
    108             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    109             $items = array_map( 'intval', $items );
    110 
    111             unset( $_REQUEST['s'] );
    112 
    113             $expected = array(
    114                 self::$site_ids['wordpress.org/foo/'],
    115                 self::$site_ids['wordpress.org/foo/bar/'],
    116                 self::$site_ids['wordpress.org/afoo/'],
    117                 self::$site_ids['make.wordpress.org/foo/'],
    118                 self::$site_ids['www.w.org/foo/'],
    119                 self::$site_ids['www.w.org/foo/bar/'],
    120             );
    121 
    122             $this->assertSameSets( $expected, $items );
    123         }
    124 
    125         public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() {
    126             if ( is_subdomain_install() ) {
    127                 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
    128             }
    129 
    130             $_REQUEST['s'] = 'foo/bar';
    131 
    132             $this->table->prepare_items();
    133 
    134             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    135             $items = array_map( 'intval', $items );
    136 
    137             unset( $_REQUEST['s'] );
    138 
    139             $expected = array(
    140                 self::$site_ids['wordpress.org/foo/bar/'],
    141                 self::$site_ids['www.w.org/foo/bar/'],
    142             );
    143 
    144             $this->assertSameSets( $expected, $items );
    145         }
    146 
    147         public function test_ms_sites_list_table_invalid_path_search_items() {
    148             $_REQUEST['s'] = 'foobar';
    149 
    150             $this->table->prepare_items();
    151 
    152             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    153             $items = array_map( 'intval', $items );
    154 
    155             unset( $_REQUEST['s'] );
    156 
    157             $this->assertEmpty( $items );
    158         }
    159 
    160         public function test_ms_sites_list_table_subdomain_domain_search_items() {
    161             if ( ! is_subdomain_install() ) {
    162                 $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
    163             }
    164 
    165             $_REQUEST['s'] = 'test';
    166 
    167             $this->table->prepare_items();
    168 
    169             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    170             $items = array_map( 'intval', $items );
    171 
    172             unset( $_REQUEST['s'] );
    173 
    174             $expected = array(
    175                 self::$site_ids['test.example.org/'],
    176                 self::$site_ids['test2.example.org/'],
    177                 self::$site_ids['test3.example.org/zig/'],
    178                 self::$site_ids['atest.example.org/'],
    179             );
    180 
    181             $this->assertSameSets( $expected, $items );
    182         }
    183 
    184         public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() {
    185             if ( ! is_subdomain_install() ) {
    186                 $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
    187             }
    188 
    189             $_REQUEST['s'] = 'test*';
    190 
    191             $this->table->prepare_items();
    192 
    193             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    194             $items = array_map( 'intval', $items );
    195 
    196             unset( $_REQUEST['s'] );
    197 
    198             $expected = array(
    199                 self::$site_ids['test.example.org/'],
    200                 self::$site_ids['test2.example.org/'],
    201                 self::$site_ids['test3.example.org/zig/'],
    202                 self::$site_ids['atest.example.org/'],
    203             );
    204 
    205             $this->assertSameSets( $expected, $items );
    206         }
    207 
    208         public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() {
    209             if ( is_subdomain_install() ) {
    210                 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
    211             }
    212 
    213             $_REQUEST['s'] = 'fo*';
    214 
    215             $this->table->prepare_items();
    216 
    217             $items = wp_list_pluck( $this->table->items, 'blog_id' );
    218             $items = array_map( 'intval', $items );
    219 
    220             unset( $_REQUEST['s'] );
    221 
    222             $expected = array(
    223                 self::$site_ids['wordpress.org/foo/'],
    224                 self::$site_ids['wordpress.org/foo/bar/'],
    225                 self::$site_ids['wordpress.org/afoo/'],
    226                 self::$site_ids['make.wordpress.org/foo/'],
    227                 self::$site_ids['www.w.org/foo/'],
    228                 self::$site_ids['www.w.org/foo/bar/'],
    229             );
    230 
    231             $this->assertSameSets( $expected, $items );
    232         }
    233 
    234         /**
    235          * @ticket 42066
    236          */
    237         public function test_get_views_should_return_views_by_default() {
    238             $expected = array(
    239                 'all'    => '<a href="sites.php" class="current" aria-current="page">All <span class="count">(14)</span></a>',
    240                 'public' => '<a href="sites.php?status=public">Public <span class="count">(14)</span></a>',
    241             );
    242 
    243             $this->assertSame( $expected, $this->table->get_views() );
    244         }
    245     }
    246 endif;
     15    public $table = false;
     16
     17    public function set_up() {
     18        parent::set_up();
     19        $this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) );
     20    }
     21
     22    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     23        self::$site_ids = array(
     24            'wordpress.org/'          => array(
     25                'domain' => 'wordpress.org',
     26                'path'   => '/',
     27            ),
     28            'wordpress.org/foo/'      => array(
     29                'domain' => 'wordpress.org',
     30                'path'   => '/foo/',
     31            ),
     32            'wordpress.org/foo/bar/'  => array(
     33                'domain' => 'wordpress.org',
     34                'path'   => '/foo/bar/',
     35            ),
     36            'wordpress.org/afoo/'     => array(
     37                'domain' => 'wordpress.org',
     38                'path'   => '/afoo/',
     39            ),
     40            'make.wordpress.org/'     => array(
     41                'domain' => 'make.wordpress.org',
     42                'path'   => '/',
     43            ),
     44            'make.wordpress.org/foo/' => array(
     45                'domain' => 'make.wordpress.org',
     46                'path'   => '/foo/',
     47            ),
     48            'www.w.org/'              => array(
     49                'domain' => 'www.w.org',
     50                'path'   => '/',
     51            ),
     52            'www.w.org/foo/'          => array(
     53                'domain' => 'www.w.org',
     54                'path'   => '/foo/',
     55            ),
     56            'www.w.org/foo/bar/'      => array(
     57                'domain' => 'www.w.org',
     58                'path'   => '/foo/bar/',
     59            ),
     60            'test.example.org/'       => array(
     61                'domain' => 'test.example.org',
     62                'path'   => '/',
     63            ),
     64            'test2.example.org/'      => array(
     65                'domain' => 'test2.example.org',
     66                'path'   => '/',
     67            ),
     68            'test3.example.org/zig/'  => array(
     69                'domain' => 'test3.example.org',
     70                'path'   => '/zig/',
     71            ),
     72            'atest.example.org/'      => array(
     73                'domain' => 'atest.example.org',
     74                'path'   => '/',
     75            ),
     76        );
     77
     78        foreach ( self::$site_ids as &$id ) {
     79            $id = $factory->blog->create( $id );
     80        }
     81        unset( $id );
     82    }
     83
     84    public static function wpTearDownAfterClass() {
     85        foreach ( self::$site_ids as $site_id ) {
     86            wp_delete_site( $site_id );
     87        }
     88    }
     89
     90    public function test_ms_sites_list_table_default_items() {
     91        $this->table->prepare_items();
     92
     93        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     94        $items = array_map( 'intval', $items );
     95
     96        $this->assertSameSets( array( 1 ) + self::$site_ids, $items );
     97    }
     98
     99    public function test_ms_sites_list_table_subdirectory_path_search_items() {
     100        if ( is_subdomain_install() ) {
     101            $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
     102        }
     103
     104        $_REQUEST['s'] = 'foo';
     105
     106        $this->table->prepare_items();
     107
     108        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     109        $items = array_map( 'intval', $items );
     110
     111        unset( $_REQUEST['s'] );
     112
     113        $expected = array(
     114            self::$site_ids['wordpress.org/foo/'],
     115            self::$site_ids['wordpress.org/foo/bar/'],
     116            self::$site_ids['wordpress.org/afoo/'],
     117            self::$site_ids['make.wordpress.org/foo/'],
     118            self::$site_ids['www.w.org/foo/'],
     119            self::$site_ids['www.w.org/foo/bar/'],
     120        );
     121
     122        $this->assertSameSets( $expected, $items );
     123    }
     124
     125    public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() {
     126        if ( is_subdomain_install() ) {
     127            $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
     128        }
     129
     130        $_REQUEST['s'] = 'foo/bar';
     131
     132        $this->table->prepare_items();
     133
     134        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     135        $items = array_map( 'intval', $items );
     136
     137        unset( $_REQUEST['s'] );
     138
     139        $expected = array(
     140            self::$site_ids['wordpress.org/foo/bar/'],
     141            self::$site_ids['www.w.org/foo/bar/'],
     142        );
     143
     144        $this->assertSameSets( $expected, $items );
     145    }
     146
     147    public function test_ms_sites_list_table_invalid_path_search_items() {
     148        $_REQUEST['s'] = 'foobar';
     149
     150        $this->table->prepare_items();
     151
     152        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     153        $items = array_map( 'intval', $items );
     154
     155        unset( $_REQUEST['s'] );
     156
     157        $this->assertEmpty( $items );
     158    }
     159
     160    public function test_ms_sites_list_table_subdomain_domain_search_items() {
     161        if ( ! is_subdomain_install() ) {
     162            $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
     163        }
     164
     165        $_REQUEST['s'] = 'test';
     166
     167        $this->table->prepare_items();
     168
     169        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     170        $items = array_map( 'intval', $items );
     171
     172        unset( $_REQUEST['s'] );
     173
     174        $expected = array(
     175            self::$site_ids['test.example.org/'],
     176            self::$site_ids['test2.example.org/'],
     177            self::$site_ids['test3.example.org/zig/'],
     178            self::$site_ids['atest.example.org/'],
     179        );
     180
     181        $this->assertSameSets( $expected, $items );
     182    }
     183
     184    public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() {
     185        if ( ! is_subdomain_install() ) {
     186            $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
     187        }
     188
     189        $_REQUEST['s'] = 'test*';
     190
     191        $this->table->prepare_items();
     192
     193        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     194        $items = array_map( 'intval', $items );
     195
     196        unset( $_REQUEST['s'] );
     197
     198        $expected = array(
     199            self::$site_ids['test.example.org/'],
     200            self::$site_ids['test2.example.org/'],
     201            self::$site_ids['test3.example.org/zig/'],
     202            self::$site_ids['atest.example.org/'],
     203        );
     204
     205        $this->assertSameSets( $expected, $items );
     206    }
     207
     208    public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() {
     209        if ( is_subdomain_install() ) {
     210            $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
     211        }
     212
     213        $_REQUEST['s'] = 'fo*';
     214
     215        $this->table->prepare_items();
     216
     217        $items = wp_list_pluck( $this->table->items, 'blog_id' );
     218        $items = array_map( 'intval', $items );
     219
     220        unset( $_REQUEST['s'] );
     221
     222        $expected = array(
     223            self::$site_ids['wordpress.org/foo/'],
     224            self::$site_ids['wordpress.org/foo/bar/'],
     225            self::$site_ids['wordpress.org/afoo/'],
     226            self::$site_ids['make.wordpress.org/foo/'],
     227            self::$site_ids['www.w.org/foo/'],
     228            self::$site_ids['www.w.org/foo/bar/'],
     229        );
     230
     231        $this->assertSameSets( $expected, $items );
     232    }
     233
     234    /**
     235     * @ticket 42066
     236     */
     237    public function test_get_views_should_return_views_by_default() {
     238        $expected = array(
     239            'all'    => '<a href="sites.php" class="current" aria-current="page">All <span class="count">(14)</span></a>',
     240            'public' => '<a href="sites.php?status=public">Public <span class="count">(14)</span></a>',
     241        );
     242
     243        $this->assertSame( $expected, $this->table->get_views() );
     244    }
     245}
Note: See TracChangeset for help on using the changeset viewer.