@wordpress/style-engine 0.13.0 → 0.15.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.
- package/CHANGELOG.md +4 -0
- package/README.md +206 -42
- package/build/index.js +7 -5
- package/build/index.js.map +1 -1
- package/build/styles/typography/index.js +7 -1
- package/build/styles/typography/index.js.map +1 -1
- package/build/styles/utils.js +5 -5
- package/build/styles/utils.js.map +1 -1
- package/build-module/index.js +6 -4
- package/build-module/index.js.map +1 -1
- package/build-module/styles/typography/index.js +7 -1
- package/build-module/styles/typography/index.js.map +1 -1
- package/build-module/styles/utils.js +5 -5
- package/build-module/styles/utils.js.map +1 -1
- package/build-types/index.d.ts +4 -4
- package/build-types/index.d.ts.map +1 -1
- package/build-types/styles/color/background.d.ts +1 -1
- package/build-types/styles/color/gradient.d.ts +1 -1
- package/build-types/styles/color/index.d.ts +1 -1
- package/build-types/styles/color/text.d.ts +1 -1
- package/build-types/styles/typography/index.d.ts +1 -1
- package/build-types/styles/typography/index.d.ts.map +1 -1
- package/build-types/styles/utils.d.ts +6 -6
- package/build-types/types.d.ts +3 -4
- package/build-types/types.d.ts.map +1 -1
- package/class-wp-style-engine-css-declarations.php +42 -15
- package/class-wp-style-engine-css-rule.php +20 -10
- package/class-wp-style-engine-css-rules-store.php +53 -3
- package/class-wp-style-engine-processor.php +76 -26
- package/class-wp-style-engine.php +260 -140
- package/package.json +2 -2
- package/phpunit/class-wp-style-engine-css-declarations-test.php +87 -7
- package/phpunit/class-wp-style-engine-css-rule-test.php +38 -7
- package/phpunit/class-wp-style-engine-css-rules-store-test.php +58 -2
- package/phpunit/class-wp-style-engine-processor-test.php +170 -31
- package/phpunit/class-wp-style-engine-test.php +223 -22
- package/src/index.ts +4 -4
- package/src/styles/typography/index.ts +13 -0
- package/src/styles/utils.ts +5 -5
- package/src/test/index.js +24 -10
- package/src/types.ts +3 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -84,24 +84,104 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
|
|
|
84
84
|
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
85
85
|
|
|
86
86
|
$this->assertSame(
|
|
87
|
-
'color:
|
|
87
|
+
'color:red;border-top-left-radius:99px;text-decoration:underline;',
|
|
88
88
|
$css_declarations->get_declarations_string()
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
|
|
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',
|
|
100
|
+
);
|
|
101
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
102
|
+
|
|
103
|
+
$this->assertSame(
|
|
104
|
+
'color: red; border-top-left-radius: 99px; text-decoration: underline;',
|
|
105
|
+
$css_declarations->get_declarations_string( true )
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Should compile css declarations into a prettified and indented css declarations block string.
|
|
111
|
+
*/
|
|
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',
|
|
117
|
+
);
|
|
118
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
119
|
+
|
|
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
|
+
}
|
|
127
|
+
|
|
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',
|
|
136
|
+
);
|
|
137
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
138
|
+
|
|
139
|
+
$this->assertSame(
|
|
140
|
+
' color: red;
|
|
141
|
+
border-top-left-radius: 99px;
|
|
142
|
+
text-decoration: underline;',
|
|
143
|
+
$css_declarations->get_declarations_string( true, 2 )
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
92
147
|
/**
|
|
93
148
|
* Should escape values and run the CSS through safecss_filter_attr.
|
|
94
149
|
*/
|
|
95
150
|
public function test_remove_unsafe_properties_and_values() {
|
|
96
151
|
$input_declarations = array(
|
|
97
|
-
'color' => '
|
|
152
|
+
'color' => 'url("https://wordpress.org")',
|
|
153
|
+
'font-size' => '<red/>',
|
|
98
154
|
'margin-right' => '10em',
|
|
155
|
+
'padding' => '</style>',
|
|
99
156
|
'potato' => 'uppercase',
|
|
100
157
|
);
|
|
101
158
|
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
102
159
|
|
|
103
160
|
$this->assertSame(
|
|
104
|
-
'
|
|
161
|
+
'margin-right:10em;',
|
|
162
|
+
$css_declarations->get_declarations_string()
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Should allow calc, clamp, min, max, and minmax CSS functions.
|
|
168
|
+
*/
|
|
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");',
|
|
105
185
|
$css_declarations->get_declarations_string()
|
|
106
186
|
);
|
|
107
187
|
}
|
|
@@ -118,13 +198,13 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
|
|
|
118
198
|
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
119
199
|
|
|
120
200
|
$this->assertSame(
|
|
121
|
-
'color:
|
|
201
|
+
'color:tomato;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
122
202
|
$css_declarations->get_declarations_string()
|
|
123
203
|
);
|
|
124
204
|
|
|
125
205
|
$css_declarations->remove_declaration( 'color' );
|
|
126
206
|
$this->assertSame(
|
|
127
|
-
'margin:
|
|
207
|
+
'margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
128
208
|
$css_declarations->get_declarations_string()
|
|
129
209
|
);
|
|
130
210
|
}
|
|
@@ -141,13 +221,13 @@ class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
|
|
|
141
221
|
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
142
222
|
|
|
143
223
|
$this->assertSame(
|
|
144
|
-
'color:
|
|
224
|
+
'color:cucumber;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
145
225
|
$css_declarations->get_declarations_string()
|
|
146
226
|
);
|
|
147
227
|
|
|
148
228
|
$css_declarations->remove_declarations( array( 'color', 'margin' ) );
|
|
149
229
|
$this->assertSame(
|
|
150
|
-
'font-family:
|
|
230
|
+
'font-family:Happy Font serif;',
|
|
151
231
|
$css_declarations->get_declarations_string()
|
|
152
232
|
);
|
|
153
233
|
}
|
|
@@ -27,7 +27,7 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
|
27
27
|
|
|
28
28
|
$this->assertSame( $selector, $css_rule->get_selector() );
|
|
29
29
|
|
|
30
|
-
$expected = "$selector
|
|
30
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
31
31
|
$this->assertSame( $expected, $css_rule->get_css() );
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -45,12 +45,12 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
|
45
45
|
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $first_declaration );
|
|
46
46
|
$css_rule->add_declarations( new WP_Style_Engine_CSS_Declarations( $overwrite_first_declaration ) );
|
|
47
47
|
|
|
48
|
-
$expected = '.taggart
|
|
48
|
+
$expected = '.taggart{font-size:4px;}';
|
|
49
49
|
$this->assertSame( $expected, $css_rule->get_css() );
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Should
|
|
53
|
+
* Should add declarations.
|
|
54
54
|
*/
|
|
55
55
|
public function test_add_declarations() {
|
|
56
56
|
// Declarations using a WP_Style_Engine_CSS_Declarations object.
|
|
@@ -60,12 +60,12 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
|
60
60
|
$css_rule = new WP_Style_Engine_CSS_Rule( '.hill-street-blues', $some_css_declarations );
|
|
61
61
|
$css_rule->add_declarations( $some_more_css_declarations );
|
|
62
62
|
|
|
63
|
-
$expected = '.hill-street-blues
|
|
63
|
+
$expected = '.hill-street-blues{margin-top:10px;font-size:1rem;}';
|
|
64
64
|
$this->assertSame( $expected, $css_rule->get_css() );
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Should set selector
|
|
68
|
+
* Should set selector.
|
|
69
69
|
*/
|
|
70
70
|
public function test_set_selector() {
|
|
71
71
|
$selector = '.taggart';
|
|
@@ -79,7 +79,7 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* Should
|
|
82
|
+
* Should generate CSS rules.
|
|
83
83
|
*/
|
|
84
84
|
public function test_get_css() {
|
|
85
85
|
$selector = '.chips';
|
|
@@ -89,8 +89,39 @@ class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
|
89
89
|
);
|
|
90
90
|
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
91
91
|
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
92
|
-
$expected = "$selector
|
|
92
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
93
93
|
|
|
94
94
|
$this->assertSame( $expected, $css_rule->get_css() );
|
|
95
95
|
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Should return empty string with no declarations.
|
|
99
|
+
*/
|
|
100
|
+
public function test_get_css_no_declarations() {
|
|
101
|
+
$selector = '.holmes';
|
|
102
|
+
$input_declarations = array();
|
|
103
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
104
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
105
|
+
|
|
106
|
+
$this->assertSame( '', $css_rule->get_css() );
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Should generate prettified CSS rules.
|
|
111
|
+
*/
|
|
112
|
+
public function test_get_prettified_css() {
|
|
113
|
+
$selector = '.baptiste';
|
|
114
|
+
$input_declarations = array(
|
|
115
|
+
'margin-left' => '0',
|
|
116
|
+
'font-family' => 'Detective Sans',
|
|
117
|
+
);
|
|
118
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
119
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
120
|
+
$expected = '.baptiste {
|
|
121
|
+
margin-left: 0;
|
|
122
|
+
font-family: Detective Sans;
|
|
123
|
+
}';
|
|
124
|
+
|
|
125
|
+
$this->assertSame( $expected, $css_rule->get_css( true ) );
|
|
126
|
+
}
|
|
96
127
|
}
|
|
@@ -14,6 +14,13 @@ require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
|
14
14
|
* Tests for registering, storing and retrieving CSS Rules.
|
|
15
15
|
*/
|
|
16
16
|
class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
17
|
+
/**
|
|
18
|
+
* Tear down after each test.
|
|
19
|
+
*/
|
|
20
|
+
public function tear_down() {
|
|
21
|
+
parent::tear_down();
|
|
22
|
+
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
23
|
+
}
|
|
17
24
|
/**
|
|
18
25
|
* Should create a new store.
|
|
19
26
|
*/
|
|
@@ -22,6 +29,20 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
22
29
|
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $new_pancakes_store );
|
|
23
30
|
}
|
|
24
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Should not create a new store with invalid $store_name.
|
|
34
|
+
*/
|
|
35
|
+
public function test_store_name_required() {
|
|
36
|
+
$not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( '' );
|
|
37
|
+
$this->assertEmpty( $not_a_store );
|
|
38
|
+
|
|
39
|
+
$also_not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( 123 );
|
|
40
|
+
$this->assertEmpty( $also_not_a_store );
|
|
41
|
+
|
|
42
|
+
$definitely_not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( null );
|
|
43
|
+
$this->assertEmpty( $definitely_not_a_store );
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
/**
|
|
26
47
|
* Should return previously created store when the same selector key is passed.
|
|
27
48
|
*/
|
|
@@ -36,6 +57,41 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
36
57
|
$this->assertEquals( $selector, $the_same_fish_store->add_rule( $selector )->get_selector() );
|
|
37
58
|
}
|
|
38
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Should return all previously created stores.
|
|
62
|
+
*/
|
|
63
|
+
public function test_get_stores() {
|
|
64
|
+
$burrito_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'burrito' );
|
|
65
|
+
$quesadilla_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'quesadilla' );
|
|
66
|
+
$this->assertEquals(
|
|
67
|
+
array(
|
|
68
|
+
'burrito' => $burrito_store,
|
|
69
|
+
'quesadilla' => $quesadilla_store,
|
|
70
|
+
),
|
|
71
|
+
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Should delete all previously created stores.
|
|
77
|
+
*/
|
|
78
|
+
public function test_remove_all_stores() {
|
|
79
|
+
$dolmades_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'dolmades' );
|
|
80
|
+
$tzatziki_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'tzatziki' );
|
|
81
|
+
$this->assertEquals(
|
|
82
|
+
array(
|
|
83
|
+
'dolmades' => $dolmades_store,
|
|
84
|
+
'tzatziki' => $tzatziki_store,
|
|
85
|
+
),
|
|
86
|
+
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
87
|
+
);
|
|
88
|
+
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
89
|
+
$this->assertEquals(
|
|
90
|
+
array(),
|
|
91
|
+
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
39
95
|
/**
|
|
40
96
|
* Should return a stored rule.
|
|
41
97
|
*/
|
|
@@ -43,7 +99,7 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
43
99
|
$new_pie_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'meat-pie' );
|
|
44
100
|
$selector = '.wp-block-sauce a:hover';
|
|
45
101
|
$store_rule = $new_pie_store->add_rule( $selector );
|
|
46
|
-
$expected =
|
|
102
|
+
$expected = '';
|
|
47
103
|
$this->assertEquals( $expected, $store_rule->get_css() );
|
|
48
104
|
|
|
49
105
|
$pie_declarations = array(
|
|
@@ -55,7 +111,7 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
55
111
|
$store_rule->add_declarations( $css_declarations );
|
|
56
112
|
|
|
57
113
|
$store_rule = $new_pie_store->add_rule( $selector );
|
|
58
|
-
$expected = "$selector
|
|
114
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
59
115
|
$this->assertEquals( $expected, $store_rule->get_css() );
|
|
60
116
|
}
|
|
61
117
|
|
|
@@ -14,12 +14,84 @@ require __DIR__ . '/../class-wp-style-engine-processor.php';
|
|
|
14
14
|
* Tests for compiling and rendering styles from a store of CSS rules.
|
|
15
15
|
*/
|
|
16
16
|
class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
|
|
17
|
+
/**
|
|
18
|
+
* Should compile CSS rules.
|
|
19
|
+
*/
|
|
20
|
+
public function test_return_rules_as_css() {
|
|
21
|
+
$a_nice_css_rule = new WP_Style_Engine_CSS_Rule( '.a-nice-rule' );
|
|
22
|
+
$a_nice_css_rule->add_declarations(
|
|
23
|
+
array(
|
|
24
|
+
'color' => 'var(--nice-color)',
|
|
25
|
+
'background-color' => 'purple',
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
$a_nicer_css_rule = new WP_Style_Engine_CSS_Rule( '.a-nicer-rule' );
|
|
29
|
+
$a_nicer_css_rule->add_declarations(
|
|
30
|
+
array(
|
|
31
|
+
'font-family' => 'Nice sans',
|
|
32
|
+
'font-size' => '1em',
|
|
33
|
+
'background-color' => 'purple',
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
$a_nice_processor = new WP_Style_Engine_Processor();
|
|
37
|
+
$a_nice_processor->add_rules( array( $a_nice_css_rule, $a_nicer_css_rule ) );
|
|
38
|
+
$this->assertEquals(
|
|
39
|
+
'.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()
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Should compile CSS rules.
|
|
46
|
+
*/
|
|
47
|
+
public function test_return_prettified_rules_as_css() {
|
|
48
|
+
$a_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-wonderful-rule' );
|
|
49
|
+
$a_wonderful_css_rule->add_declarations(
|
|
50
|
+
array(
|
|
51
|
+
'color' => 'var(--wonderful-color)',
|
|
52
|
+
'background-color' => 'orange',
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
$a_very_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-very_wonderful-rule' );
|
|
56
|
+
$a_very_wonderful_css_rule->add_declarations(
|
|
57
|
+
array(
|
|
58
|
+
'color' => 'var(--wonderful-color)',
|
|
59
|
+
'background-color' => 'orange',
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
$a_more_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-more-wonderful-rule' );
|
|
63
|
+
$a_more_wonderful_css_rule->add_declarations(
|
|
64
|
+
array(
|
|
65
|
+
'font-family' => 'Wonderful sans',
|
|
66
|
+
'font-size' => '1em',
|
|
67
|
+
'background-color' => 'orange',
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
$a_wonderful_processor = new WP_Style_Engine_Processor();
|
|
71
|
+
$a_wonderful_processor->add_rules( array( $a_wonderful_css_rule, $a_very_wonderful_css_rule, $a_more_wonderful_css_rule ) );
|
|
72
|
+
|
|
73
|
+
$expected = '.a-more-wonderful-rule {
|
|
74
|
+
font-family: Wonderful sans;
|
|
75
|
+
font-size: 1em;
|
|
76
|
+
background-color: orange;
|
|
77
|
+
}
|
|
78
|
+
.a-wonderful-rule,
|
|
79
|
+
.a-very_wonderful-rule {
|
|
80
|
+
color: var(--wonderful-color);
|
|
81
|
+
background-color: orange;
|
|
82
|
+
}
|
|
83
|
+
';
|
|
84
|
+
$this->assertEquals(
|
|
85
|
+
$expected,
|
|
86
|
+
$a_wonderful_processor->get_css( array( 'prettify' => true ) )
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
17
90
|
/**
|
|
18
91
|
* Should compile CSS rules from the store.
|
|
19
92
|
*/
|
|
20
93
|
public function test_return_store_rules_as_css() {
|
|
21
|
-
$a_nice_store
|
|
22
|
-
$a_nice_renderer = new WP_Style_Engine_Processor_Gutenberg( $a_nice_store );
|
|
94
|
+
$a_nice_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'nice' );
|
|
23
95
|
$a_nice_store->add_rule( '.a-nice-rule' )->add_declarations(
|
|
24
96
|
array(
|
|
25
97
|
'color' => 'var(--nice-color)',
|
|
@@ -33,95 +105,162 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
|
|
|
33
105
|
'background-color' => 'purple',
|
|
34
106
|
)
|
|
35
107
|
);
|
|
36
|
-
|
|
37
|
-
$
|
|
108
|
+
$a_nice_renderer = new WP_Style_Engine_Processor();
|
|
109
|
+
$a_nice_renderer->add_store( $a_nice_store );
|
|
110
|
+
$this->assertEquals(
|
|
111
|
+
'.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()
|
|
113
|
+
);
|
|
38
114
|
}
|
|
39
115
|
|
|
40
116
|
/**
|
|
41
117
|
* Should merge CSS declarations.
|
|
42
118
|
*/
|
|
43
119
|
public function test_dedupe_and_merge_css_declarations() {
|
|
44
|
-
$
|
|
45
|
-
$
|
|
46
|
-
$
|
|
120
|
+
$an_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
121
|
+
$an_excellent_processor = new WP_Style_Engine_Processor();
|
|
122
|
+
$an_excellent_rule->add_declarations(
|
|
47
123
|
array(
|
|
48
124
|
'color' => 'var(--excellent-color)',
|
|
49
125
|
'border-style' => 'dotted',
|
|
50
126
|
)
|
|
51
127
|
);
|
|
52
|
-
$
|
|
128
|
+
$an_excellent_processor->add_rules( $an_excellent_rule );
|
|
129
|
+
|
|
130
|
+
$another_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
131
|
+
$another_excellent_rule->add_declarations(
|
|
53
132
|
array(
|
|
54
133
|
'color' => 'var(--excellent-color)',
|
|
55
134
|
'border-style' => 'dotted',
|
|
56
135
|
'border-color' => 'brown',
|
|
57
136
|
)
|
|
58
137
|
);
|
|
138
|
+
$an_excellent_processor->add_rules( $another_excellent_rule );
|
|
139
|
+
$this->assertEquals(
|
|
140
|
+
'.an-excellent-rule{color:var(--excellent-color);border-style:dotted;border-color:brown;}',
|
|
141
|
+
$an_excellent_processor->get_css()
|
|
142
|
+
);
|
|
59
143
|
|
|
60
|
-
$
|
|
61
|
-
|
|
62
|
-
$an_excellent_store->add_rule( '.an-excellent-rule' )->add_declarations(
|
|
144
|
+
$yet_another_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
145
|
+
$yet_another_excellent_rule->add_declarations(
|
|
63
146
|
array(
|
|
64
147
|
'color' => 'var(--excellent-color)',
|
|
65
148
|
'border-style' => 'dashed',
|
|
66
149
|
'border-width' => '2px',
|
|
67
150
|
)
|
|
68
151
|
);
|
|
69
|
-
|
|
70
|
-
$this->assertEquals(
|
|
152
|
+
$an_excellent_processor->add_rules( $yet_another_excellent_rule );
|
|
153
|
+
$this->assertEquals(
|
|
154
|
+
'.an-excellent-rule{color:var(--excellent-color);border-style:dashed;border-color:brown;border-width:2px;}',
|
|
155
|
+
$an_excellent_processor->get_css()
|
|
156
|
+
);
|
|
71
157
|
}
|
|
72
158
|
|
|
73
159
|
/**
|
|
74
|
-
* Should
|
|
160
|
+
* Should print out uncombined selectors duplicate CSS rules.
|
|
75
161
|
*/
|
|
76
|
-
public function
|
|
77
|
-
$
|
|
78
|
-
|
|
79
|
-
|
|
162
|
+
public function test_output_verbose_css_rules() {
|
|
163
|
+
$a_sweet_rule = new WP_Style_Engine_CSS_Rule(
|
|
164
|
+
'.a-sweet-rule',
|
|
165
|
+
array(
|
|
166
|
+
'color' => 'var(--sweet-color)',
|
|
167
|
+
'background-color' => 'purple',
|
|
168
|
+
)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
$a_sweeter_rule = new WP_Style_Engine_CSS_Rule(
|
|
172
|
+
'#an-even-sweeter-rule > marquee',
|
|
80
173
|
array(
|
|
81
174
|
'color' => 'var(--sweet-color)',
|
|
82
175
|
'background-color' => 'purple',
|
|
83
176
|
)
|
|
84
177
|
);
|
|
85
|
-
|
|
178
|
+
|
|
179
|
+
$the_sweetest_rule = new WP_Style_Engine_CSS_Rule(
|
|
180
|
+
'.the-sweetest-rule-of-all a',
|
|
86
181
|
array(
|
|
87
182
|
'color' => 'var(--sweet-color)',
|
|
88
183
|
'background-color' => 'purple',
|
|
89
184
|
)
|
|
90
185
|
);
|
|
91
186
|
|
|
92
|
-
$
|
|
187
|
+
$a_sweet_processor = new WP_Style_Engine_Processor();
|
|
188
|
+
$a_sweet_processor->add_rules( array( $a_sweet_rule, $a_sweeter_rule, $the_sweetest_rule ) );
|
|
189
|
+
|
|
190
|
+
$this->assertEquals(
|
|
191
|
+
'.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 ) )
|
|
193
|
+
);
|
|
93
194
|
}
|
|
94
195
|
|
|
95
196
|
/**
|
|
96
|
-
* Should combine
|
|
197
|
+
* Should combine duplicate CSS rules.
|
|
97
198
|
*/
|
|
98
|
-
public function
|
|
99
|
-
$
|
|
100
|
-
|
|
101
|
-
|
|
199
|
+
public function test_combine_css_rules() {
|
|
200
|
+
$a_sweet_rule = new WP_Style_Engine_CSS_Rule(
|
|
201
|
+
'.a-sweet-rule',
|
|
202
|
+
array(
|
|
203
|
+
'color' => 'var(--sweet-color)',
|
|
204
|
+
'background-color' => 'purple',
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
$a_sweeter_rule = new WP_Style_Engine_CSS_Rule(
|
|
209
|
+
'#an-even-sweeter-rule > marquee',
|
|
210
|
+
array(
|
|
211
|
+
'color' => 'var(--sweet-color)',
|
|
212
|
+
'background-color' => 'purple',
|
|
213
|
+
)
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
$a_sweet_processor = new WP_Style_Engine_Processor();
|
|
217
|
+
$a_sweet_processor->add_rules( array( $a_sweet_rule, $a_sweeter_rule ) );
|
|
218
|
+
|
|
219
|
+
$this->assertEquals(
|
|
220
|
+
'.a-sweet-rule,#an-even-sweeter-rule > marquee{color:var(--sweet-color);background-color:purple;}',
|
|
221
|
+
$a_sweet_processor->get_css()
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Should combine and store CSS rules.
|
|
226
|
+
*/
|
|
227
|
+
public function test_combine_previously_added_css_rules() {
|
|
228
|
+
$a_lovely_processor = new WP_Style_Engine_Processor();
|
|
229
|
+
$a_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
230
|
+
'.a-lovely-rule',
|
|
102
231
|
array(
|
|
103
232
|
'border-color' => 'purple',
|
|
104
233
|
)
|
|
105
234
|
);
|
|
106
|
-
$
|
|
235
|
+
$a_lovely_processor->add_rules( $a_lovely_rule );
|
|
236
|
+
$a_lovelier_rule = new WP_Style_Engine_CSS_Rule(
|
|
237
|
+
'.a-lovelier-rule',
|
|
107
238
|
array(
|
|
108
239
|
'border-color' => 'purple',
|
|
109
240
|
)
|
|
110
241
|
);
|
|
242
|
+
$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() );
|
|
111
244
|
|
|
112
|
-
$
|
|
113
|
-
|
|
114
|
-
$a_lovely_store->add_rule( '.a-most-lovely-rule' )->add_declarations(
|
|
245
|
+
$a_most_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
246
|
+
'.a-most-lovely-rule',
|
|
115
247
|
array(
|
|
116
248
|
'border-color' => 'purple',
|
|
117
249
|
)
|
|
118
250
|
);
|
|
119
|
-
$
|
|
251
|
+
$a_lovely_processor->add_rules( $a_most_lovely_rule );
|
|
252
|
+
|
|
253
|
+
$a_perfectly_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
254
|
+
'.a-perfectly-lovely-rule',
|
|
120
255
|
array(
|
|
121
256
|
'border-color' => 'purple',
|
|
122
257
|
)
|
|
123
258
|
);
|
|
259
|
+
$a_lovely_processor->add_rules( $a_perfectly_lovely_rule );
|
|
124
260
|
|
|
125
|
-
$this->assertEquals(
|
|
261
|
+
$this->assertEquals(
|
|
262
|
+
'.a-lovely-rule,.a-lovelier-rule,.a-most-lovely-rule,.a-perfectly-lovely-rule{border-color:purple;}',
|
|
263
|
+
$a_lovely_processor->get_css()
|
|
264
|
+
);
|
|
126
265
|
}
|
|
127
266
|
}
|