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/theme/wpThemeGetAllowedFilters.php

    r57107 r60148  
    11<?php
    2 if ( is_multisite() ) :
     2
     3/**
     4 * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions.
     5 *
     6 * @group ms-required
     7 * @group multisite
     8 * @group themes
     9 */
     10class Tests_Theme_wpThemeGetAllowedFilters extends WP_UnitTestCase {
    311    /**
    4      * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions.
    5      *
    6      * @group themes
    7      * @group multisite
     12     * @var array List of themes allowed before filters are applied.
    813     */
    9     class Tests_Theme_wpThemeGetAllowedFilters extends WP_UnitTestCase {
    10         /**
    11          * @var array List of themes allowed before filters are applied.
    12          */
    13         protected $default_allowed;
     14    protected $default_allowed;
    1415
    15         protected $filter_network_allowed_themes_args;
     16    protected $filter_network_allowed_themes_args;
    1617
    17         public function test_network_allowed_themes_filter_sends_blog_id() {
    18             $blog_id = 1;
     18    public function test_network_allowed_themes_filter_sends_blog_id() {
     19        $blog_id = 1;
    1920
    20             add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
    21             WP_Theme::get_allowed( $blog_id );
    22             remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) );
     21        add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
     22        WP_Theme::get_allowed( $blog_id );
     23        remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) );
    2324
    24             $this->assertCount( 2, $this->filter_network_allowed_themes_args );
    25             $this->assertSame( $blog_id, $this->filter_network_allowed_themes_args[1] );
    26         }
     25        $this->assertCount( 2, $this->filter_network_allowed_themes_args );
     26        $this->assertSame( $blog_id, $this->filter_network_allowed_themes_args[1] );
     27    }
    2728
    28         /**
    29         * Test the `allowed_themes` filter, which filters themes allowed on a network.
    30         */
    31         public function test_wp_theme_get_allowed_with_allowed_themes_filter() {
    32             $blog_id = 1;
     29    /**
     30    * Test the `allowed_themes` filter, which filters themes allowed on a network.
     31    */
     32    public function test_wp_theme_get_allowed_with_allowed_themes_filter() {
     33        $blog_id = 1;
    3334
    34             $this->default_allowed = WP_Theme::get_allowed( $blog_id );
     35        $this->default_allowed = WP_Theme::get_allowed( $blog_id );
    3536
    36             add_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
    37             $allowed = WP_Theme::get_allowed( $blog_id );
    38             remove_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
     37        add_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
     38        $allowed = WP_Theme::get_allowed( $blog_id );
     39        remove_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
    3940
    40             $expected = $this->default_allowed + array( 'allow-on-network' => true );
     41        $expected = $this->default_allowed + array( 'allow-on-network' => true );
    4142
    42             $this->assertSame( $expected, $allowed );
    43         }
     43        $this->assertSame( $expected, $allowed );
     44    }
    4445
    45         /**
    46         * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`.
    47         */
    48         public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() {
    49             $blog_id = 1;
     46    /**
     47    * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`.
     48    */
     49    public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() {
     50        $blog_id = 1;
    5051
    51             $this->default_allowed = WP_Theme::get_allowed( $blog_id );
     52        $this->default_allowed = WP_Theme::get_allowed( $blog_id );
    5253
    53             add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
    54             $allowed = WP_Theme::get_allowed( $blog_id );
    55             remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 );
     54        add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
     55        $allowed = WP_Theme::get_allowed( $blog_id );
     56        remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 );
    5657
    57             $expected = $this->default_allowed + array( 'network-allowed-theme' => true );
     58        $expected = $this->default_allowed + array( 'network-allowed-theme' => true );
    5859
    59             $this->assertSame( $expected, $allowed );
    60         }
     60        $this->assertSame( $expected, $allowed );
     61    }
    6162
    62         /**
    63         * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.
    64         */
    65         public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() {
    66             $blog_id = 1;
     63    /**
     64    * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.
     65    */
     66    public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() {
     67        $blog_id = 1;
    6768
    68             $this->default_allowed = WP_Theme::get_allowed( $blog_id );
     69        $this->default_allowed = WP_Theme::get_allowed( $blog_id );
    6970
    70             add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 );
    71             $allowed = WP_Theme::get_allowed( $blog_id );
    72             remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 );
     71        add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 );
     72        $allowed = WP_Theme::get_allowed( $blog_id );
     73        remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 );
    7374
    74             $expected = $this->default_allowed + array( 'site-allowed-theme' => true );
     75        $expected = $this->default_allowed + array( 'site-allowed-theme' => true );
    7576
    76             $this->assertSame( $expected, $allowed );
    77         }
     77        $this->assertSame( $expected, $allowed );
     78    }
    7879
    79         public function filter_allowed_themes( $allowed_themes ) {
    80             $allowed_themes['allow-on-network'] = true;
     80    public function filter_allowed_themes( $allowed_themes ) {
     81        $allowed_themes['allow-on-network'] = true;
    8182
    82             return $allowed_themes;
    83         }
     83        return $allowed_themes;
     84    }
    8485
    85         public function filter_network_allowed_themes( $allowed_themes, $blog_id ) {
    86             $this->filter_network_allowed_themes_args = func_get_args();
     86    public function filter_network_allowed_themes( $allowed_themes, $blog_id ) {
     87        $this->filter_network_allowed_themes_args = func_get_args();
    8788
    88             $allowed_themes['network-allowed-theme'] = true;
     89        $allowed_themes['network-allowed-theme'] = true;
    8990
    90             return $allowed_themes;
    91         }
     91        return $allowed_themes;
     92    }
    9293
    93         public function filter_site_allowed_themes( $allowed_themes, $blog_id ) {
    94             $allowed_themes['site-allowed-theme'] = true;
     94    public function filter_site_allowed_themes( $allowed_themes, $blog_id ) {
     95        $allowed_themes['site-allowed-theme'] = true;
    9596
    96             return $allowed_themes;
    97         }
     97        return $allowed_themes;
    9898    }
    99 endif;
     99}
Note: See TracChangeset for help on using the changeset viewer.