Make WordPress Core


Ignore:
Timestamp:
02/06/2023 07:57:41 PM (4 years ago)
Author:
flixos90
Message:

Themes: Add caching to WP_Theme::is_block_theme().

This changeset adds a block_theme entry in the theme cache data, similar to the existing entries headers, errors, stylesheet, and template.

Props spacedmonkey, costdev, joemcgill, flixos90, mukesh27, adamsilverstein.
Fixes #57114.

File:
1 edited

Legend:

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

    r53933 r55236  
    277277
    278278        /**
     279         * @ticket 57114
     280         *
     281         * @covers WP_Theme::is_block_theme
     282         *
     283         * @dataProvider data_is_block_theme
     284         */
     285        public function test_is_block_theme_property( $theme_dir, $expected ) {
     286                $theme = new WP_Theme( $theme_dir, $this->theme_root );
     287                $theme->is_block_theme();
     288                $reflection          = new ReflectionClass( $theme );
     289                $reflection_property = $reflection->getProperty( 'block_theme' );
     290                $reflection_property->setAccessible( true );
     291
     292                $this->assertSame( $expected, $reflection_property->getValue( $theme ) );
     293        }
     294
     295        /**
     296         * @ticket 57114
     297         *
     298         * @covers WP_Theme::is_block_theme
     299         * @covers WP_Theme::cache_get
     300         */
     301        public function test_is_block_theme_check_cache() {
     302                $filter = new MockAction();
     303                add_filter( 'theme_file_path', array( $filter, 'filter' ) );
     304
     305                $theme1 = new WP_Theme( 'block-theme', $this->theme_root );
     306                // First run.
     307                $this->assertTrue( $theme1->is_block_theme(), 'is_block_theme should return true on first run' );
     308
     309                $theme2 = new WP_Theme( 'block-theme', $this->theme_root );
     310                // Second run.
     311                $this->assertTrue( $theme2->is_block_theme(), 'is_block_theme should return true on second run' );
     312                $this->assertCount( 0, $filter->get_events(), 'Should only be 0, as second run should be cached' );
     313        }
     314
     315        /**
     316         * @ticket 57114
     317         *
     318         * @covers WP_Theme::is_block_theme
     319         * @covers WP_Theme::cache_delete
     320         */
     321        public function test_is_block_theme_delete_cache() {
     322                $filter = new MockAction();
     323                add_filter( 'theme_file_path', array( $filter, 'filter' ) );
     324
     325                $theme = new WP_Theme( 'block-theme', $this->theme_root );
     326                // First run.
     327                $this->assertTrue( $theme->is_block_theme(), 'is_block_theme should return true on first run' );
     328                // Clear cache.
     329                $theme->cache_delete();
     330                // Second run.
     331                $this->assertTrue( $theme->is_block_theme(), 'is_block_theme should return true on second run' );
     332                $this->assertCount( 2, $filter->get_events(), 'Should only be 4, as second run should not be cached' );
     333        }
     334
     335        /**
    279336         * Test get_files for an existing theme.
    280337         *
Note: See TracChangeset for help on using the changeset viewer.