mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Classic themes using default presets are not working.
This commit makes the presets provided by the theme via add_theme_support always create CSS Custom Properties, whether or not the theme has a theme.json file. This way, if the overwrites a core preset, the core CSS variables are also overwritten and use the theme value. Props oandregal, hellofromTonya, desrosj, costdev, pbearne, johnstonphilip, webmandesign. Fixes #54782. git-svn-id: https://develop.svn.wordpress.org/trunk@52675 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
f9f27c5
commit b7aa3a0
Showing
2 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
<?php | ||
|
||
/** | ||
* @group themes | ||
*/ | ||
class Tests_Theme_GlobalStylesheet extends WP_UnitTestCase { | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->orig_theme_dir = $GLOBALS['wp_theme_directories']; | ||
$this->theme_root = realpath( DIR_TESTDATA . '/themedir1' ); | ||
|
||
// /themes is necessary as theme.php functions assume /themes is the root if there is only one root. | ||
$GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root ); | ||
|
||
// Set up the new root. | ||
add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); | ||
add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); | ||
add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); | ||
|
||
// Clear caches. | ||
wp_clean_themes_cache(); | ||
unset( $GLOBALS['wp_themes'] ); | ||
} | ||
|
||
public function tear_down() { | ||
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; | ||
|
||
// Clear up the filters to modify the theme root. | ||
remove_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); | ||
remove_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); | ||
remove_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); | ||
|
||
wp_clean_themes_cache(); | ||
unset( $GLOBALS['wp_themes'] ); | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
public function filter_set_theme_root() { | ||
return $this->theme_root; | ||
} | ||
|
||
public function test_block_theme_using_variables() { | ||
switch_theme( 'block-theme' ); | ||
|
||
$styles = wp_get_global_stylesheet( array( 'variables' ) ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--small: 13px' ), 'small font size is 13px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is 20px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--large: 36px' ), 'large font size is 36px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is 42px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--custom: 100px;' ), 'custom font size is 100px' ); | ||
|
||
switch_theme( WP_DEFAULT_THEME ); | ||
} | ||
|
||
public function test_block_theme_using_presets() { | ||
switch_theme( 'block-theme' ); | ||
|
||
$styles = wp_get_global_stylesheet( array( 'presets' ) ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--small: 13px' ), 'small font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--large: 36px' ), 'large font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--custom: 100px;' ), 'custom font size is not present' ); | ||
|
||
switch_theme( WP_DEFAULT_THEME ); | ||
} | ||
|
||
public function test_block_theme_using_defaults() { | ||
switch_theme( 'block-theme' ); | ||
|
||
$styles = wp_get_global_stylesheet(); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--small: 13px' ), 'small font size is 13px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is 20px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--large: 36px' ), 'large font size is 36px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is 42px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--custom: 100px;' ), 'custom font size is 100px' ); | ||
|
||
switch_theme( WP_DEFAULT_THEME ); | ||
} | ||
|
||
public function test_variables_in_classic_theme_with_no_presets_using_variables() { | ||
$styles = wp_get_global_stylesheet( array( 'variables' ) ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--small: 13px' ), 'small font size is 13px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is 20px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--large: 36px' ), 'large font size is 36px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is 42px' ); | ||
} | ||
|
||
public function test_variables_in_classic_theme_with_no_presets_using_presets() { | ||
$styles = wp_get_global_stylesheet( array( 'presets' ) ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--small: 13px' ), 'small font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--large: 36px' ), 'large font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is not present' ); | ||
} | ||
|
||
public function test_variables_in_classic_theme_with_no_presets_using_defaults() { | ||
$styles = wp_get_global_stylesheet(); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--small: 13px' ), 'small font size is 13px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is 20px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--large: 36px' ), 'large font size is 36px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is 42px' ); | ||
} | ||
|
||
public function test_variables_in_classic_theme_with_presets_using_variables() { | ||
add_theme_support( | ||
'editor-font-sizes', | ||
array( | ||
array( | ||
'name' => 'Small', | ||
'size' => 18, | ||
'slug' => 'small', | ||
), | ||
array( | ||
'name' => 'Large', | ||
'size' => 26.25, | ||
'slug' => 'large', | ||
), | ||
) | ||
); | ||
|
||
$styles = wp_get_global_stylesheet( array( 'variables' ) ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--small: 18px' ), 'small font size is 18px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is 20px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--large: 26.25px' ), 'large font size is 26.25px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is 42px' ); | ||
|
||
remove_theme_support( 'editor-font-sizes' ); | ||
} | ||
|
||
public function test_variables_in_classic_theme_with_presets_using_presets() { | ||
add_theme_support( | ||
'editor-font-sizes', | ||
array( | ||
array( | ||
'name' => 'Small', | ||
'size' => 18, | ||
'slug' => 'small', | ||
), | ||
array( | ||
'name' => 'Large', | ||
'size' => 26.25, | ||
'slug' => 'large', | ||
), | ||
) | ||
); | ||
|
||
$styles = wp_get_global_stylesheet( array( 'presets' ) ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--small: 18px' ), 'small font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--large: 26.25px' ), 'large font size is not present' ); | ||
$this->assertFalse( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'x-large font size is not present' ); | ||
|
||
remove_theme_support( 'editor-font-sizes' ); | ||
} | ||
|
||
public function test_variables_in_classic_theme_with_presets_using_defaults() { | ||
add_theme_support( | ||
'editor-font-sizes', | ||
array( | ||
array( | ||
'name' => 'Small', | ||
'size' => 18, | ||
'slug' => 'small', | ||
), | ||
array( | ||
'name' => 'Large', | ||
'size' => 26.25, | ||
'slug' => 'large', | ||
), | ||
) | ||
); | ||
|
||
$styles = wp_get_global_stylesheet(); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--small: 18px' ), 'small font size is 18px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--medium: 20px' ), 'medium font size is 20px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--large: 26.25px' ), 'large font size is 26.25px' ); | ||
$this->assertTrue( str_contains( $styles, '--wp--preset--font-size--x-large: 42px' ), 'small font size is 42px' ); | ||
|
||
remove_theme_support( 'editor-font-sizes' ); | ||
} | ||
|
||
} |