Skip to content

Commit

Permalink
Updated tests to reflect the changed situation:
Browse files Browse the repository at this point in the history
- Before we were unsetting blockGap for block and elements from the merged $theme_json structure in sanitize().
- After we keep them in the merged $theme_json, but skip them when printing out the global stylesheet.
  • Loading branch information
ramonjd committed Apr 27, 2022
1 parent e4d87c5 commit 3b3d96e
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,38 @@ function test_get_stylesheet_skips_disabled_protected_properties() {
$this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
}

function test_get_stylesheet_skips_top_level_properties_at_block_level() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'spacing' => array(
'padding' => true,
'blockGap' => true,
),
),
'styles' => array(
'spacing' => array(
'padding' => '1vw',
'blockGap' => '1em',
),
'blocks' => array(
'core/columns' => array(
'spacing' => array(
'padding' => '0.5rem',
'blockGap' => '24px',
),
),
),
),
)
);

$expected = 'body { margin: 0; }body{padding: 1vw;--wp--style--block-gap: 1em;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }.wp-block-columns{padding: 0.5rem;}';
$this->assertEquals( $expected, $theme_json->get_stylesheet() );
$this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
}

function test_get_stylesheet_renders_enabled_protected_properties() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
Expand Down Expand Up @@ -2253,7 +2285,7 @@ function test_sanitization() {
'core/group' => array(
'spacing' => array(
'margin' => 'valid value',
'blockGap' => 'invalid value',
'blockGap' => 'valid value',
),
),
),
Expand All @@ -2271,7 +2303,8 @@ function test_sanitization() {
'blocks' => array(
'core/group' => array(
'spacing' => array(
'margin' => 'valid value',
'margin' => 'valid value',
'blockGap' => 'valid value',
),
),
),
Expand Down

0 comments on commit 3b3d96e

Please sign in to comment.