diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index b4f9ed1afcb98..da8a75d6e1e58 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -1474,87 +1474,86 @@ private function data_wp_class_processor( WP_Interactivity_API_Directives_Proces * It updates the style attribute value of the current HTML element based on * the evaluation of its associated references. * + * Each `data-wp-style--` entry removes every declaration of the + * property, then appends a declaration with the entry's value when the + * value is set. Other declarations keep their text. + * + * The value is converted to a string: + * + * - A string is used without surrounding whitespace. + * - `true` is `true`, and a number other than `0` is its string. + * - An empty string, `0` and any other value remove the property. + * + * A string that is not one valid CSS declaration value, such as one with a + * semicolon outside a string or block, or one ending in `!important`, is + * ignored and the property keeps its declarations, as `style.setProperty()` + * ignores it in the browser. + * * @since 6.5.0 + * @since 7.3.0 Parses the style attribute value as CSS. * * @param WP_Interactivity_API_Directives_Processor $p The directives processor instance. * @param string $mode Whether the processing is entering or exiting the tag. */ private function data_wp_style_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) { - if ( 'enter' === $mode ) { - $entries = $this->get_directive_entries( $p, 'style' ); - foreach ( $entries as $entry ) { - $style_property = $entry['suffix']; - if ( empty( $style_property ) || null !== $entry['unique_id'] ) { - continue; - } + if ( 'enter' !== $mode ) { + return; + } - $style_property_value = $this->evaluate( $entry ); - $style_attribute_value = $p->get_attribute( 'style' ); - $style_attribute_value = ( $style_attribute_value && ! is_bool( $style_attribute_value ) ) ? $style_attribute_value : ''; + // Maps each property name to its value, or to '' to remove the property. + $values = array(); + foreach ( $this->get_directive_entries( $p, 'style' ) as $entry ) { + if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) { + continue; + } - /* - * Checks first if the style property is not falsy and the style - * attribute value is not empty because if it is, it doesn't need to - * update the attribute value. - */ - if ( $style_property_value || $style_attribute_value ) { - $style_attribute_value = $this->merge_style_property( $style_attribute_value, $style_property, $style_property_value ); - /* - * If the style attribute value is not empty, it sets it. Otherwise, - * it removes it. - */ - if ( ! empty( $style_attribute_value ) ) { - $p->set_attribute( 'style', $style_attribute_value ); - } else { - $p->remove_attribute( 'style' ); - } - } + $value = $this->evaluate( $entry ); + if ( true === $value ) { + $value = 'true'; + } elseif ( is_int( $value ) || is_float( $value ) ) { + $value = $value ? (string) $value : ''; } - } - } - /** - * Merges an individual style property in the `style` attribute of an HTML - * element, updating or removing the property when necessary. - * - * If a property is modified, the old one is removed and the new one is added - * at the end of the list. - * - * @since 6.5.0 - * - * Example: - * - * merge_style_property( 'color:green;', 'color', 'red' ) => 'color:red;' - * merge_style_property( 'background:green;', 'color', 'red' ) => 'background:green;color:red;' - * merge_style_property( 'color:green;', 'color', null ) => '' - * - * @param string $style_attribute_value The current style attribute value. - * @param string $style_property_name The style property name to set. - * @param string|false|null $style_property_value The value to set for the style property. With false, null or an - * empty string, it removes the style property. - * @return string The new style attribute value after the specified property has been added, updated or removed. - */ - private function merge_style_property( string $style_attribute_value, string $style_property_name, $style_property_value ): string { - $style_assignments = explode( ';', $style_attribute_value ); - $result = array(); - $style_property_value = ! empty( $style_property_value ) ? rtrim( trim( $style_property_value ), ';' ) : null; - $new_style_property = $style_property_value ? $style_property_name . ':' . $style_property_value . ';' : ''; - - // Generates an array with all the properties but the modified one. - foreach ( $style_assignments as $style_assignment ) { - if ( empty( trim( $style_assignment ) ) ) { + $value = is_string( $value ) ? trim( $value ) : ''; + + // Only a value that can be written as one declaration replaces the property. + if ( '' !== $value && ! ( new WP_HTML_Style_Attribute_Processor( '' ) )->append_declaration( $entry['suffix'], $value ) ) { continue; } - list( $name, $value ) = explode( ':', $style_assignment ); - if ( trim( $name ) !== $style_property_name ) { - $result[] = trim( $name ) . ':' . trim( $value ) . ';'; + + $values[ $entry['suffix'] ] = $value; + } + + if ( empty( $values ) ) { + return; + } + + $style = $p->get_attribute( 'style' ); + $styles = new WP_HTML_Style_Attribute_Processor( $style ); + + while ( $styles->next_declaration() ) { + if ( isset( $values[ $styles->get_property_name() ] ) ) { + $styles->remove_declaration(); + } + } + + foreach ( $values as $name => $value ) { + if ( '' !== $value ) { + $styles->append_declaration( (string) $name, $value ); } } - // Adds the new/modified property at the end of the list. - $result[] = $new_style_property; + $original_style = is_string( $style ) ? $style : ''; + $updated_style = $styles->get_updated_style(); + if ( $original_style === $updated_style ) { + return; + } - return implode( '', $result ); + if ( '' === $updated_style ) { + $p->remove_attribute( 'style' ); + } else { + $p->set_attribute( 'style', $updated_style ); + } } /** diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php index 1a5884f34b8e6..6d1eb12221792 100644 --- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php @@ -36,129 +36,321 @@ public function set_up() { } /** - * Invokes the private `merge_style_property` method of WP_Interactivity_API - * class. - * - * @param string $style_attribute_value The current style attribute value. - * @param string $style_property_name The style property name to set. - * @param string|false|null $style_property_value The value to set for the style property. With false, null or an - * empty string, it removes the style property. - * @return string The new style attribute value after the specified property has been added, updated or removed. - */ - private function merge_style_property( $style_attribute_value, $style_property_name, $style_property_value ) { - $evaluate = new ReflectionMethod( $this->interactivity, 'merge_style_property' ); - if ( PHP_VERSION_ID < 80100 ) { - $evaluate->setAccessible( true ); + * Invokes the `process_directives` method of WP_Interactivity_API class. + * + * @param string $html The HTML that needs to be processed. + * @return array An array containing an instance of the WP_HTML_Tag_Processor and the processed HTML. + */ + private function process_directives( $html ) { + $new_html = $this->interactivity->process_directives( $html ); + $p = new WP_HTML_Tag_Processor( $new_html ); + $p->next_tag(); + return array( $p, $new_html ); + } + + /** + * Processes a `div` element with one `data-wp-style` entry per property. + * + * @param string|null $style Style attribute value, or null for no style attribute. + * @param array $properties Values to evaluate, keyed by property name. + * @return string|true|null Style attribute value after processing. + */ + private function style_after_directives( ?string $style, array $properties ) { + $interactivity = new WP_Interactivity_API(); + $state = array(); + $html = 'invokeArgs( $this->interactivity, array( $style_attribute_value, $style_property_name, $style_property_value ) ); + foreach ( array_keys( $properties ) as $i => $name ) { + $state[ "p{$i}" ] = $properties[ $name ]; + $html .= " data-wp-style--{$name}=\"styleTest::state.p{$i}\""; + } + $html .= '>Text'; + + $interactivity->state( 'styleTest', $state ); + $p = new WP_HTML_Tag_Processor( $interactivity->process_directives( $html ) ); + $p->next_tag(); + return $p->get_attribute( 'style' ); } /** - * Tests that `merge_style_property` correctly sets style properties. + * Tests that the `data-wp-style` directive sets style properties. * * @ticket 60356 * - * @covers ::merge_style_property + * @covers ::process_directives */ - public function test_merge_style_property_sets_properties() { + public function test_wp_style_sets_properties() { // Adds property on empty style attribute. - $result = $this->merge_style_property( '', 'color', 'green' ); - $this->assertSame( 'color:green;', $result ); + $this->assertSame( 'color: green;', $this->style_after_directives( '', array( 'color' => 'green' ) ) ); // Changes style property when there is an existing property. - $result = $this->merge_style_property( 'color:red;', 'color', 'green' ); - $this->assertSame( 'color:green;', $result ); + $this->assertSame( 'color: green;', $this->style_after_directives( 'color:red;', array( 'color' => 'green' ) ) ); // Adds a new property when the existing one does not match. - $result = $this->merge_style_property( 'color:red;', 'background', 'blue' ); - $this->assertSame( 'color:red;background:blue;', $result ); + $this->assertSame( 'color:red; background: blue;', $this->style_after_directives( 'color:red;', array( 'background' => 'blue' ) ) ); // Handles multiple existing properties. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'color', 'green' ); - $this->assertSame( 'margin:5px;color:green;', $result ); + $this->assertSame( 'margin:5px; color: green;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => 'green' ) ) ); // Adds a new property when multiple existing properties do not match. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'padding', '10px' ); - $this->assertSame( 'color:red;margin:5px;padding:10px;', $result ); + $this->assertSame( 'color:red;margin:5px; padding: 10px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'padding' => '10px' ) ) ); - // Removes whitespaces in all properties. - $result = $this->merge_style_property( ' color : red; margin : 5px; ', 'padding', ' 10px ' ); - $this->assertSame( 'color:red;margin:5px;padding:10px;', $result ); + // Keeps whitespace in existing declarations and trims the new value. + $this->assertSame( ' color : red; margin : 5px; padding: 10px;', $this->style_after_directives( ' color : red; margin : 5px; ', array( 'padding' => ' 10px ' ) ) ); // Updates a property when it's not the first one in the value. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'margin', '15px' ); - $this->assertSame( 'color:red;margin:15px;', $result ); + $this->assertSame( 'color:red; margin: 15px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'margin' => '15px' ) ) ); // Adds missing trailing semicolon. - $result = $this->merge_style_property( 'color:red;margin:5px', 'padding', '10px' ); - $this->assertSame( 'color:red;margin:5px;padding:10px;', $result ); + $this->assertSame( 'color:red;margin:5px; padding: 10px;', $this->style_after_directives( 'color:red;margin:5px', array( 'padding' => '10px' ) ) ); - // Doesn't add double semicolons. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'padding', '10px;' ); - $this->assertSame( 'color:red;margin:5px;padding:10px;', $result ); + // Ignores a value with a trailing semicolon, which is not one declaration value. + $this->assertSame( 'color:red;margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'padding' => '10px;' ) ) ); - // Handles empty properties in the input. - $result = $this->merge_style_property( 'color:red;;margin:5px;;', 'padding', '10px' ); - $this->assertSame( 'color:red;margin:5px;padding:10px;', $result ); + // Keeps empty declarations in the input. + $this->assertSame( 'color:red;;margin:5px;; padding: 10px;', $this->style_after_directives( 'color:red;;margin:5px;;', array( 'padding' => '10px' ) ) ); // Moves the modified property to the end. - $result = $this->merge_style_property( 'border-style: dashed; border: 3px solid red;', 'border-style', 'inset' ); - $this->assertSame( 'border:3px solid red;border-style:inset;', $result ); + $this->assertSame( 'border: 3px solid red; border-style: inset;', $this->style_after_directives( 'border-style: dashed; border: 3px solid red;', array( 'border-style' => 'inset' ) ) ); } /** - * Tests that `merge_style_property` works correctly with falsy values, - * removing or ignoring them as appropriate. + * Tests that the `data-wp-style` directive removes a property, or adds + * nothing, for falsy values. * * @ticket 60356 * - * @covers ::merge_style_property + * @covers ::process_directives */ - public function test_merge_style_property_with_falsy_values() { - // Removes a property with an empty string. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'color', '' ); - $this->assertSame( 'margin:5px;', $result ); + public function test_wp_style_with_falsy_values() { + foreach ( array( '', null, false, 0, 0.0, array() ) as $value ) { + $this->assertSame( 'margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => $value ) ), 'Removes the property with ' . var_export( $value, true ) ); + $this->assertSame( 'color:red;', $this->style_after_directives( 'color:red;', array( 'padding' => $value ) ), 'Adds nothing with ' . var_export( $value, true ) ); + } + } - // Removes a property with null. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'color', null ); - $this->assertSame( 'margin:5px;', $result ); + /** + * Tests that the `data-wp-style` directive writes non-falsy scalar values + * as strings. + * + * The string `'0'` sets the property, `true` is written as `true`, and a + * number is written as its string. + * + * @covers ::process_directives + */ + public function test_wp_style_writes_scalar_values_as_strings() { + $this->assertSame( 'opacity: 0;', $this->style_after_directives( 'opacity:1', array( 'opacity' => '0' ) ) ); + $this->assertSame( '--flag: true;', $this->style_after_directives( null, array( '--flag' => true ) ) ); + $this->assertSame( 'z-index: 5;', $this->style_after_directives( null, array( 'z-index' => 5 ) ) ); + $this->assertSame( 'opacity: 0.5;', $this->style_after_directives( null, array( 'opacity' => 0.5 ) ) ); + } - // Removes a property with false. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'color', false ); - $this->assertSame( 'margin:5px;', $result ); + /** + * Tests that the `data-wp-style` directive removes the property for a value + * that is not a string, number or boolean. + * + * @covers ::process_directives + */ + public function test_wp_style_removes_property_for_non_scalar_values() { + $this->assertSame( 'margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => array( 'green' ) ) ) ); + $this->assertSame( 'margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => (object) array( 'a' => 'green' ) ) ) ); + } - // Removes a property with 0. - $result = $this->merge_style_property( 'color:red;margin:5px;', 'color', 0 ); - $this->assertSame( 'margin:5px;', $result ); + /** + * Tests that the `data-wp-style` directive preserves values containing a colon. + * + * Only the first colon in a declaration separates the property name from its + * value, so a value may contain more of them. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_preserves_values_containing_colons() { + // Keeps an untouched property whose value contains a URL. + $this->assertSame( + 'background-image:url(https://example.com/a.png); color: green;', + $this->style_after_directives( 'background-image:url(https://example.com/a.png)', array( 'color' => 'green' ) ) + ); - // It doesn't add a new property with an empty string. - $result = $this->merge_style_property( 'color:red;', 'padding', '' ); - $this->assertSame( 'color:red;', $result ); + // Replaces a property whose previous value contained a URL. + $this->assertSame( + 'background-image: none;', + $this->style_after_directives( 'background-image:url(https://example.com/a.png)', array( 'background-image' => 'none' ) ) + ); - // It doesn't add a new property with null. - $result = $this->merge_style_property( 'color:red;', 'padding', null ); - $this->assertSame( 'color:red;', $result ); + // Keeps every colon after the first, not only the second. + $this->assertSame( + '--fallback:url(https://a.test/x.png), url(https://b.test/y.png); color: green;', + $this->style_after_directives( '--fallback:url(https://a.test/x.png), url(https://b.test/y.png);', array( 'color' => 'green' ) ) + ); + } - // It doesn't add a new property with false. - $result = $this->merge_style_property( 'color:red;', 'padding', false ); - $this->assertSame( 'color:red;', $result ); + /** + * Tests that the `data-wp-style` directive preserves values containing a + * semicolon. + * + * A semicolon inside a quoted string or a `url()` does not end a declaration. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_preserves_values_containing_semicolons() { + // Keeps a quoted value containing a semicolon. + $this->assertSame( + 'font-family:"Foo;Bar",serif; color: green;', + $this->style_after_directives( 'font-family:"Foo;Bar",serif', array( 'color' => 'green' ) ) + ); + + // Keeps a data URI, which contains both a colon and a semicolon. + $this->assertSame( + 'background-image:url(data:image/gif;base64,R0lGODlhAQ); color: green;', + $this->style_after_directives( 'background-image:url(data:image/gif;base64,R0lGODlhAQ)', array( 'color' => 'green' ) ) + ); - // It doesn't add a new property with 0. - $result = $this->merge_style_property( 'color:red;', 'padding', 0 ); - $this->assertSame( 'color:red;', $result ); + // Replaces a property whose value contains a quoted semicolon. + $this->assertSame( + 'color:red; font-family: serif;', + $this->style_after_directives( 'font-family:"Foo;Bar",serif;color:red', array( 'font-family' => 'serif' ) ) + ); } /** - * Invokes the `process_directives` method of WP_Interactivity_API class. + * Tests that the `data-wp-style` directive sets a value containing a + * semicolon inside a string or a `url()`. * - * @param string $html The HTML that needs to be processed. - * @return array An array containing an instance of the WP_HTML_Tag_Processor and the processed HTML. + * The appended value is written from its tokens, which escapes a semicolon + * in a string and a semicolon or comma in a `url()`. + * + * @ticket 63899 + * + * @covers ::process_directives */ - private function process_directives( $html ) { - $new_html = $this->interactivity->process_directives( $html ); - $p = new WP_HTML_Tag_Processor( $new_html ); - $p->next_tag(); - return array( $p, $new_html ); + public function test_wp_style_sets_values_containing_semicolons() { + $this->assertSame( + 'color:red; font-family: "Foo\\3b Bar", serif;', + $this->style_after_directives( 'color:red', array( 'font-family' => '"Foo;Bar", serif' ) ) + ); + + $this->assertSame( + 'background-image: url(data:image/gif\\3b base64\\2c R0lGODlhAQ);', + $this->style_after_directives( null, array( 'background-image' => 'url(data:image/gif;base64,R0lGODlhAQ)' ) ) + ); + } + + /** + * Tests that the `data-wp-style` directive keeps segments that contain no + * colon. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_handles_segments_without_a_colon() { + $this->assertSame( + 'translate:none;translate3d(0px, 0px, 0px); color: green;', + $this->style_after_directives( 'translate:none;translate3d(0px, 0px, 0px);', array( 'color' => 'green' ) ) + ); + } + + /** + * Tests that the `data-wp-style` directive matches property names as CSS + * does. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_matches_property_names() { + // Replaces a standard property written in any case. + $this->assertSame( 'margin:5px; color: green;', $this->style_after_directives( 'COLOR:red;margin:5px;', array( 'color' => 'green' ) ) ); + + // Replaces only the custom property with the same case. + $this->assertSame( '--MyVar:1; --myvar: 3;', $this->style_after_directives( '--MyVar:1;--myvar:2;', array( '--myvar' => '3' ) ) ); + + // Removes every declaration of the property. + $this->assertSame( 'margin:5px; color: green;', $this->style_after_directives( 'color:red;margin:5px;color:blue;', array( 'color' => 'green' ) ) ); + } + + /** + * Tests that the `data-wp-style` directive replaces a declaration with an + * `!important` priority. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_replaces_important_declaration() { + $this->assertSame( 'margin:5px; color: blue;', $this->style_after_directives( 'color: red !important; margin:5px;', array( 'color' => 'blue' ) ) ); + $this->assertSame( 'margin:5px;', $this->style_after_directives( 'color: red !important; margin:5px;', array( 'color' => false ) ) ); + } + + /** + * Tests that the `data-wp-style` directive applies several entries on one + * element: it replaces, removes and adds properties in one style attribute. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_applies_several_entries() { + $this->assertSame( + 'margin: 0 auto; padding: 1em; width: 50%; background: url(https://example.com/b.png); color: blue;', + $this->style_after_directives( + 'color: red; margin: 0 auto; background: url(https://example.com/a.png); padding: 1em; height: 10px; width: 50%', + array( + 'color' => 'blue', + 'height' => false, + 'background' => 'url(https://example.com/b.png)', + ) + ) + ); + } + + /** + * Tests that the `data-wp-style` directive ignores a value that is not one + * valid declaration value and keeps the property's declarations. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_ignores_invalid_values() { + // A value with an unclosed function. + $this->assertSame( 'color:red;margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => 'rgb(0 0 0' ) ) ); + + // A value with an !important priority. + $this->assertSame( 'color:red;margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => 'green !important' ) ) ); + + // A value with a closing brace. + $this->assertSame( 'color:red;margin:5px;', $this->style_after_directives( 'color:red;margin:5px;', array( 'color' => 'green}' ) ) ); + + // An invalid value leaves the other entries on the element in effect. + $this->assertSame( + 'margin:5px; color: blue;', + $this->style_after_directives( + 'color:red;margin:5px;', + array( + 'color' => 'blue', + 'padding' => '1px}', + ) + ) + ); + } + + /** + * Tests that the `data-wp-style` directive keeps the style attribute text + * when no declaration changes. + * + * @ticket 63899 + * + * @covers ::process_directives + */ + public function test_wp_style_keeps_style_attribute_text_when_unchanged() { + $this->assertSame( ' padding : 10px ;; ', $this->style_after_directives( ' padding : 10px ;; ', array( 'color' => false ) ) ); } /** @@ -172,7 +364,7 @@ private function process_directives( $html ) { public function test_wp_style_sets_style_attribute() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'color: green;', $p->get_attribute( 'style' ) ); } /** @@ -190,7 +382,7 @@ public function test_wp_style_sets_multiple_style_properties() { data-wp-style--background="myPlugin::state.green" >Text'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'background:green;color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'background: green; color: green;', $p->get_attribute( 'style' ) ); } /** @@ -208,7 +400,7 @@ public function test_wp_style_sets_multiple_style_properties_with_different_valu data-wp-style--background="myPlugin::state.false" >Text'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'color: green;', $p->get_attribute( 'style' ) ); $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'color: green;', $p->get_attribute( 'style' ) ); } /** @@ -231,7 +423,7 @@ public function test_wp_style_sets_multiple_style_properties_with_different_valu public function test_wp_style_sets_style_property_when_style_attribute_exists() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'padding:10px;color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'padding:10px; color: green;', $p->get_attribute( 'style' ) ); } /** @@ -245,7 +437,7 @@ public function test_wp_style_sets_style_property_when_style_attribute_exists() public function test_wp_style_overwrites_style_property_when_style_property_exists() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'color: green;', $p->get_attribute( 'style' ) ); } /** @@ -287,7 +479,7 @@ public function test_wp_style_doesnt_add_style_property_on_false() { public function test_wp_style_keeps_style_property_when_style_property_exists() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'color: green;', $p->get_attribute( 'style' ) ); } /** @@ -301,7 +493,7 @@ public function test_wp_style_keeps_style_property_when_style_property_exists() public function test_wp_style_keeps_style_property_when_style_property_exists_and_is_not_the_only_one() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'padding:10px;color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'padding:10px; color: green;', $p->get_attribute( 'style' ) ); } /** @@ -372,7 +564,7 @@ public function test_wp_style_doesnt_change_style_attribute_with_empty_directive public function test_wp_style_doesnt_change_style_attribute_with_empty_value() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'padding:10px', $p->get_attribute( 'style' ) ); } /** @@ -387,7 +579,7 @@ public function test_wp_style_doesnt_change_style_attribute_with_empty_value() { public function test_wp_style_doesnt_change_style_attribute_without_value() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'padding: 10px;', $p->get_attribute( 'style' ) ); } /** @@ -401,7 +593,7 @@ public function test_wp_style_doesnt_change_style_attribute_without_value() { public function test_wp_style_works_with_multiple_directives() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( 'color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'color: green;', $p->get_attribute( 'style' ) ); } /** @@ -459,7 +651,7 @@ public function test_wp_style_doesnt_add_style_property_on_falsy_values() { public function test_wp_style_can_use_CSS_variables() { $html = '
Text
'; list($p) = $this->process_directives( $html ); - $this->assertSame( '--text-color:green;', $p->get_attribute( 'style' ) ); + $this->assertSame( '--text-color: green;', $p->get_attribute( 'style' ) ); } /** diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php index 561c1c4eca93e..32e9afba95240 100644 --- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php @@ -1356,7 +1356,7 @@ public function test_process_directives_process_the_directives_in_the_correct_or $p->next_tag(); $this->assertSame( 'some-id', $p->get_attribute( 'id' ) ); $this->assertSame( 'some-class', $p->get_attribute( 'class' ) ); - $this->assertSame( 'display:none;', $p->get_attribute( 'style' ) ); + $this->assertSame( 'display: none;', $p->get_attribute( 'style' ) ); $this->assertStringContainsString( 'Updated', $p->get_updated_html() ); $this->assertStringNotContainsString( 'Text', $p->get_updated_html() ); }