-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support opt-in visual styles for core blocks
The purpose of this change is to offer default visual styles for themes that want them without interfering with existing themes that provide their own. Core blocks may include a `theme.scss` file containing visual styles, and those styles will be built into `build/core-blocks/theme.css`. The visual styles are enqueued for editing but are not enqueued for viewing unless there is theme support for `wp-block-styles`.
- Loading branch information
1 parent
c93b778
commit 6728906
Showing
6 changed files
with
145 additions
and
2 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,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,106 @@ | ||
<?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(); | ||
} | ||
|
||
/** | ||
* Tests that visual block styles are enqueued in the editor even when there is not theme support for 'wp-block-styles'. | ||
* | ||
* Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. | ||
*/ | ||
function test_block_styles_for_editing_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' ) ); | ||
} | ||
|
||
/** | ||
* Tests that visual block styles are enqueued when there is theme support for 'wp-block-styles'. | ||
* | ||
* Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. | ||
*/ | ||
function test_block_styles_for_editing_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' ) ); | ||
} | ||
|
||
/** | ||
* Tests that visual block styles are not enqueued for viewing when there is no theme support for 'wp-block-styles'. | ||
* | ||
* Visual block styles should not be enqueued unless a theme opts in. | ||
* This way we avoid style conflicts with existing themes. | ||
*/ | ||
function test_no_block_styles_for_viewing_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-core-blocks' ); | ||
$this->assertFalse( wp_style_is( 'wp-core-blocks-theme' ) ); | ||
} | ||
|
||
/** | ||
* Tests that visual block styles are enqueued for viewing when there is theme support for 'wp-block-styles'. | ||
* | ||
* Visual block styles should be enqueued when a theme opts in. | ||
*/ | ||
function test_block_styles_for_viewing_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