Make WordPress Core

Changeset 63595


Ignore:
Timestamp:
09/10/2026 09:39:21 PM (3 days ago)
Author:
lancewillett
Message:

Tests: Restore themes after block tests.

Save the incoming stylesheet in block and theme test fixtures and switch back during teardown when it changes. Restore the theme before database rollback so theme-related runtime state and caches do not leak into later tests.

Developed in: https://github.com/WordPress/wordpress-develop/pull/13205

Props jonsurrell.
See #65893.

Location:
trunk/tests/phpunit/tests
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/editor.php

    r61678 r63595  
    1717
    1818                parent::set_up();
     19                $this->original_stylesheet = get_stylesheet();
    1920
    2021                remove_action( 'wp_print_styles', 'print_emoji_styles' );
     
    5253                global $post_ID;
    5354                $post_ID = null;
     55
     56                if ( get_stylesheet() !== $this->original_stylesheet ) {
     57                        switch_theme( $this->original_stylesheet );
     58                }
     59
    5460                parent::tear_down();
    5561        }
     
    6470         */
    6571        protected $original_wp_styles;
     72
     73        /**
     74         * Original stylesheet.
     75         *
     76         * @var string
     77         */
     78        private $original_stylesheet;
    6679
    6780        public function filter_set_block_categories_post( $block_categories, $post ) {
  • trunk/tests/phpunit/tests/blocks/getBlockAssetUrl.php

    r56692 r63595  
    1919        private $orig_theme_dir;
    2020
     21        /**
     22         * Original stylesheet.
     23         *
     24         * @var string
     25         */
     26        private $original_stylesheet;
     27
    2128        public function set_up() {
    2229                global $wp_theme_directories;
    2330
    2431                parent::set_up();
     32                $this->original_stylesheet = get_stylesheet();
    2533
    2634                // Sets up the `wp-content/themes/` directory to ensure consistency when running tests.
     
    3442        public function tear_down() {
    3543                global $wp_theme_directories;
     44
     45                if ( get_stylesheet() !== $this->original_stylesheet ) {
     46                        switch_theme( $this->original_stylesheet );
     47                }
    3648
    3749                $wp_theme_directories = $this->orig_theme_dir;
  • trunk/tests/phpunit/tests/blocks/getBlockTemplates.php

    r59951 r63595  
    99
    1010        const TEST_THEME = 'block-theme';
     11
     12        /**
     13         * Original stylesheet.
     14         *
     15         * @var string
     16         */
     17        private $original_stylesheet;
    1118
    1219        /**
     
    9299        public function set_up() {
    93100                parent::set_up();
     101                $this->original_stylesheet = get_stylesheet();
    94102                switch_theme( self::TEST_THEME );
     103        }
     104
     105        public function tear_down() {
     106                if ( get_stylesheet() !== $this->original_stylesheet ) {
     107                        switch_theme( $this->original_stylesheet );
     108                }
     109
     110                parent::tear_down();
    95111        }
    96112
  • trunk/tests/phpunit/tests/blocks/getHookedBlocks.php

    r62264 r63595  
    1616
    1717        const TEST_THEME_NAME = 'block-theme-with-hooked-blocks';
     18
     19        /**
     20         * Original stylesheet.
     21         *
     22         * @var string
     23         */
     24        private $original_stylesheet;
     25
     26        public function set_up() {
     27                parent::set_up();
     28                $this->original_stylesheet = get_stylesheet();
     29        }
    1830
    1931        /**
     
    4456                }
    4557
     58                if ( get_stylesheet() !== $this->original_stylesheet ) {
     59                        switch_theme( $this->original_stylesheet );
     60                }
     61
    4662                parent::tear_down();
    4763        }
  • trunk/tests/phpunit/tests/blocks/register.php

    r61019 r63595  
    2222
    2323        /**
     24         * Original stylesheet.
     25         *
     26         * @var string
     27         */
     28        private $original_stylesheet;
     29
     30        /**
    2431         * ID for a test post.
    2532         *
     
    6269        public function set_up() {
    6370                parent::set_up();
     71                $this->original_stylesheet = get_stylesheet();
    6472
    6573                global $wp_scripts, $wp_styles;
     
    96104                $wp_scripts = $this->original_wp_scripts;
    97105                $wp_styles  = $this->original_wp_styles;
     106
     107                if ( get_stylesheet() !== $this->original_stylesheet ) {
     108                        switch_theme( $this->original_stylesheet );
     109                }
    98110
    99111                parent::tear_down();
  • trunk/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php

    r60904 r63595  
    2929
    3030        /**
     31         * Original stylesheet.
     32         *
     33         * @var string
     34         */
     35        private $original_stylesheet;
     36
     37        /**
    3138         * Set up each test method.
    3239         *
     
    3845                $this->registry                     = new WP_Block_Patterns_Registry();
    3946                $this->original_registered_patterns = $this->get_registered_patterns_variable_value();
     47                $this->original_stylesheet          = get_stylesheet();
    4048        }
    4149
     
    5563
    5664                $this->set_registered_patterns_variable_value( $this->original_registered_patterns );
     65
     66                if ( get_stylesheet() !== $this->original_stylesheet ) {
     67                        switch_theme( $this->original_stylesheet );
     68                }
     69
    5770                parent::tear_down();
    5871        }
  • trunk/tests/phpunit/tests/theme/wpThemeGetBlockPatterns.php

    r60729 r63595  
    2020        private $initial_cache_object;
    2121
     22        /**
     23         * Original stylesheet.
     24         *
     25         * @var string
     26         */
     27        private $original_stylesheet;
     28
    2229        public function set_up() {
    2330                parent::set_up();
    2431
    2532                $this->initial_cache_object = wp_using_ext_object_cache();
     33                $this->original_stylesheet  = get_stylesheet();
    2634        }
    2735
    2836        public function tear_down() {
    2937                wp_using_ext_object_cache( $this->initial_cache_object );
     38
     39                if ( get_stylesheet() !== $this->original_stylesheet ) {
     40                        switch_theme( $this->original_stylesheet );
     41                }
     42
    3043                parent::tear_down();
    3144        }
Note: See TracChangeset for help on using the changeset viewer.