Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1287,10 +1287,12 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
}
}

// Add responsive breakpoint states for elements.
foreach ( array_keys( $responsive_media_queries ) as $breakpoint_state ) {
$schema_styles_elements[ $element ][ $breakpoint_state ] = $styles_non_top_level;
}
/*
* Breakpoint states are not added here. A responsive element is
* written as a block breakpoint containing elements, the third
* structure listed above, which is assembled further down from
* this same element schema.
*/
}

$schema_styles_blocks = array();
Expand Down
53 changes: 42 additions & 11 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,7 @@ public function test_remove_insecure_properties_removes_unsafe_styles_sub_proper
/**
* @covers WP_Theme_JSON_Gutenberg::remove_insecure_properties
*/
public function test_remove_insecure_properties_preserves_responsive_block_element_styles() {
public function test_remove_insecure_properties_strips_breakpoints_set_on_a_block_element() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inverts an existing assertion. test_remove_insecure_properties_preserves_responsive_block_element_styles asserted the element-nested breakpoints were kept.

Is this change right or is the original correct?

$actual = WP_Theme_JSON_Gutenberg::remove_insecure_properties(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
Expand Down Expand Up @@ -3643,30 +3643,61 @@ public function test_remove_insecure_properties_preserves_responsive_block_eleme
)
);

// The breakpoints are dropped. Only the element's own styles remain.
$expected = array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'styles' => array(
'blocks' => array(
'core/group' => array(
'elements' => array(
'link' => array(
'color' => array(
'color' => array(
'text' => 'var(--wp--preset--color--dark-gray)',
),
'@mobile' => array(
'color' => array(
'text' => 'var(--wp--preset--color--dark-pink)',
),
),
'@tablet' => array(
'color' => array(
'text' => 'var(--wp--preset--color--dark-red)',
),
),
),
),
),
),
);

$this->assertEqualSetsWithIndex( $expected, $actual );
}

/**
* @covers WP_Theme_JSON_Gutenberg::remove_insecure_properties
*/
public function test_remove_insecure_properties_strips_breakpoints_set_on_a_top_level_element() {
$actual = WP_Theme_JSON_Gutenberg::remove_insecure_properties(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'styles' => array(
'elements' => array(
'link' => array(
'color' => array(
'text' => 'var:preset|color|dark-gray',
),
'@mobile' => array(
'color' => array(
'text' => 'var:preset|color|dark-pink',
),
),
),
),
),
)
);

$expected = array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'styles' => array(
'elements' => array(
'link' => array(
'color' => array(
'text' => 'var(--wp--preset--color--dark-gray)',
),
),
),
),
);

Expand Down
Loading