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

    r51860 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * Test 'site_details' functionality.
     5 *
     6 * @group ms-required
     7 * @group ms-site
     8 * @group multisite
     9 */
     10class Tests_Multisite_SiteDetails extends WP_UnitTestCase {
     11
    412    /**
    5      * Test 'site_details' functionality.
     13     * @dataProvider data_allowed_options
    614     *
    7      * @group ms-site
    8      * @group multisite
     15     * @ticket 40063
    916     */
    10     class Tests_Multisite_SiteDetails extends WP_UnitTestCase {
    11         /**
    12          * @dataProvider data_allowed_options
    13          *
    14          * @ticket 40063
    15          */
    16         public function test_update_allowed_option_deletes_site_details_cache( $allowed_option, $temporary_value ) {
    17             $site = get_site();
     17    public function test_update_allowed_option_deletes_site_details_cache( $allowed_option, $temporary_value ) {
     18        $site = get_site();
    1819
    19             $original_value = $site->$allowed_option;
    20             update_option( $allowed_option, $temporary_value );
     20        $original_value = $site->$allowed_option;
     21        update_option( $allowed_option, $temporary_value );
    2122
    22             $cached_result = wp_cache_get( $site->id, 'site-details' );
     23        $cached_result = wp_cache_get( $site->id, 'site-details' );
    2324
    24             /* Reset to original value. */
    25             update_option( $allowed_option, $original_value );
     25        /* Reset to original value. */
     26        update_option( $allowed_option, $original_value );
    2627
    27             $this->assertFalse( $cached_result );
    28         }
    29 
    30         /**
    31          * @dataProvider data_allowed_options
    32          *
    33          * @ticket 40063
    34          */
    35         public function test_update_allowed_option_deletes_blog_details_cache( $allowed_option, $temporary_value ) {
    36             $blog_details = get_blog_details();
    37 
    38             $original_value = $blog_details->$allowed_option;
    39             update_option( $allowed_option, $temporary_value );
    40 
    41             $cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
    42 
    43             /* Reset to original value. */
    44             update_option( $allowed_option, $original_value );
    45 
    46             $this->assertFalse( $cached_result );
    47         }
    48 
    49         /**
    50          * @dataProvider data_allowed_options
    51          *
    52          * @ticket 40063
    53          */
    54         public function test_update_allowed_option_does_not_delete_site_cache( $allowed_option, $temporary_value ) {
    55             $site = get_site();
    56 
    57             $original_value = $site->$allowed_option;
    58             update_option( $allowed_option, $temporary_value );
    59 
    60             $cached_result = wp_cache_get( $site->id, 'sites' );
    61 
    62             /* Reset to original value. */
    63             update_option( $allowed_option, $original_value );
    64 
    65             $this->assertNotFalse( $cached_result );
    66         }
    67 
    68         /**
    69          * @dataProvider data_allowed_options
    70          *
    71          * @ticket 40063
    72          */
    73         public function test_update_allowed_option_does_not_delete_short_blog_details_cache( $allowed_option, $temporary_value ) {
    74             $blog_details = get_blog_details( null, false );
    75 
    76             $original_value = get_option( $allowed_option );
    77             update_option( $allowed_option, $temporary_value );
    78 
    79             $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
    80 
    81             /* Reset to original value. */
    82             update_option( $allowed_option, $original_value );
    83 
    84             $this->assertNotFalse( $cached_result );
    85         }
    86 
    87         /**
    88          * @dataProvider data_allowed_options
    89          *
    90          * @ticket 40063
    91          */
    92         public function test_update_allowed_option_does_not_update_sites_last_changed( $allowed_option, $temporary_value ) {
    93             $last_changed = wp_cache_get_last_changed( 'sites' );
    94 
    95             $original_value = get_option( $allowed_option );
    96             update_option( $allowed_option, $temporary_value );
    97 
    98             $new_last_changed = wp_cache_get_last_changed( 'sites' );
    99 
    100             /* Reset to original value. */
    101             update_option( $allowed_option, $original_value );
    102 
    103             $this->assertSame( $new_last_changed, $last_changed );
    104         }
    105 
    106         public function data_allowed_options() {
    107             return array(
    108                 array( 'blogname', 'Custom Site' ),
    109                 array( 'home', 'http://custom-site-url.org' ),
    110                 array( 'siteurl', 'http://custom-site-url.org' ),
    111                 array( 'post_count', '4' ),
    112             );
    113         }
    114 
    115         /**
    116          * @ticket 40063
    117          */
    118         public function test_update_random_blog_option_does_not_delete_cache() {
    119             $site = get_site();
    120 
    121             update_option( 'foobar_option', 'foobar_value' );
    122             $cached_result = wp_cache_get( $site->id, 'sites' );
    123 
    124             delete_option( 'foobar_option' );
    125 
    126             $this->assertNotFalse( $cached_result );
    127         }
    128 
    129         /**
    130          * @ticket 40247
    131          */
    132         public function test_site_details_cached_including_false_values() {
    133             $id = self::factory()->blog->create();
    134 
    135             $site = get_site( $id );
    136 
    137             // Trigger retrieving site details (post_count is not set on new sites).
    138             $post_count = $site->post_count;
    139 
    140             $cached_details = wp_cache_get( $site->id, 'site-details' );
    141 
    142             wp_delete_site( $id );
    143             wp_update_network_site_counts();
    144 
    145             $this->assertNotFalse( $cached_details );
    146         }
    147 
    148         public function test_site_details_filter_with_blogname() {
    149             add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
    150             $site     = get_site();
    151             $blogname = $site->blogname;
    152             remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
    153 
    154             $this->assertSame( 'Foo Bar', $blogname );
    155         }
    156 
    157         public function _filter_site_details_blogname( $details ) {
    158             $details->blogname = 'Foo Bar';
    159             return $details;
    160         }
    161 
    162         /**
    163          * @ticket 40458
    164          */
    165         public function test_site_details_filter_with_custom_value_isetter() {
    166             add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
    167             $site               = get_site();
    168             $custom_value_isset = isset( $site->custom_value );
    169             remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
    170 
    171             $this->assertTrue( $custom_value_isset );
    172         }
    173 
    174         /**
    175          * @ticket 40458
    176          */
    177         public function test_site_details_filter_with_custom_value_getter() {
    178             add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
    179             $site         = get_site();
    180             $custom_value = $site->custom_value;
    181             remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
    182 
    183             $this->assertSame( 'foo', $custom_value );
    184         }
    185 
    186         public function _filter_site_details_custom_value( $details ) {
    187             $details->custom_value = 'foo';
    188             return $details;
    189         }
     28        $this->assertFalse( $cached_result );
    19029    }
    19130
    192 endif;
     31    /**
     32     * @dataProvider data_allowed_options
     33     *
     34     * @ticket 40063
     35     */
     36    public function test_update_allowed_option_deletes_blog_details_cache( $allowed_option, $temporary_value ) {
     37        $blog_details = get_blog_details();
     38
     39        $original_value = $blog_details->$allowed_option;
     40        update_option( $allowed_option, $temporary_value );
     41
     42        $cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
     43
     44        /* Reset to original value. */
     45        update_option( $allowed_option, $original_value );
     46
     47        $this->assertFalse( $cached_result );
     48    }
     49
     50    /**
     51     * @dataProvider data_allowed_options
     52     *
     53     * @ticket 40063
     54     */
     55    public function test_update_allowed_option_does_not_delete_site_cache( $allowed_option, $temporary_value ) {
     56        $site = get_site();
     57
     58        $original_value = $site->$allowed_option;
     59        update_option( $allowed_option, $temporary_value );
     60
     61        $cached_result = wp_cache_get( $site->id, 'sites' );
     62
     63        /* Reset to original value. */
     64        update_option( $allowed_option, $original_value );
     65
     66        $this->assertNotFalse( $cached_result );
     67    }
     68
     69    /**
     70     * @dataProvider data_allowed_options
     71     *
     72     * @ticket 40063
     73     */
     74    public function test_update_allowed_option_does_not_delete_short_blog_details_cache( $allowed_option, $temporary_value ) {
     75        $blog_details = get_blog_details( null, false );
     76
     77        $original_value = get_option( $allowed_option );
     78        update_option( $allowed_option, $temporary_value );
     79
     80        $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
     81
     82        /* Reset to original value. */
     83        update_option( $allowed_option, $original_value );
     84
     85        $this->assertNotFalse( $cached_result );
     86    }
     87
     88    /**
     89     * @dataProvider data_allowed_options
     90     *
     91     * @ticket 40063
     92     */
     93    public function test_update_allowed_option_does_not_update_sites_last_changed( $allowed_option, $temporary_value ) {
     94        $last_changed = wp_cache_get_last_changed( 'sites' );
     95
     96        $original_value = get_option( $allowed_option );
     97        update_option( $allowed_option, $temporary_value );
     98
     99        $new_last_changed = wp_cache_get_last_changed( 'sites' );
     100
     101        /* Reset to original value. */
     102        update_option( $allowed_option, $original_value );
     103
     104        $this->assertSame( $new_last_changed, $last_changed );
     105    }
     106
     107    public function data_allowed_options() {
     108        return array(
     109            array( 'blogname', 'Custom Site' ),
     110            array( 'home', 'http://custom-site-url.org' ),
     111            array( 'siteurl', 'http://custom-site-url.org' ),
     112            array( 'post_count', '4' ),
     113        );
     114    }
     115
     116    /**
     117     * @ticket 40063
     118     */
     119    public function test_update_random_blog_option_does_not_delete_cache() {
     120        $site = get_site();
     121
     122        update_option( 'foobar_option', 'foobar_value' );
     123        $cached_result = wp_cache_get( $site->id, 'sites' );
     124
     125        delete_option( 'foobar_option' );
     126
     127        $this->assertNotFalse( $cached_result );
     128    }
     129
     130    /**
     131     * @ticket 40247
     132     */
     133    public function test_site_details_cached_including_false_values() {
     134        $id = self::factory()->blog->create();
     135
     136        $site = get_site( $id );
     137
     138        // Trigger retrieving site details (post_count is not set on new sites).
     139        $post_count = $site->post_count;
     140
     141        $cached_details = wp_cache_get( $site->id, 'site-details' );
     142
     143        wp_delete_site( $id );
     144        wp_update_network_site_counts();
     145
     146        $this->assertNotFalse( $cached_details );
     147    }
     148
     149    public function test_site_details_filter_with_blogname() {
     150        add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
     151        $site     = get_site();
     152        $blogname = $site->blogname;
     153        remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
     154
     155        $this->assertSame( 'Foo Bar', $blogname );
     156    }
     157
     158    public function _filter_site_details_blogname( $details ) {
     159        $details->blogname = 'Foo Bar';
     160        return $details;
     161    }
     162
     163    /**
     164     * @ticket 40458
     165     */
     166    public function test_site_details_filter_with_custom_value_isetter() {
     167        add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
     168        $site               = get_site();
     169        $custom_value_isset = isset( $site->custom_value );
     170        remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
     171
     172        $this->assertTrue( $custom_value_isset );
     173    }
     174
     175    /**
     176     * @ticket 40458
     177     */
     178    public function test_site_details_filter_with_custom_value_getter() {
     179        add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
     180        $site         = get_site();
     181        $custom_value = $site->custom_value;
     182        remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
     183
     184        $this->assertSame( 'foo', $custom_value );
     185    }
     186
     187    public function _filter_site_details_custom_value( $details ) {
     188        $details->custom_value = 'foo';
     189        return $details;
     190    }
     191}
Note: See TracChangeset for help on using the changeset viewer.