Make WordPress Core


Ignore:
Timestamp:
08/21/2022 04:55:18 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in theme tests.

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In this particular group of test files, the test classes contain a set_up() method which sets a few dynamic (not explicitly declared) properties.

For those properties which were set using a function call or variable access, the property has been explicitly declared on the class now.

For those properties which were set using a constant scalar expression and for which the value is not changed by any of the tests, the property setting has been removed in favor of declaring a class constant.

Includes removing one unused dynamic property declaration: $this->queries in Test_Block_Supports_Layout, which appears to be a copy/paste from Tests_Theme_wpThemeJsonResolver.

Follow-up to [40/tests], [260/tests], [598/tests], [50960], [52675], [53085], [53557], [53558], [53850], [53851], [53852], [53853], [53854], [53856].

Props jrf.
See #56033.

File:
1 edited

Legend:

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

    r53874 r53916  
    88class Tests_Theme_ThemeDir extends WP_UnitTestCase {
    99
     10        /**
     11         * Theme root directory.
     12         *
     13         * @var string
     14         */
     15        const THEME_ROOT = DIR_TESTDATA . '/themedir1';
     16
     17        /**
     18         * Original theme directory.
     19         *
     20         * @var string
     21         */
     22        private $orig_theme_dir;
     23
    1024        public function set_up() {
    1125                parent::set_up();
    12                 $this->theme_root = DIR_TESTDATA . '/themedir1';
    1326
    1427                $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
    1528
    1629                // /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
    17                 $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
     30                $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', self::THEME_ROOT );
    1831
    1932                add_filter( 'theme_root', array( $this, 'filter_theme_root' ) );
     
    3447        // Replace the normal theme root directory with our premade test directory.
    3548        public function filter_theme_root( $dir ) {
    36                 return $this->theme_root;
     49                return self::THEME_ROOT;
    3750        }
    3851
     
    5871                $this->assertSame( 'default', $theme['Stylesheet'] );
    5972
    60                 $this->assertContains( $this->theme_root . '/default/functions.php', $theme['Template Files'] );
    61                 $this->assertContains( $this->theme_root . '/default/index.php', $theme['Template Files'] );
    62                 $this->assertContains( $this->theme_root . '/default/style.css', $theme['Stylesheet Files'] );
    63 
    64                 $this->assertSame( $this->theme_root . '/default', $theme['Template Dir'] );
    65                 $this->assertSame( $this->theme_root . '/default', $theme['Stylesheet Dir'] );
     73                $this->assertContains( self::THEME_ROOT . '/default/functions.php', $theme['Template Files'] );
     74                $this->assertContains( self::THEME_ROOT . '/default/index.php', $theme['Template Files'] );
     75                $this->assertContains( self::THEME_ROOT . '/default/style.css', $theme['Stylesheet Files'] );
     76
     77                $this->assertSame( self::THEME_ROOT . '/default', $theme['Template Dir'] );
     78                $this->assertSame( self::THEME_ROOT . '/default', $theme['Stylesheet Dir'] );
    6679                $this->assertSame( 'publish', $theme['Status'] );
    6780                $this->assertSame( '', $theme['Parent Theme'] );
     
    89102                $template_files = $theme['Template Files'];
    90103
    91                 $this->assertSame( $this->theme_root . '/sandbox/functions.php', reset( $template_files ) );
    92                 $this->assertSame( $this->theme_root . '/sandbox/index.php', next( $template_files ) );
     104                $this->assertSame( self::THEME_ROOT . '/sandbox/functions.php', reset( $template_files ) );
     105                $this->assertSame( self::THEME_ROOT . '/sandbox/index.php', next( $template_files ) );
    93106
    94107                $stylesheet_files = $theme['Stylesheet Files'];
    95108
    96                 $this->assertSame( $this->theme_root . '/sandbox/style.css', reset( $stylesheet_files ) );
    97 
    98                 $this->assertSame( $this->theme_root . '/sandbox', $theme['Template Dir'] );
    99                 $this->assertSame( $this->theme_root . '/sandbox', $theme['Stylesheet Dir'] );
     109                $this->assertSame( self::THEME_ROOT . '/sandbox/style.css', reset( $stylesheet_files ) );
     110
     111                $this->assertSame( self::THEME_ROOT . '/sandbox', $theme['Template Dir'] );
     112                $this->assertSame( self::THEME_ROOT . '/sandbox', $theme['Stylesheet Dir'] );
    100113                $this->assertSame( 'publish', $theme['Status'] );
    101114                $this->assertSame( '', $theme['Parent Theme'] );
     
    123136                $this->assertSame( 'sandbox', $theme['Template'] );
    124137                $this->assertSame( 'stylesheetonly', $theme['Stylesheet'] );
    125                 $this->assertContains( $this->theme_root . '/sandbox/functions.php', $theme['Template Files'] );
    126                 $this->assertContains( $this->theme_root . '/sandbox/index.php', $theme['Template Files'] );
    127 
    128                 $this->assertContains( $this->theme_root . '/stylesheetonly/style.css', $theme['Stylesheet Files'] );
    129 
    130                 $this->assertSame( $this->theme_root . '/sandbox', $theme['Template Dir'] );
    131                 $this->assertSame( $this->theme_root . '/stylesheetonly', $theme['Stylesheet Dir'] );
     138                $this->assertContains( self::THEME_ROOT . '/sandbox/functions.php', $theme['Template Files'] );
     139                $this->assertContains( self::THEME_ROOT . '/sandbox/index.php', $theme['Template Files'] );
     140
     141                $this->assertContains( self::THEME_ROOT . '/stylesheetonly/style.css', $theme['Stylesheet Files'] );
     142
     143                $this->assertSame( self::THEME_ROOT . '/sandbox', $theme['Template Dir'] );
     144                $this->assertSame( self::THEME_ROOT . '/stylesheetonly', $theme['Stylesheet Dir'] );
    132145                $this->assertSame( 'publish', $theme['Status'] );
    133146                $this->assertSame( 'Sandbox', $theme['Parent Theme'] );
     
    143156                // Ignore themes in the default /themes directory.
    144157                foreach ( $themes as $theme_name => $theme ) {
    145                         if ( $theme->get_theme_root() !== $this->theme_root ) {
     158                        if ( $theme->get_theme_root() !== self::THEME_ROOT ) {
    146159                                unset( $themes[ $theme_name ] );
    147160                        }
     
    199212
    200213        public function test_wp_get_theme_with_non_default_theme_root() {
    201                 $this->assertFalse( wp_get_theme( 'sandbox', $this->theme_root )->errors() );
     214                $this->assertFalse( wp_get_theme( 'sandbox', self::THEME_ROOT )->errors() );
    202215                $this->assertFalse( wp_get_theme( 'sandbox' )->errors() );
    203216        }
     
    213226
    214227                $templates = $theme['Template Files'];
    215                 $this->assertContains( $this->theme_root . '/page-templates/template-top-level.php', $templates );
     228                $this->assertContains( self::THEME_ROOT . '/page-templates/template-top-level.php', $templates );
    216229        }
    217230
     
    239252         */
    240253        public function test_get_theme_data_subdir() {
    241                 $theme_data = get_theme_data( $this->theme_root . '/subdir/theme2/style.css' );
     254                $theme_data = get_theme_data( self::THEME_ROOT . '/subdir/theme2/style.css' );
    242255
    243256                $this->assertSame( 'My Subdir Theme', $theme_data['Name'] );
Note: See TracChangeset for help on using the changeset viewer.