Make WordPress Core

Changeset 54040


Ignore:
Timestamp:
08/31/2022 04:02:05 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Correctly back up and restore theme directories in Tests_Theme.

In the set_up() method, a copy would be made of the original value of the global $wp_theme_directories variable, with the intention to restore that original value in the tear_down() method after running each test. Unfortunately, this was not implemented correctly.

  • The backup is made to a function local variable in set_up() and not stored somewhere where it is accessible from the tear_down() method.
  • The restoring then references a non-existent property to restore, which would effectively set the $wp_theme_directories global to null.

Fixed by declaring and using a private property to store the original $wp_theme_directories value.

This bug was discovered while fixing (removing) the magic methods in the WP_UnitTestCase_Base class in an effort to improve compatibility with PHP 8.2.

Follow-up to [38907].

Props jrf, costdev, johnbillion, swissspidy.
See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme.php

    r53357 r54040  
    2424    );
    2525
     26    /**
     27     * Original theme directory.
     28     *
     29     * @var string[]
     30     */
     31    private $orig_theme_dir;
     32
    2633    public function set_up() {
    2734        global $wp_theme_directories;
     
    2936        parent::set_up();
    3037
    31         $backup_wp_theme_directories = $wp_theme_directories;
    32         $wp_theme_directories        = array( WP_CONTENT_DIR . '/themes' );
     38        $this->orig_theme_dir = $wp_theme_directories;
     39        $wp_theme_directories = array( WP_CONTENT_DIR . '/themes' );
    3340
    3441        add_filter( 'extra_theme_headers', array( $this, 'theme_data_extra_headers' ) );
     
    4047        global $wp_theme_directories;
    4148
    42         $wp_theme_directories = $this->wp_theme_directories;
     49        $wp_theme_directories = $this->orig_theme_dir;
    4350
    4451        remove_filter( 'extra_theme_headers', array( $this, 'theme_data_extra_headers' ) );
Note: See TracChangeset for help on using the changeset viewer.