-
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.
Browse files
Browse the repository at this point in the history
* Revert "Revert test data for `WithSlug` variation (#62579)" This reverts commit 2917269. * Clear up test caching Co-authored-by: oandregal <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: tellthemachines <[email protected]> Co-authored-by: ramonjd <[email protected]>
- Loading branch information
1 parent
6633dc3
commit 2fdcec7
Showing
3 changed files
with
107 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,41 @@ | |
*/ | ||
|
||
class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase { | ||
/** | ||
* Administrator ID. | ||
* | ||
* @var int | ||
*/ | ||
protected static $administrator_id; | ||
|
||
/** | ||
* WP_Theme_JSON_Resolver_Gutenberg::$blocks_cache property. | ||
* | ||
* @var ReflectionProperty | ||
*/ | ||
private static $property_blocks_cache; | ||
|
||
/** | ||
* Original value of the WP_Theme_JSON_Resolver_Gutenberg::$blocks_cache property. | ||
* | ||
* @var array | ||
*/ | ||
private static $property_blocks_cache_orig_value; | ||
|
||
/** | ||
* WP_Theme_JSON_Resolver_Gutenberg::$core property. | ||
* | ||
* @var ReflectionProperty | ||
*/ | ||
private static $property_core; | ||
|
||
/** | ||
* Original value of the WP_Theme_JSON_Resolver_Gutenberg::$core property. | ||
* | ||
* @var WP_Theme_JSON_Gutenberg | ||
*/ | ||
private static $property_core_orig_value; | ||
|
||
/** | ||
* Theme root directory. | ||
* | ||
|
@@ -23,6 +58,31 @@ class WP_Block_Supports_Block_Style_Variations_Test extends WP_UnitTestCase { | |
*/ | ||
private $orig_theme_dir; | ||
|
||
public static function set_up_before_class() { | ||
parent::set_up_before_class(); | ||
|
||
self::$administrator_id = self::factory()->user->create( | ||
array( | ||
'role' => 'administrator', | ||
'user_email' => '[email protected]', | ||
) | ||
); | ||
|
||
static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'blocks_cache' ); | ||
static::$property_blocks_cache->setAccessible( true ); | ||
static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue(); | ||
|
||
static::$property_core = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'core' ); | ||
static::$property_core->setAccessible( true ); | ||
static::$property_core_orig_value = static::$property_core->getValue(); | ||
} | ||
|
||
public static function tear_down_after_class() { | ||
static::$property_blocks_cache->setValue( null, static::$property_blocks_cache_orig_value ); | ||
static::$property_core->setValue( null, static::$property_core_orig_value ); | ||
parent::tear_down_after_class(); | ||
} | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
$this->theme_root = realpath( dirname( __DIR__ ) . '/data/themedir1' ); | ||
|
@@ -94,6 +154,22 @@ public function test_add_registered_block_styles_to_theme_data() { | |
), | ||
); | ||
|
||
/* | ||
* This style is to be deliberately overwritten by the theme.json partial | ||
* See `phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json`. | ||
*/ | ||
register_block_style( | ||
'core/group', | ||
array( | ||
'name' => 'WithSlug', | ||
'style_data' => array( | ||
'color' => array( | ||
'background' => 'whitesmoke', | ||
'text' => 'black', | ||
), | ||
), | ||
) | ||
); | ||
register_block_style( | ||
'core/group', | ||
array( | ||
|
@@ -106,6 +182,12 @@ public function test_add_registered_block_styles_to_theme_data() { | |
$group_styles = $theme_json['styles']['blocks']['core/group'] ?? array(); | ||
$expected = array( | ||
'variations' => array( | ||
'WithSlug' => array( | ||
'color' => array( | ||
'background' => 'aliceblue', | ||
'text' => 'midnightblue', | ||
), | ||
), | ||
'my-variation' => $variation_styles_data, | ||
|
||
/* | ||
|
@@ -129,6 +211,7 @@ public function test_add_registered_block_styles_to_theme_data() { | |
); | ||
|
||
unregister_block_style( 'core/group', 'my-variation' ); | ||
unregister_block_style( 'core/group', 'WithSlug' ); | ||
|
||
$this->assertSameSetsWithIndex( $group_styles, $expected ); | ||
} | ||
|
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
12 changes: 12 additions & 0 deletions
12
phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json
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,12 @@ | ||
{ | ||
"version": 3, | ||
"blockTypes": [ "core/group", "core/columns" ], | ||
"slug": "WithSlug", | ||
"title": "With Slug", | ||
"styles": { | ||
"color": { | ||
"background": "aliceblue", | ||
"text": "midnightblue" | ||
} | ||
} | ||
} |