@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
@@ -6,17 +6,30 @@
6
6
  * @subpackage style-engine
7
7
  */
8
8
 
9
- require __DIR__ . '/../class-wp-style-engine-css-rule.php';
10
- 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
+ }
16
+
17
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
18
+ require __DIR__ . '/../class-wp-style-engine-css-rule.php';
19
+ }
11
20
 
12
21
  /**
13
- * Tests for registering, storing and generating CSS declarations.
22
+ * Tests for registering, storing and generating CSS rules.
23
+ *
24
+ * @coversDefaultClass WP_Style_Engine_CSS_Rule
14
25
  */
15
26
  class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
16
27
  /**
17
- * Should set declarations on instantiation.
28
+ * Tests that declarations are set on instantiation.
29
+ *
30
+ * @covers ::__construct
18
31
  */
19
- public function test_instantiate_with_selector_and_rules() {
32
+ public function test_should_instantiate_with_selector_and_rules() {
20
33
  $selector = '.law-and-order';
21
34
  $input_declarations = array(
22
35
  'margin-top' => '10px',
@@ -25,16 +38,20 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
25
38
  $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
26
39
  $css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
27
40
 
28
- $this->assertSame( $selector, $css_rule->get_selector() );
41
+ $this->assertSame( $selector, $css_rule->get_selector(), 'Return value of get_selector() does not match value passed to constructor.' );
29
42
 
30
43
  $expected = "$selector{{$css_declarations->get_declarations_string()}}";
31
- $this->assertSame( $expected, $css_rule->get_css() );
44
+
45
+ $this->assertSame( $expected, $css_rule->get_css(), 'Value returned by get_css() does not match expected declarations string.' );
32
46
  }
33
47
 
34
48
  /**
35
- * Test dedupe declaration properties.
49
+ * Tests that declaration properties are deduplicated.
50
+ *
51
+ * @covers ::add_declarations
52
+ * @covers ::get_css
36
53
  */
37
- public function test_dedupe_properties_in_rules() {
54
+ public function test_should_dedupe_properties_in_rules() {
38
55
  $selector = '.taggart';
39
56
  $first_declaration = array(
40
57
  'font-size' => '2rem',
@@ -50,9 +67,12 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
50
67
  }
51
68
 
52
69
  /**
53
- * Should add declarations.
70
+ * Tests that declarations can be added to existing rules.
71
+ *
72
+ * @covers ::add_declarations
73
+ * @covers ::get_css
54
74
  */
55
- public function test_add_declarations() {
75
+ public function test_should_add_declarations_to_existing_rules() {
56
76
  // Declarations using a WP_Style_Engine_CSS_Declarations object.
57
77
  $some_css_declarations = new WP_Style_Engine_CSS_Declarations( array( 'margin-top' => '10px' ) );
58
78
  // Declarations using a property => value array.
@@ -61,27 +81,32 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
61
81
  $css_rule->add_declarations( $some_more_css_declarations );
62
82
 
63
83
  $expected = '.hill-street-blues{margin-top:10px;font-size:1rem;}';
84
+
64
85
  $this->assertSame( $expected, $css_rule->get_css() );
65
86
  }
66
87
 
67
88
  /**
68
- * Should set selector.
89
+ * Tests setting a selector to a rule.
90
+ *
91
+ * @covers ::set_selector
69
92
  */
70
- public function test_set_selector() {
93
+ public function test_should_set_selector() {
71
94
  $selector = '.taggart';
72
95
  $css_rule = new WP_Style_Engine_CSS_Rule( $selector );
73
96
 
74
- $this->assertSame( $selector, $css_rule->get_selector() );
97
+ $this->assertSame( $selector, $css_rule->get_selector(), 'Return value of get_selector() does not match value passed to constructor.' );
75
98
 
76
99
  $css_rule->set_selector( '.law-and-order' );
77
100
 
78
- $this->assertSame( '.law-and-order', $css_rule->get_selector() );
101
+ $this->assertSame( '.law-and-order', $css_rule->get_selector(), 'Return value of get_selector() does not match value passed to set_selector().' );
79
102
  }
80
103
 
81
104
  /**
82
- * Should generate CSS rules.
105
+ * Tests generating a CSS rule string.
106
+ *
107
+ * @covers ::get_css
83
108
  */
84
- public function test_get_css() {
109
+ public function test_should_generate_css_rule_string() {
85
110
  $selector = '.chips';
86
111
  $input_declarations = array(
87
112
  'margin-top' => '10px',
@@ -95,9 +120,11 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
95
120
  }
96
121
 
97
122
  /**
98
- * Should return empty string with no declarations.
123
+ * Tests that an empty string will be returned where there are no declarations in a CSS rule.
124
+ *
125
+ * @covers ::get_css
99
126
  */
100
- public function test_get_css_no_declarations() {
127
+ public function test_should_return_empty_string_with_no_declarations() {
101
128
  $selector = '.holmes';
102
129
  $input_declarations = array();
103
130
  $css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
@@ -107,9 +134,11 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
107
134
  }
108
135
 
109
136
  /**
110
- * Should generate prettified CSS rules.
137
+ * Tests that CSS rules are prettified.
138
+ *
139
+ * @covers ::get_css
111
140
  */
112
- public function test_get_prettified_css() {
141
+ public function test_should_prettify_css_rule_output() {
113
142
  $selector = '.baptiste';
114
143
  $input_declarations = array(
115
144
  'margin-left' => '0',
@@ -6,63 +6,93 @@
6
6
  * @subpackage style-engine
7
7
  */
8
8
 
9
- require __DIR__ . '/../class-wp-style-engine-css-rules-store.php';
10
- require __DIR__ . '/../class-wp-style-engine-css-rule.php';
11
- 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
+ }
16
+
17
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
18
+ require __DIR__ . '/../class-wp-style-engine-css-rule.php';
19
+ }
20
+
21
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Rules_Store' ) ) {
22
+ require __DIR__ . '/../class-wp-style-engine-css-rules-store.php';
23
+ }
12
24
 
13
25
  /**
14
- * Tests for registering, storing and retrieving CSS Rules.
26
+ * Tests for registering, storing and retrieving a collection of CSS Rules (a store).
27
+ *
28
+ * @coversDefaultClass WP_Style_Engine_CSS_Rules_Store
15
29
  */
16
30
  class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
17
31
  /**
18
- * Tear down after each test.
32
+ * Cleans up stores after each test.
19
33
  */
20
34
  public function tear_down() {
21
- parent::tear_down();
22
35
  WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
36
+ parent::tear_down();
23
37
  }
38
+
24
39
  /**
25
- * Should create a new store.
40
+ * Tests creating a new store on instantiation.
41
+ *
42
+ * @covers ::__construct
26
43
  */
27
- public function test_create_new_store() {
44
+ public function test_should_create_new_store_on_instantiation() {
28
45
  $new_pancakes_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'pancakes-with-strawberries' );
46
+
29
47
  $this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $new_pancakes_store );
30
48
  }
31
49
 
32
50
  /**
33
- * Should not create a new store with invalid $store_name.
51
+ * Tests that a `$store_name` argument is required and no store will be created without one.
52
+ *
53
+ * @covers ::get_store
34
54
  */
35
- public function test_store_name_required() {
55
+ public function test_should_not_create_store_without_a_store_name() {
36
56
  $not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( '' );
37
- $this->assertEmpty( $not_a_store );
57
+
58
+ $this->assertEmpty( $not_a_store, 'get_store() did not return an empty value with empty string as argument.' );
38
59
 
39
60
  $also_not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( 123 );
40
- $this->assertEmpty( $also_not_a_store );
61
+
62
+ $this->assertEmpty( $also_not_a_store, 'get_store() did not return an empty value with number as argument.' );
41
63
 
42
64
  $definitely_not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( null );
43
- $this->assertEmpty( $definitely_not_a_store );
65
+
66
+ $this->assertEmpty( $definitely_not_a_store, 'get_store() did not return an empty value with `null` as argument.' );
44
67
  }
45
68
 
46
69
  /**
47
- * Should return previously created store when the same selector key is passed.
70
+ * Tests returning a previously created store when the same selector key is passed.
71
+ *
72
+ * @covers ::get_store
48
73
  */
49
- public function test_get_store() {
74
+ public function test_should_return_existing_store() {
50
75
  $new_fish_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'fish-n-chips' );
51
76
  $selector = '.haddock';
52
77
 
53
- $new_fish_store->add_rule( $selector )->get_selector();
54
- $this->assertEquals( $selector, $new_fish_store->add_rule( $selector )->get_selector() );
78
+ $new_fish_store->add_rule( $selector );
79
+
80
+ $this->assertSame( $selector, $new_fish_store->add_rule( $selector )->get_selector(), 'Selector string of store rule does not match expected value' );
55
81
 
56
82
  $the_same_fish_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'fish-n-chips' );
57
- $this->assertEquals( $selector, $the_same_fish_store->add_rule( $selector )->get_selector() );
83
+
84
+ $this->assertSame( $selector, $the_same_fish_store->add_rule( $selector )->get_selector(), 'Selector string of existing store rule does not match expected value' );
58
85
  }
59
86
 
60
87
  /**
61
- * Should return all previously created stores.
88
+ * Tests returning all previously created stores.
89
+ *
90
+ * @covers ::get_stores
62
91
  */
63
- public function test_get_stores() {
92
+ public function test_should_get_all_existing_stores() {
64
93
  $burrito_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'burrito' );
65
94
  $quesadilla_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'quesadilla' );
95
+
66
96
  $this->assertEquals(
67
97
  array(
68
98
  'burrito' => $burrito_store,
@@ -73,34 +103,43 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
73
103
  }
74
104
 
75
105
  /**
76
- * Should delete all previously created stores.
106
+ * Tests that all previously created stores are deleted.
107
+ *
108
+ * @covers ::remove_all_stores
77
109
  */
78
- public function test_remove_all_stores() {
110
+ public function test_should_remove_all_stores() {
79
111
  $dolmades_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'dolmades' );
80
112
  $tzatziki_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'tzatziki' );
113
+
81
114
  $this->assertEquals(
82
115
  array(
83
116
  'dolmades' => $dolmades_store,
84
117
  'tzatziki' => $tzatziki_store,
85
118
  ),
86
- WP_Style_Engine_CSS_Rules_Store::get_stores()
119
+ WP_Style_Engine_CSS_Rules_Store::get_stores(),
120
+ 'Return value of get_stores() does not match expectation'
87
121
  );
88
122
  WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
123
+
89
124
  $this->assertEquals(
90
125
  array(),
91
- WP_Style_Engine_CSS_Rules_Store::get_stores()
126
+ WP_Style_Engine_CSS_Rules_Store::get_stores(),
127
+ 'Return value of get_stores() is not an empty array after remove_all_stores() called.'
92
128
  );
93
129
  }
94
130
 
95
131
  /**
96
- * Should return a stored rule.
132
+ * Tests adding rules to an existing store.
133
+ *
134
+ * @covers ::add_rule
97
135
  */
98
- public function test_add_rule() {
136
+ public function test_should_add_rule_to_existing_store() {
99
137
  $new_pie_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'meat-pie' );
100
138
  $selector = '.wp-block-sauce a:hover';
101
139
  $store_rule = $new_pie_store->add_rule( $selector );
102
140
  $expected = '';
103
- $this->assertEquals( $expected, $store_rule->get_css() );
141
+
142
+ $this->assertSame( $expected, $store_rule->get_css(), 'Return value of get_css() is not a empty string where a rule has no CSS declarations.' );
104
143
 
105
144
  $pie_declarations = array(
106
145
  'color' => 'brown',
@@ -112,13 +151,16 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
112
151
 
113
152
  $store_rule = $new_pie_store->add_rule( $selector );
114
153
  $expected = "$selector{{$css_declarations->get_declarations_string()}}";
115
- $this->assertEquals( $expected, $store_rule->get_css() );
154
+
155
+ $this->assertSame( $expected, $store_rule->get_css(), 'Return value of get_css() does not match expected CSS from existing store rules.' );
116
156
  }
117
157
 
118
158
  /**
119
- * Should return all stored rules.
159
+ * Tests that all stored rule objects are returned.
160
+ *
161
+ * @covers ::get_all_rules
120
162
  */
121
- public function test_get_all_rules() {
163
+ public function test_should_get_all_rule_objects_for_a_store() {
122
164
  $new_pizza_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'pizza-with-mozzarella' );
123
165
  $selector = '.wp-block-anchovies a:hover';
124
166
  $store_rule = $new_pizza_store->add_rule( $selector );
@@ -126,33 +168,7 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
126
168
  $selector => $store_rule,
127
169
  );
128
170
 
129
- $this->assertEquals( $expected, $new_pizza_store->get_all_rules() );
130
-
131
- $pizza_declarations = array(
132
- 'color' => 'red',
133
- 'border-color' => 'yellow',
134
- 'border-radius' => '10rem',
135
- );
136
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $pizza_declarations );
137
- $store_rule->add_declarations( array( $css_declarations ) );
138
-
139
- $expected = array(
140
- $selector => $store_rule,
141
- );
142
- $this->assertEquals( $expected, $new_pizza_store->get_all_rules() );
143
-
144
- $new_pizza_declarations = array(
145
- 'color' => 'red',
146
- 'border-color' => 'red',
147
- 'font-size' => '10rem',
148
- );
149
- $css_declarations = new WP_Style_Engine_CSS_Declarations( $new_pizza_declarations );
150
- $store_rule->add_declarations( array( $css_declarations ) );
151
-
152
- $expected = array(
153
- $selector => $store_rule,
154
- );
155
- $this->assertEquals( $expected, $new_pizza_store->get_all_rules() );
171
+ $this->assertSame( $expected, $new_pizza_store->get_all_rules(), 'Return value for get_all_rules() does not match expectations.' );
156
172
 
157
173
  $new_selector = '.wp-block-mushroom a:hover';
158
174
  $newer_pizza_declarations = array(
@@ -166,6 +182,7 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
166
182
  $selector => $store_rule,
167
183
  $new_selector => $new_store_rule,
168
184
  );
169
- $this->assertEquals( $expected, $new_pizza_store->get_all_rules() );
185
+
186
+ $this->assertSame( $expected, $new_pizza_store->get_all_rules(), 'Return value for get_all_rules() does not match expectations after adding new rules to store.' );
170
187
  }
171
188
  }
@@ -1,23 +1,44 @@
1
1
  <?php
2
2
  /**
3
- * Tests the Style Engine Renderer class.
3
+ * Tests the Style Engine Processor class.
4
4
  *
5
5
  * @package Gutenberg
6
6
  * @subpackage style-engine
7
7
  */
8
- require __DIR__ . '/../class-wp-style-engine-css-rules-store.php';
9
- require __DIR__ . '/../class-wp-style-engine-css-rule.php';
10
- require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
11
- require __DIR__ . '/../class-wp-style-engine-processor.php';
8
+
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_Processor' ) ) {
14
+ require __DIR__ . '/../class-wp-style-engine-processor.php';
15
+ }
16
+
17
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Declarations' ) ) {
18
+ require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
19
+ }
20
+
21
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
22
+ require __DIR__ . '/../class-wp-style-engine-css-rule.php';
23
+ }
24
+
25
+ if ( ! class_exists( 'WP_Style_Engine_CSS_Rules_Store' ) ) {
26
+ require __DIR__ . '/../class-wp-style-engine-css-rules-store.php';
27
+ }
12
28
 
13
29
  /**
14
30
  * Tests for compiling and rendering styles from a store of CSS rules.
31
+ *
32
+ * @coversDefaultClass WP_Style_Engine_Processor
15
33
  */
16
34
  class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
17
35
  /**
18
- * Should compile CSS rules.
36
+ * Tests adding rules and returning compiled CSS rules.
37
+ *
38
+ * @covers ::add_rules
39
+ * @covers ::get_css
19
40
  */
20
- public function test_return_rules_as_css() {
41
+ public function test_should_return_rules_as_compiled_css() {
21
42
  $a_nice_css_rule = new WP_Style_Engine_CSS_Rule( '.a-nice-rule' );
22
43
  $a_nice_css_rule->add_declarations(
23
44
  array(
@@ -35,16 +56,19 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
35
56
  );
36
57
  $a_nice_processor = new WP_Style_Engine_Processor();
37
58
  $a_nice_processor->add_rules( array( $a_nice_css_rule, $a_nicer_css_rule ) );
38
- $this->assertEquals(
59
+
60
+ $this->assertSame(
39
61
  '.a-nice-rule{color:var(--nice-color);background-color:purple;}.a-nicer-rule{font-family:Nice sans;font-size:1em;background-color:purple;}',
40
- $a_nice_processor->get_css()
62
+ $a_nice_processor->get_css( array( 'prettify' => false ) )
41
63
  );
42
64
  }
43
65
 
44
66
  /**
45
- * Should compile CSS rules.
67
+ * Tests compiling CSS rules and formatting them with new lines and indents.
68
+ *
69
+ * @covers ::get_css
46
70
  */
47
- public function test_return_prettified_rules_as_css() {
71
+ public function test_should_return_prettified_css_rules() {
48
72
  $a_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-wonderful-rule' );
49
73
  $a_wonderful_css_rule->add_declarations(
50
74
  array(
@@ -81,16 +105,18 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
81
105
  background-color: orange;
82
106
  }
83
107
  ';
84
- $this->assertEquals(
108
+ $this->assertSame(
85
109
  $expected,
86
110
  $a_wonderful_processor->get_css( array( 'prettify' => true ) )
87
111
  );
88
112
  }
89
113
 
90
114
  /**
91
- * Should compile CSS rules from the store.
115
+ * Tests adding a store and compiling CSS rules from that store.
116
+ *
117
+ * @covers ::add_store
92
118
  */
93
- public function test_return_store_rules_as_css() {
119
+ public function test_should_return_store_rules_as_css() {
94
120
  $a_nice_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'nice' );
95
121
  $a_nice_store->add_rule( '.a-nice-rule' )->add_declarations(
96
122
  array(
@@ -107,16 +133,19 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
107
133
  );
108
134
  $a_nice_renderer = new WP_Style_Engine_Processor();
109
135
  $a_nice_renderer->add_store( $a_nice_store );
110
- $this->assertEquals(
136
+ $this->assertSame(
111
137
  '.a-nice-rule{color:var(--nice-color);background-color:purple;}.a-nicer-rule{font-family:Nice sans;font-size:1em;background-color:purple;}',
112
- $a_nice_renderer->get_css()
138
+ $a_nice_renderer->get_css( array( 'prettify' => false ) )
113
139
  );
114
140
  }
115
141
 
116
142
  /**
117
- * Should merge CSS declarations.
143
+ * Tests that CSS declarations are merged and deduped in the final CSS rules output.
144
+ *
145
+ * @covers ::add_rules
146
+ * @covers ::get_css
118
147
  */
119
- public function test_dedupe_and_merge_css_declarations() {
148
+ public function test_should_dedupe_and_merge_css_declarations() {
120
149
  $an_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
121
150
  $an_excellent_processor = new WP_Style_Engine_Processor();
122
151
  $an_excellent_rule->add_declarations(
@@ -136,9 +165,10 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
136
165
  )
137
166
  );
138
167
  $an_excellent_processor->add_rules( $another_excellent_rule );
139
- $this->assertEquals(
168
+ $this->assertSame(
140
169
  '.an-excellent-rule{color:var(--excellent-color);border-style:dotted;border-color:brown;}',
141
- $an_excellent_processor->get_css()
170
+ $an_excellent_processor->get_css( array( 'prettify' => false ) ),
171
+ 'Return value of get_css() does not match expectations with new, deduped and merged declarations.'
142
172
  );
143
173
 
144
174
  $yet_another_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
@@ -150,16 +180,19 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
150
180
  )
151
181
  );
152
182
  $an_excellent_processor->add_rules( $yet_another_excellent_rule );
153
- $this->assertEquals(
183
+ $this->assertSame(
154
184
  '.an-excellent-rule{color:var(--excellent-color);border-style:dashed;border-color:brown;border-width:2px;}',
155
- $an_excellent_processor->get_css()
185
+ $an_excellent_processor->get_css( array( 'prettify' => false ) ),
186
+ 'Return value of get_css() does not match expectations with deduped and merged declarations.'
156
187
  );
157
188
  }
158
189
 
159
190
  /**
160
- * Should print out uncombined selectors duplicate CSS rules.
191
+ * Tests printing out 'unoptimized' CSS, that is, uncombined selectors and duplicate CSS rules.
192
+ *
193
+ * @covers ::get_css
161
194
  */
162
- public function test_output_verbose_css_rules() {
195
+ public function test_should_not_optimize_css_output() {
163
196
  $a_sweet_rule = new WP_Style_Engine_CSS_Rule(
164
197
  '.a-sweet-rule',
165
198
  array(
@@ -187,16 +220,23 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
187
220
  $a_sweet_processor = new WP_Style_Engine_Processor();
188
221
  $a_sweet_processor->add_rules( array( $a_sweet_rule, $a_sweeter_rule, $the_sweetest_rule ) );
189
222
 
190
- $this->assertEquals(
223
+ $this->assertSame(
191
224
  '.a-sweet-rule{color:var(--sweet-color);background-color:purple;}#an-even-sweeter-rule > marquee{color:var(--sweet-color);background-color:purple;}.the-sweetest-rule-of-all a{color:var(--sweet-color);background-color:purple;}',
192
- $a_sweet_processor->get_css( array( 'optimize' => false ) )
225
+ $a_sweet_processor->get_css(
226
+ array(
227
+ 'optimize' => false,
228
+ 'prettify' => false,
229
+ )
230
+ )
193
231
  );
194
232
  }
195
233
 
196
234
  /**
197
- * Should combine duplicate CSS rules.
235
+ * Tests that 'optimized' CSS is output, that is, that duplicate CSS rules are combined under their corresponding selectors.
236
+ *
237
+ * @covers ::get_css
198
238
  */
199
- public function test_combine_css_rules() {
239
+ public function test_should_optimize_css_output_by_default() {
200
240
  $a_sweet_rule = new WP_Style_Engine_CSS_Rule(
201
241
  '.a-sweet-rule',
202
242
  array(
@@ -216,15 +256,18 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
216
256
  $a_sweet_processor = new WP_Style_Engine_Processor();
217
257
  $a_sweet_processor->add_rules( array( $a_sweet_rule, $a_sweeter_rule ) );
218
258
 
219
- $this->assertEquals(
259
+ $this->assertSame(
220
260
  '.a-sweet-rule,#an-even-sweeter-rule > marquee{color:var(--sweet-color);background-color:purple;}',
221
- $a_sweet_processor->get_css()
261
+ $a_sweet_processor->get_css( array( 'prettify' => false ) )
222
262
  );
223
263
  }
224
- /**
225
- * Should combine and store CSS rules.
226
- */
227
- public function test_combine_previously_added_css_rules() {
264
+
265
+ /**
266
+ * Tests that incoming CSS rules are merged with existing CSS rules.
267
+ *
268
+ * @covers ::add_rules
269
+ */
270
+ public function test_should_combine_previously_added_css_rules() {
228
271
  $a_lovely_processor = new WP_Style_Engine_Processor();
229
272
  $a_lovely_rule = new WP_Style_Engine_CSS_Rule(
230
273
  '.a-lovely-rule',
@@ -240,7 +283,11 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
240
283
  )
241
284
  );
242
285
  $a_lovely_processor->add_rules( $a_lovelier_rule );
243
- $this->assertEquals( '.a-lovely-rule,.a-lovelier-rule{border-color:purple;}', $a_lovely_processor->get_css() );
286
+ $this->assertSame(
287
+ '.a-lovely-rule,.a-lovelier-rule{border-color:purple;}',
288
+ $a_lovely_processor->get_css( array( 'prettify' => false ) ),
289
+ 'Return value of get_css() does not match expectations when combining 2 CSS rules'
290
+ );
244
291
 
245
292
  $a_most_lovely_rule = new WP_Style_Engine_CSS_Rule(
246
293
  '.a-most-lovely-rule',
@@ -258,9 +305,10 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
258
305
  );
259
306
  $a_lovely_processor->add_rules( $a_perfectly_lovely_rule );
260
307
 
261
- $this->assertEquals(
308
+ $this->assertSame(
262
309
  '.a-lovely-rule,.a-lovelier-rule,.a-most-lovely-rule,.a-perfectly-lovely-rule{border-color:purple;}',
263
- $a_lovely_processor->get_css()
310
+ $a_lovely_processor->get_css( array( 'prettify' => false ) ),
311
+ 'Return value of get_css() does not match expectations when combining 4 CSS rules'
264
312
  );
265
313
  }
266
314
  }