Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Oct 13, 2022
1 parent 1c6fb96 commit 5d42cc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected static function filter_declaration( $property, $value, $spacer = '' )
*
* It does not need to be backported to future versions of WordPress.
*/
if ( isset( static::$valid_custom_declarations[ $property ] ) ) {
if ( '' !== $filtered_value && isset( static::$valid_custom_declarations[ $property ] ) ) {
return safecss_filter_attr( static::$valid_custom_declarations[ $property ] . ":{$spacer}{$value}" ) ?
"{$property}:{$spacer}{$value}" : '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,24 @@ public function test_should_strip_html_tags_and_remove_unsafe_css_properties() {


/**
* Tests that calc, clamp, min, max, and minmax CSS functions are allowed.
* Tests that calc, clamp, min, max, minmax CSS functions and --wp--* CSS custom properties are allowed.
*
* @covers ::get_declarations_string
* @covers ::filter_declaration
*/
public function test_should_allow_css_functions_and_strip_unsafe_css_values() {
$input_declarations = array(
'background' => 'var(--wp--preset--color--primary, 10px)', // Simple var().
'font-size' => 'clamp(36.00rem, calc(32.00rem + 10.00vw), 40.00rem)', // Nested clamp().
'width' => 'min(150vw, 100px)',
'min-width' => 'max(150vw, 100px)',
'max-width' => 'minmax(400px, 50%)',
'padding' => 'calc(80px * -1)',
'background-image' => 'url("https://wordpress.org")',
'line-height' => 'url("https://wordpress.org")',
'margin' => 'illegalfunction(30px)',
'background' => 'var(--wp--preset--color--primary, 10px)', // Simple var().
'font-size' => 'clamp(36.00rem, calc(32.00rem + 10.00vw), 40.00rem)', // Nested clamp().
'width' => 'min(150vw, 100px)',
'min-width' => 'max(150vw, 100px)',
'max-width' => 'minmax(400px, 50%)',
'padding' => 'calc(80px * -1)',
'background-image' => 'url("https://wordpress.org")',
'line-height' => 'url("https://wordpress.org")',
'margin' => 'illegalfunction(30px)',
'--wp--style--unstable-gallery-gap' => '12em',
'/::border-[<width>]' => '2000.75em',
);
$css_declarations = new WP_Style_Engine_CSS_Declarations_Gutenberg( $input_declarations );
$safecss_filter_attr_allow_css_mock_action = new MockAction();
Expand All @@ -146,13 +148,13 @@ public function test_should_allow_css_functions_and_strip_unsafe_css_values() {
$css_declarations_string = $css_declarations->get_declarations_string();

$this->assertSame(
9,
11,
$safecss_filter_attr_allow_css_mock_action->get_call_count(),
'"safecss_filter_attr_allow_css" filters were not applied to CSS declaration values.'
);

$this->assertSame(
'background:var(--wp--preset--color--primary, 10px);font-size:clamp(36.00rem, calc(32.00rem + 10.00vw), 40.00rem);width:min(150vw, 100px);min-width:max(150vw, 100px);max-width:minmax(400px, 50%);padding:calc(80px * -1);background-image:url("https://wordpress.org");',
'background:var(--wp--preset--color--primary, 10px);font-size:clamp(36.00rem, calc(32.00rem + 10.00vw), 40.00rem);width:min(150vw, 100px);min-width:max(150vw, 100px);max-width:minmax(400px, 50%);padding:calc(80px * -1);background-image:url("https://wordpress.org");--wp--style--unstable-gallery-gap:12em;border-width:2000.75em;',
$css_declarations_string,
'Unsafe values were not removed'
);
Expand Down Expand Up @@ -215,26 +217,6 @@ public function data_should_compile_css_declarations_to_css_declarations_string(
);
}

/**
* Tests allows --wp--* CSS custom properties.
*/
public function test_should_allow_wp_custom_properties() {
$input_declarations = array(
'--wp--love-your-work' => 'url("https://wordpress.org")',
'--wp--style--unstable-gallery-gap' => '12em',
'--wp-yeah-nah' => '100%',
'--wp--preset--here-is-a-potato' => '88px',
'--wp--style--/::target-[<nonsense>]' => '2000.75em',
'--wp--style--block-gap' => '2em',
);
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );

$this->assertSame(
'--wp--style--unstable-gallery-gap:12em;',
$css_declarations->get_declarations_string()
);
}

/**
* Tests removing a single declaration.
*
Expand Down

0 comments on commit 5d42cc4

Please sign in to comment.