mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@55236 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -275,6 +275,63 @@ class Tests_Theme_wpTheme extends WP_UnitTestCase {
|
||||
$this->assertSame( $expected, $theme->is_block_theme() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57114
|
||||
*
|
||||
* @covers WP_Theme::is_block_theme
|
||||
*
|
||||
* @dataProvider data_is_block_theme
|
||||
*/
|
||||
public function test_is_block_theme_property( $theme_dir, $expected ) {
|
||||
$theme = new WP_Theme( $theme_dir, $this->theme_root );
|
||||
$theme->is_block_theme();
|
||||
$reflection = new ReflectionClass( $theme );
|
||||
$reflection_property = $reflection->getProperty( 'block_theme' );
|
||||
$reflection_property->setAccessible( true );
|
||||
|
||||
$this->assertSame( $expected, $reflection_property->getValue( $theme ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57114
|
||||
*
|
||||
* @covers WP_Theme::is_block_theme
|
||||
* @covers WP_Theme::cache_get
|
||||
*/
|
||||
public function test_is_block_theme_check_cache() {
|
||||
$filter = new MockAction();
|
||||
add_filter( 'theme_file_path', array( $filter, 'filter' ) );
|
||||
|
||||
$theme1 = new WP_Theme( 'block-theme', $this->theme_root );
|
||||
// First run.
|
||||
$this->assertTrue( $theme1->is_block_theme(), 'is_block_theme should return true on first run' );
|
||||
|
||||
$theme2 = new WP_Theme( 'block-theme', $this->theme_root );
|
||||
// Second run.
|
||||
$this->assertTrue( $theme2->is_block_theme(), 'is_block_theme should return true on second run' );
|
||||
$this->assertCount( 0, $filter->get_events(), 'Should only be 0, as second run should be cached' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57114
|
||||
*
|
||||
* @covers WP_Theme::is_block_theme
|
||||
* @covers WP_Theme::cache_delete
|
||||
*/
|
||||
public function test_is_block_theme_delete_cache() {
|
||||
$filter = new MockAction();
|
||||
add_filter( 'theme_file_path', array( $filter, 'filter' ) );
|
||||
|
||||
$theme = new WP_Theme( 'block-theme', $this->theme_root );
|
||||
// First run.
|
||||
$this->assertTrue( $theme->is_block_theme(), 'is_block_theme should return true on first run' );
|
||||
// Clear cache.
|
||||
$theme->cache_delete();
|
||||
// Second run.
|
||||
$this->assertTrue( $theme->is_block_theme(), 'is_block_theme should return true on second run' );
|
||||
$this->assertCount( 2, $filter->get_events(), 'Should only be 4, as second run should not be cached' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_files for an existing theme.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user