Make WordPress Core


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

    r51869 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * Tests specific to `get_space_allowed()` in multisite.
     5 *
     6 * @group ms-required
     7 * @group multisite
     8 */
     9class Tests_Multisite_GetSpaceAllowed extends WP_UnitTestCase {
    410
    511    /**
    6      * Tests specific to `get_space_allowed()` in multisite.
    7      *
    8      * @group multisite
     12     * When no option exists for the site or the network, a fallback of
     13     * 100 is expected.
    914     */
    10     class Tests_Multisite_GetSpaceAllowed extends WP_UnitTestCase {
     15    public function test_get_space_allowed_default() {
     16        delete_option( 'blog_upload_space' );
     17        delete_site_option( 'blog_upload_space' );
    1118
    12         /**
    13          * When no option exists for the site or the network, a fallback of
    14          * 100 is expected.
    15          */
    16         public function test_get_space_allowed_default() {
    17             delete_option( 'blog_upload_space' );
    18             delete_site_option( 'blog_upload_space' );
    19 
    20             $this->assertSame( 100, get_space_allowed() );
    21         }
    22 
    23         /**
    24          * If an individual site's option is not available, the default network
    25          * level option is used as a fallback.
    26          */
    27         public function test_get_space_allowed_no_site_option_fallback_to_network_option() {
    28             delete_site_option( 'blog_upload_space' );
    29             update_site_option( 'blog_upload_space', 200 );
    30 
    31             $this->assertSame( 200, get_space_allowed() );
    32         }
    33 
    34         /**
    35          * @dataProvider data_blog_upload_space
    36          *
    37          * @param mixed $site_option    Option to assign to the site's `blog_upload_space`.
    38          * @param mixed $network_option Option to assign to the network's `blog_upload_space`.
    39          * @param int   $expected       Expected return value.
    40          */
    41         public function test_get_space_allowed( $site_option, $network_option, $expected ) {
    42             update_option( 'blog_upload_space', $site_option );
    43             update_site_option( 'blog_upload_space', $network_option );
    44 
    45             $this->assertSame( $expected, get_space_allowed() );
    46         }
    47 
    48         public function data_blog_upload_space() {
    49             return array(
    50                 // A valid site option will be preferred over a network option.
    51                 array( 111, 200, 111 ),
    52                 array( -1, 200, -1 ),
    53                 array( 222, 0, 222 ),
    54 
    55                 // Non-numeric site options should result in a fallback to the network option.
    56                 array( '', 333, 333 ),
    57                 array( false, 444, 444 ),
    58                 array( 'NAN', 555, 555 ),
    59                 array( false, -10, -10 ),
    60 
    61                 // If neither network or site options are valid, fallback to the default.
    62                 array( false, false, 100 ),
    63                 array( 'NAN', 'NAN', 100 ),
    64 
    65                 // These effectively disable uploads.
    66                 array( 0, 666, 0 ),
    67                 array( false, 0, 0 ),
    68                 array( 'NAN', 0, 0 ),
    69             );
    70         }
    71 
    72         public function test_get_space_allowed_filtered() {
    73             update_option( 'blog_upload_space', 777 );
    74             update_site_option( 'blog_upload_space', 888 );
    75 
    76             add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
    77             $space_allowed = get_space_allowed();
    78             remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
    79 
    80             $this->assertSame( 999, $space_allowed );
    81         }
    82 
    83         public function _filter_space_allowed() {
    84             return 999;
    85         }
     19        $this->assertSame( 100, get_space_allowed() );
    8620    }
    8721
    88 endif;
     22    /**
     23     * If an individual site's option is not available, the default network
     24     * level option is used as a fallback.
     25     */
     26    public function test_get_space_allowed_no_site_option_fallback_to_network_option() {
     27        delete_site_option( 'blog_upload_space' );
     28        update_site_option( 'blog_upload_space', 200 );
     29
     30        $this->assertSame( 200, get_space_allowed() );
     31    }
     32
     33    /**
     34     * @dataProvider data_blog_upload_space
     35     *
     36     * @param mixed $site_option    Option to assign to the site's `blog_upload_space`.
     37     * @param mixed $network_option Option to assign to the network's `blog_upload_space`.
     38     * @param int   $expected       Expected return value.
     39     */
     40    public function test_get_space_allowed( $site_option, $network_option, $expected ) {
     41        update_option( 'blog_upload_space', $site_option );
     42        update_site_option( 'blog_upload_space', $network_option );
     43
     44        $this->assertSame( $expected, get_space_allowed() );
     45    }
     46
     47    public function data_blog_upload_space() {
     48        return array(
     49            // A valid site option will be preferred over a network option.
     50            array( 111, 200, 111 ),
     51            array( -1, 200, -1 ),
     52            array( 222, 0, 222 ),
     53
     54            // Non-numeric site options should result in a fallback to the network option.
     55            array( '', 333, 333 ),
     56            array( false, 444, 444 ),
     57            array( 'NAN', 555, 555 ),
     58            array( false, -10, -10 ),
     59
     60            // If neither network or site options are valid, fallback to the default.
     61            array( false, false, 100 ),
     62            array( 'NAN', 'NAN', 100 ),
     63
     64            // These effectively disable uploads.
     65            array( 0, 666, 0 ),
     66            array( false, 0, 0 ),
     67            array( 'NAN', 0, 0 ),
     68        );
     69    }
     70
     71    public function test_get_space_allowed_filtered() {
     72        update_option( 'blog_upload_space', 777 );
     73        update_site_option( 'blog_upload_space', 888 );
     74
     75        add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
     76        $space_allowed = get_space_allowed();
     77        remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
     78
     79        $this->assertSame( 999, $space_allowed );
     80    }
     81
     82    public function _filter_space_allowed() {
     83        return 999;
     84    }
     85}
Note: See TracChangeset for help on using the changeset viewer.