-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix for classic themes using default presets #2233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
oandregal
wants to merge
18
commits into
WordPress:trunk
from
oandregal:fix/classic-themes-using-default-presets
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
963b582
Always take into account theme data for generating the CSS Custom Pro…
oandregal 51da14d
Add comment
oandregal b885713
Fix lint issues
oandregal 9d9bb5f
Only output the variables once
oandregal 0123099
Better formatting
oandregal 35684b2
Add tests
oandregal 81f893c
Use themes as group
oandregal 8b763d7
Fix lint issues for globalStylesheet.php
oandregal 48a7b79
Add classic with presets theme to the list of themes
oandregal 147ff5f
Switch to default theme after tests
oandregal 7d245b9
More fine-grained tests with good info
oandregal 9cde490
Fix lint issues
oandregal 11990b6
Update tests for classic-with-presets
oandregal 93f9d41
Use single instead of double quotes
oandregal 8647bf4
Set up theme dir
oandregal 160070e
Update classname to follow other files in the same dir
oandregal a78a74e
Add theme support dynamically to default theme instead of creating a …
oandregal 91e4a2f
Fix linting issues
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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' ); | ||
oandregal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $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' ); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.