@wordpress/style-engine 0.15.1-next.957ca95e4c.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -30
  2. package/README.md +36 -32
  3. package/build/index.js +6 -2
  4. package/build/index.js.map +1 -1
  5. package/build/styles/index.js +3 -1
  6. package/build/styles/index.js.map +1 -1
  7. package/build/styles/outline/index.js +47 -0
  8. package/build/styles/outline/index.js.map +1 -0
  9. package/build-module/index.js +6 -2
  10. package/build-module/index.js.map +1 -1
  11. package/build-module/styles/index.js +2 -1
  12. package/build-module/styles/index.js.map +1 -1
  13. package/build-module/styles/outline/index.js +38 -0
  14. package/build-module/styles/outline/index.js.map +1 -0
  15. package/build-types/index.d.ts +6 -2
  16. package/build-types/index.d.ts.map +1 -1
  17. package/build-types/styles/index.d.ts +1 -1
  18. package/build-types/styles/index.d.ts.map +1 -1
  19. package/build-types/styles/outline/index.d.ts +10 -0
  20. package/build-types/styles/outline/index.d.ts.map +1 -0
  21. package/class-wp-style-engine-css-declarations.php +14 -15
  22. package/class-wp-style-engine-css-rule.php +14 -14
  23. package/class-wp-style-engine-css-rules-store.php +7 -7
  24. package/class-wp-style-engine-processor.php +18 -6
  25. package/class-wp-style-engine.php +82 -185
  26. package/docs/using-the-style-engine-with-block-supports.md +151 -0
  27. package/package.json +4 -3
  28. package/phpunit/class-wp-style-engine-css-declarations-test.php +142 -95
  29. package/phpunit/class-wp-style-engine-css-rule-test.php +50 -21
  30. package/phpunit/class-wp-style-engine-css-rules-store-test.php +75 -58
  31. package/phpunit/class-wp-style-engine-processor-test.php +85 -37
  32. package/phpunit/{class-wp-style-engine-test.php → style-engine-test.php} +76 -50
  33. package/src/index.ts +6 -2
  34. package/src/styles/index.ts +2 -0
  35. package/src/styles/outline/index.ts +55 -0
  36. package/style-engine.php +154 -0
  37. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,151 @@
1
+ # Using the Style Engine to generate block supports styles
2
+
3
+ [Block supports](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/) is the API that allows a block to declare support for certain features.
4
+
5
+ Where a block declares support for a specific style group or property, e.g., "spacing" or "spacing.padding", the block's attributes are extended to include a **style object**.
6
+
7
+ For example:
8
+
9
+ ```json
10
+ {
11
+ "attributes": {
12
+ "style": {
13
+ "spacing": {
14
+ "margin": {
15
+ "top": "10px"
16
+ },
17
+ "padding": "1em"
18
+ },
19
+ "typography": {
20
+ "fontSize": "2.2rem"
21
+ }
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ Using this object, the Style Engine can generate the classes and CSS required to style the block element.
28
+
29
+ The global function `wp_style_engine_get_styles` accepts a style object as its first argument, and will output compiled CSS and an array of CSS declaration property/value pairs.
30
+
31
+ ```php
32
+ $block_styles = array(
33
+ 'spacing' => array( 'padding' => '10px', 'margin' => array( 'top' => '1em') ),
34
+ 'typography' => array( 'fontSize' => '2.2rem' ),
35
+ );
36
+ $styles = wp_style_engine_get_styles(
37
+ $block_styles
38
+ );
39
+ print_r( $styles );
40
+
41
+ /*
42
+ array(
43
+ 'css' => 'padding:10px;margin-top:1em;font-size:2.2rem',
44
+ 'declarations' => array( 'padding' => '10px', 'margin-top' => '1em', 'font-size' => '2.2rem' )
45
+ )
46
+ */
47
+ ```
48
+
49
+ ## Checking for block support and skip serialization
50
+
51
+ Before passing the block style object to the Style Engine, it's important to take into account:
52
+
53
+ 1. whether the theme has elected to support a particular block style, and
54
+ 2. whether a block has elected to "skip serialization" of that particular block style, that is, opt-out of automatic application of styles to the block's element (usually in order to do it via the block's internals). See the [block API documentation](https://developer.wordpress.org/block-editor/explanations/architecture/styles/#block-supports-api) for further information.
55
+
56
+ If a block either:
57
+
58
+ - has no support for a specific style, or
59
+ - skips serialization of that style
60
+
61
+ it's likely that you'll want to remove those style values from the style object.
62
+
63
+ For example:
64
+
65
+ ```php
66
+ // Check if a block has support using block_has_support (https://developer.wordpress.org/reference/functions/block_has_support/)
67
+ $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false ); // Returns true.
68
+ $has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false ); // Returns false.
69
+
70
+ // Check skipping of serialization.
71
+ $should_skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' ); // Returns true.
72
+ $should_skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' ); // Returns false.
73
+
74
+ // Now build the styles object.
75
+ $spacing_block_styles = array();
76
+ $spacing_block_styles['padding'] = $has_padding_support && ! $skip_padding ? _wp_array_get( $block_attributes['style'], array( 'spacing', 'padding' ), null ) : null;
77
+ $spacing_block_styles['margin'] = $has_margin_support && ! $skip_margin ? _wp_array_get( $block_attributes['style'], array( 'spacing', 'margin' ), null ) : null;
78
+
79
+ // Now get the styles.
80
+ $styles = wp_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
81
+
82
+ print_r( $styles );
83
+
84
+ /*
85
+ // Nothing, because there's no support for margin and the block skip's serialization for padding.
86
+ array()
87
+ */
88
+ ```
89
+
90
+ ## Generating classnames and CSS custom selectors from presets
91
+
92
+ Many of theme.json's presets will generate both CSS custom properties and CSS rules (consisting of a selector and the CSS declarations) on the frontend.
93
+
94
+ Styling a block using these presets normally involves adding the selector to the "className" attribute of the block.
95
+
96
+ For styles that can have preset values, such as text color and font family, the Style Engine knows how to construct the classnames using the preset slug.
97
+
98
+ To discern CSS values from preset values however, the Style Engine expects a special format.
99
+
100
+ Preset values must follow the pattern `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`.
101
+
102
+ When the Style Engine encounters these values, it will parse them and create a CSS value of `var(--wp--preset--font-size--small)` and/or generate a classname if required.
103
+
104
+ Example:
105
+
106
+ ```php
107
+ // Let's say the block attributes styles contain a fontSize preset slug of "small".
108
+ $preset_font_size = "var:preset|font-size|{$block_attributes['fontSize']}";
109
+ // Now let's say the block attributes styles contain a backgroundColor preset slug of "blue".
110
+ $preset_background_color = "var:preset|color|{$block_attributes['backgroundColor']}";
111
+
112
+ $block_styles = array(
113
+ 'typography' => array( 'fontSize' => $preset_font_size ),
114
+ 'color' => array( 'background' => $preset_background_color )
115
+ );
116
+
117
+ $styles = wp_style_engine_get_styles(
118
+ $block_styles
119
+ );
120
+ print_r( $styles );
121
+
122
+ /*
123
+ array(
124
+ 'css' => 'background-color:var(--wp--preset--color--blue);font-size:var(--wp--preset--font-size--small);',
125
+ 'classnames' => 'has-background-color has-blue-background-color has-small-font-size',
126
+ )
127
+ */
128
+ ```
129
+
130
+ If you don't want the Style Engine to output the CSS custom vars as well, which you might not if you're applying both the CSS and classnames to the block element, you can pass `'convert_vars_to_classnames' => true` in the options array.
131
+
132
+ ```php
133
+ $options = array(
134
+ // Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
135
+ 'convert_vars_to_classnames' => 'true',
136
+ );
137
+ $styles = wp_style_engine_get_styles(
138
+ $block_styles,
139
+ $options
140
+ );
141
+ print_r( $styles );
142
+
143
+ /*
144
+ array(
145
+ 'css' => 'letter-spacing:12px;', // non-preset-based CSS will still be compiled.
146
+ 'classnames' => 'has-background-color has-blue-background-color has-small-font-size',
147
+ )
148
+ */
149
+ ```
150
+
151
+ Read more about [global styles](https://developer.wordpress.org/block-editor/explanations/architecture/styles/#global-styles) and [preset CSS custom properties](https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/#css-custom-properties-presets-custom) and [theme supports](https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/).
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@wordpress/style-engine",
3
- "version": "0.15.1-next.957ca95e4c.0",
4
- "description": "WordPress Style engine.",
3
+ "version": "1.0.0",
4
+ "description": "A suite of parsers and compilers for WordPress styles.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
7
7
  "keywords": [
8
8
  "wordpress",
9
9
  "gutenberg",
10
10
  "styles",
11
+ "css",
11
12
  "global styles"
12
13
  ],
13
14
  "homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/style-engine/README.md",
@@ -34,5 +35,5 @@
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "272a74bbbaab10ee24424eafe9578e705fbfbbb4"
38
+ "gitHead": "56ef3f5a754e44155ee79e827c7a1d0efc1ee5aa"
38
39
  }
@@ -6,16 +6,26 @@
6
6
  * @subpackage style-engine
7
7
  */
8
8
 
9
- require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
9
+ // Check for the existence of Style Engine classes and methods.
10
+ // Once the Style Engine has been migrated to Core we can remove the if statements and require imports.
11
+ // Testing new features from the Gutenberg package may require
12
+ // testing against `gutenberg_` and `_Gutenberg` functions and methods in the future.
13
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Declarations' ) ) {
14
+ require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
15
+ }
10
16
 
11
17
  /**
12
- * Tests for registering, storing and generating CSS declarations.
18
+ * Tests registering, storing and generating CSS declarations.
19
+ *
20
+ * @coversDefaultClass WP_Style_Engine_CSS_Declarations
13
21
  */
14
22
  class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
15
23
  /**
16
- * Should set declarations on instantiation.
24
+ * Tests setting declarations on instantiation.
25
+ *
26
+ * @covers ::__construct
17
27
  */
18
- public function test_instantiate_with_declarations() {
28
+ public function test_should_instantiate_with_declarations() {
19
29
  $input_declarations = array(
20
30
  'margin-top' => '10px',
21
31
  'font-size' => '2rem',
@@ -25,22 +35,29 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
25
35
  }
26
36
 
27
37
  /**
28
- * Should add declarations.
38
+ * Tests that declarations are added.
39
+ *
40
+ * @covers ::add_declarations
41
+ * @covers ::add_declaration
29
42
  */
30
- public function test_add_declarations() {
43
+ public function test_should_add_declarations() {
31
44
  $input_declarations = array(
32
45
  'padding' => '20px',
33
46
  'color' => 'var(--wp--preset--elbow-patches)',
34
47
  );
35
48
  $css_declarations = new WP_Style_Engine_CSS_Declarations();
36
49
  $css_declarations->add_declarations( $input_declarations );
50
+
37
51
  $this->assertSame( $input_declarations, $css_declarations->get_declarations() );
38
52
  }
39
53
 
40
54
  /**
41
- * Should add declarations.
55
+ * Tests that new declarations are added to existing declarations.
56
+ *
57
+ * @covers ::add_declarations
58
+ * @covers ::add_declaration
42
59
  */
43
- public function test_add_a_single_declaration() {
60
+ public function test_should_add_new_declarations_to_existing() {
44
61
  $input_declarations = array(
45
62
  'border-width' => '1%',
46
63
  'background-color' => 'var(--wp--preset--english-mustard)',
@@ -50,13 +67,17 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
50
67
  'letter-spacing' => '1.5px',
51
68
  );
52
69
  $css_declarations->add_declarations( $extra_declaration );
70
+
53
71
  $this->assertSame( array_merge( $input_declarations, $extra_declaration ), $css_declarations->get_declarations() );
54
72
  }
55
73
 
56
74
  /**
57
- * Should sanitize properties before storing.
75
+ * Tests that properties are sanitized before storing.
76
+ *
77
+ * @covers ::filter_declaration
78
+ * @covers ::sanitize_property
58
79
  */
59
- public function test_sanitize_properties() {
80
+ public function test_should_sanitize_properties() {
60
81
  $input_declarations = array(
61
82
  '^--wp--style--sleepy-potato$' => '40px',
62
83
  '<background-//color>' => 'var(--wp--preset--english-mustard)',
@@ -73,123 +94,141 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
73
94
  }
74
95
 
75
96
  /**
76
- * Should compile css declarations into a css declarations block string.
97
+ * Tests that values with HTML tags are escaped, and CSS properties are run through safecss_filter_attr().
98
+ *
99
+ * @covers ::get_declarations_string
100
+ * @covers ::filter_declaration
77
101
  */
78
- public function test_generate_css_declarations_string() {
79
- $input_declarations = array(
80
- 'color' => 'red',
81
- 'border-top-left-radius' => '99px',
82
- 'text-decoration' => 'underline',
102
+ public function test_should_strip_html_tags_and_remove_unsafe_css_properties() {
103
+ $input_declarations = array(
104
+ 'font-size' => '<red/>',
105
+ 'padding' => '</style>',
106
+ 'potato' => 'uppercase',
107
+ 'cheese' => '10px',
108
+ 'margin-right' => '10em',
83
109
  );
84
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
110
+ $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
111
+ $safe_style_css_mock_action = new MockAction();
85
112
 
86
- $this->assertSame(
87
- 'color:red;border-top-left-radius:99px;text-decoration:underline;',
88
- $css_declarations->get_declarations_string()
89
- );
90
- }
113
+ // filter_declaration() is called in get_declarations_string().
114
+ add_filter( 'safe_style_css', array( $safe_style_css_mock_action, 'filter' ) );
115
+ $css_declarations_string = $css_declarations->get_declarations_string();
91
116
 
92
- /**
93
- * Should compile css declarations into a prettified css declarations block string.
94
- */
95
- public function test_generate_prettified_css_declarations_string() {
96
- $input_declarations = array(
97
- 'color' => 'red',
98
- 'border-top-left-radius' => '99px',
99
- 'text-decoration' => 'underline',
117
+ $this->assertSame(
118
+ 3, // Values with HTML tags are removed first by wp_strip_all_tags().
119
+ $safe_style_css_mock_action->get_call_count(),
120
+ '"safe_style_css" filters were not applied to CSS declaration properties.'
100
121
  );
101
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
102
122
 
103
123
  $this->assertSame(
104
- 'color: red; border-top-left-radius: 99px; text-decoration: underline;',
105
- $css_declarations->get_declarations_string( true )
124
+ 'margin-right:10em;',
125
+ $css_declarations_string,
126
+ 'Unallowed CSS properties or values with HTML tags were not removed.'
106
127
  );
107
128
  }
108
129
 
130
+
109
131
  /**
110
- * Should compile css declarations into a prettified and indented css declarations block string.
132
+ * Tests that calc, clamp, min, max, and minmax CSS functions are allowed.
133
+ *
134
+ * @covers ::get_declarations_string
135
+ * @covers ::filter_declaration
111
136
  */
112
- public function test_generate_prettified_with_indent_css_declarations_string() {
113
- $input_declarations = array(
114
- 'color' => 'red',
115
- 'border-top-left-radius' => '99px',
116
- 'text-decoration' => 'underline',
137
+ public function test_should_allow_css_functions_and_strip_unsafe_css_values() {
138
+ $input_declarations = array(
139
+ 'background' => 'var(--wp--preset--color--primary, 10px)', // Simple var().
140
+ 'font-size' => 'clamp(36.00rem, calc(32.00rem + 10.00vw), 40.00rem)', // Nested clamp().
141
+ 'width' => 'min(150vw, 100px)',
142
+ 'min-width' => 'max(150vw, 100px)',
143
+ 'max-width' => 'minmax(400px, 50%)',
144
+ 'padding' => 'calc(80px * -1)',
145
+ 'background-image' => 'url("https://wordpress.org")',
146
+ 'line-height' => 'url("https://wordpress.org")',
147
+ 'margin' => 'illegalfunction(30px)',
117
148
  );
118
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
149
+ $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
150
+ $safecss_filter_attr_allow_css_mock_action = new MockAction();
119
151
 
120
- $this->assertSame(
121
- ' color: red;
122
- border-top-left-radius: 99px;
123
- text-decoration: underline;',
124
- $css_declarations->get_declarations_string( true, 1 )
125
- );
126
- }
152
+ // filter_declaration() is called in get_declarations_string().
153
+ add_filter( 'safecss_filter_attr_allow_css', array( $safecss_filter_attr_allow_css_mock_action, 'filter' ) );
154
+ $css_declarations_string = $css_declarations->get_declarations_string();
127
155
 
128
- /**
129
- * Should compile css declarations into a css declarations block string.
130
- */
131
- public function test_generate_prettified_with_more_indents_css_declarations_string() {
132
- $input_declarations = array(
133
- 'color' => 'red',
134
- 'border-top-left-radius' => '99px',
135
- 'text-decoration' => 'underline',
156
+ $this->assertSame(
157
+ 9,
158
+ $safecss_filter_attr_allow_css_mock_action->get_call_count(),
159
+ '"safecss_filter_attr_allow_css" filters were not applied to CSS declaration values.'
136
160
  );
137
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
138
161
 
139
162
  $this->assertSame(
140
- ' color: red;
141
- border-top-left-radius: 99px;
142
- text-decoration: underline;',
143
- $css_declarations->get_declarations_string( true, 2 )
163
+ '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");',
164
+ $css_declarations_string,
165
+ 'Unsafe values were not removed'
144
166
  );
145
167
  }
146
168
 
147
169
  /**
148
- * Should escape values and run the CSS through safecss_filter_attr.
170
+ * Tests that CSS declarations are compiled into a CSS declarations block string.
171
+ *
172
+ * @covers ::get_declarations_string
173
+ *
174
+ * @dataProvider data_should_compile_css_declarations_to_css_declarations_string
175
+ *
176
+ * @param string $expected The expected declarations block string.
177
+ * @param bool $should_prettify Optional. Whether to pretty the string. Default false.
178
+ * @param int $indent_count Optional. The number of tab indents. Default false.
149
179
  */
150
- public function test_remove_unsafe_properties_and_values() {
180
+ public function test_should_compile_css_declarations_to_css_declarations_string( $expected, $should_prettify = false, $indent_count = 0 ) {
151
181
  $input_declarations = array(
152
- 'color' => 'url("https://wordpress.org")',
153
- 'font-size' => '<red/>',
154
- 'margin-right' => '10em',
155
- 'padding' => '</style>',
156
- 'potato' => 'uppercase',
182
+ 'color' => 'red',
183
+ 'border-top-left-radius' => '99px',
184
+ 'text-decoration' => 'underline',
157
185
  );
158
186
  $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
159
187
 
160
188
  $this->assertSame(
161
- 'margin-right:10em;',
162
- $css_declarations->get_declarations_string()
189
+ $expected,
190
+ $css_declarations->get_declarations_string( $should_prettify, $indent_count )
163
191
  );
164
192
  }
165
193
 
166
194
  /**
167
- * Should allow calc, clamp, min, max, and minmax CSS functions.
195
+ * Data provider for test_should_compile_css_declarations_to_css_declarations_string().
196
+ *
197
+ * @return array
168
198
  */
169
- public function test_allow_particular_css_functions() {
170
- $input_declarations = array(
171
- 'background' => 'var(--wp--preset--color--primary, 10px)', // Simple var().
172
- 'font-size' => 'clamp(36.00rem, calc(32.00rem + 10.00vw), 40.00rem)', // Nested clamp().
173
- 'width' => 'min(150vw, 100px)',
174
- 'min-width' => 'max(150vw, 100px)',
175
- 'max-width' => 'minmax(400px, 50%)',
176
- 'padding' => 'calc(80px * -1)',
177
- 'background-image' => 'url("https://wordpress.org")',
178
- 'line-height' => 'url("https://wordpress.org")',
179
- 'margin' => 'illegalfunction(30px)',
180
- );
181
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
182
-
183
- $this->assertSame(
184
- '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");',
185
- $css_declarations->get_declarations_string()
199
+ public function data_should_compile_css_declarations_to_css_declarations_string() {
200
+ return array(
201
+ 'unprettified, no indent' => array(
202
+ 'expected' => 'color:red;border-top-left-radius:99px;text-decoration:underline;',
203
+ ),
204
+ 'unprettified, one indent' => array(
205
+ 'expected' => 'color:red;border-top-left-radius:99px;text-decoration:underline;',
206
+ 'should_prettify' => false,
207
+ 'indent_count' => 1,
208
+ ),
209
+ 'prettified, no indent' => array(
210
+ 'expected' => 'color: red; border-top-left-radius: 99px; text-decoration: underline;',
211
+ 'should_prettify' => true,
212
+ ),
213
+ 'prettified, one indent' => array(
214
+ 'expected' => "\tcolor: red;\n\tborder-top-left-radius: 99px;\n\ttext-decoration: underline;",
215
+ 'should_prettify' => true,
216
+ 'indent_count' => 1,
217
+ ),
218
+ 'prettified, two indents' => array(
219
+ 'expected' => "\t\tcolor: red;\n\t\tborder-top-left-radius: 99px;\n\t\ttext-decoration: underline;",
220
+ 'should_prettify' => true,
221
+ 'indent_count' => 2,
222
+ ),
186
223
  );
187
224
  }
188
225
 
189
226
  /**
190
- * Should remove a declaration
227
+ * Tests removing a single declaration.
228
+ *
229
+ * @covers ::remove_declaration
191
230
  */
192
- public function test_remove_declaration() {
231
+ public function test_should_remove_single_declaration() {
193
232
  $input_declarations = array(
194
233
  'color' => 'tomato',
195
234
  'margin' => '10em 10em 20em 1px',
@@ -199,20 +238,25 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
199
238
 
200
239
  $this->assertSame(
201
240
  'color:tomato;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
202
- $css_declarations->get_declarations_string()
241
+ $css_declarations->get_declarations_string(),
242
+ 'CSS declarations string does not match the values of `$declarations` passed to the constructor.'
203
243
  );
204
244
 
205
245
  $css_declarations->remove_declaration( 'color' );
246
+
206
247
  $this->assertSame(
207
248
  'margin:10em 10em 20em 1px;font-family:Happy Font serif;',
208
- $css_declarations->get_declarations_string()
249
+ $css_declarations->get_declarations_string(),
250
+ 'Output after removing "color" declaration via `remove_declaration()` does not match expectations'
209
251
  );
210
252
  }
211
253
 
212
254
  /**
213
- * Should remove declarations
255
+ * Tests that multiple declarations are removed.
256
+ *
257
+ * @covers ::remove_declarations
214
258
  */
215
- public function test_remove_declarations() {
259
+ public function test_should_remove_multiple_declarations() {
216
260
  $input_declarations = array(
217
261
  'color' => 'cucumber',
218
262
  'margin' => '10em 10em 20em 1px',
@@ -222,13 +266,16 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
222
266
 
223
267
  $this->assertSame(
224
268
  'color:cucumber;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
225
- $css_declarations->get_declarations_string()
269
+ $css_declarations->get_declarations_string(),
270
+ 'CSS declarations string does not match the values of `$declarations` passed to the constructor.'
226
271
  );
227
272
 
228
273
  $css_declarations->remove_declarations( array( 'color', 'margin' ) );
274
+
229
275
  $this->assertSame(
230
276
  'font-family:Happy Font serif;',
231
- $css_declarations->get_declarations_string()
277
+ $css_declarations->get_declarations_string(),
278
+ 'Output after removing "color" and "margin" declarations via `remove_declarations()` does not match expectations'
232
279
  );
233
280
  }
234
281
  }