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
Support adding opt-in visual styles for core blocks #6947
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,2 @@ | ||
// TODO: Remove this comment when adding theme styles. | ||
// Including an empty file for now so webpack will build an aggregate build/core-blocks/theme.css. |
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
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,85 @@ | ||
<?php | ||
/** | ||
* Core block theme tests. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
/** | ||
* Test inclusion of opt-in core block theme. | ||
*/ | ||
class Core_Block_Theme_Test extends WP_UnitTestCase { | ||
private $old_wp_styles; | ||
private $old_wp_scripts; | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; | ||
remove_action( 'wp_default_scripts', 'wp_default_scripts' ); | ||
|
||
$GLOBALS['wp_scripts'] = new WP_Scripts(); | ||
$GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); | ||
|
||
$this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null; | ||
remove_action( 'wp_default_styles', 'wp_default_styles' ); | ||
|
||
$GLOBALS['wp_styles'] = new WP_Styles(); | ||
$GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' ); | ||
} | ||
|
||
function tearDown() { | ||
$GLOBALS['wp_scripts'] = $this->old_wp_scripts; | ||
add_action( 'wp_default_scripts', 'wp_default_scripts' ); | ||
|
||
$GLOBALS['wp_styles'] = $this->old_wp_styles; | ||
add_action( 'wp_default_styles', 'wp_default_styles' ); | ||
|
||
if ( current_theme_supports( 'wp-block-styles' ) ) { | ||
remove_theme_support( 'wp-block-styles' ); | ||
} | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
function test_block_theme_in_editor_without_theme_support() { | ||
// Confirm we are without theme support by default. | ||
$this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); | ||
|
||
gutenberg_register_scripts_and_styles(); | ||
|
||
$this->assertFalse( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
wp_enqueue_style( 'wp-edit-blocks' ); | ||
$this->assertTrue( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
} | ||
|
||
function test_block_theme_in_editor_with_theme_support() { | ||
add_theme_support( 'wp-block-styles' ); | ||
gutenberg_register_scripts_and_styles(); | ||
|
||
$this->assertFalse( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
wp_enqueue_style( 'wp-edit-blocks' ); | ||
$this->assertTrue( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
} | ||
|
||
function test_no_block_theme_on_front_end_without_theme_support() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rename this from |
||
// Confirm we are without theme support by default. | ||
$this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); | ||
|
||
gutenberg_register_scripts_and_styles(); | ||
|
||
$this->assertFalse( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
wp_enqueue_style( 'wp-core-blocks' ); | ||
$this->assertFalse( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
} | ||
|
||
function test_block_theme_on_front_end_with_theme_support() { | ||
add_theme_support( 'wp-block-styles' ); | ||
|
||
gutenberg_register_scripts_and_styles(); | ||
|
||
$this->assertFalse( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
wp_enqueue_style( 'wp-core-blocks' ); | ||
$this->assertTrue( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could add a comment to (at least) this test (and maybe the next) stating default block styles are always loaded for the editor and why. I know you've explained it elsewhere in this PR but that documentation won't be obvious to someone reading this test/just this file, so it bears repeating.
It's reasonably obvious what these tests are doing but not obvious why. I think a bit more explanation would make them clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'll make the update.