@wordpress/style-engine 1.2.0 → 1.3.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 +8 -0
- package/build/styles/border/index.js +2 -2
- package/build/styles/border/index.js.map +1 -1
- package/build/styles/utils.js +2 -2
- package/build/styles/utils.js.map +1 -1
- package/build-module/styles/border/index.js +2 -2
- package/build-module/styles/border/index.js.map +1 -1
- package/build-module/styles/utils.js +2 -2
- package/build-module/styles/utils.js.map +1 -1
- package/build-types/styles/utils.d.ts +2 -2
- package/class-wp-style-engine-css-declarations.php +32 -0
- package/package.json +2 -2
- package/src/styles/border/index.ts +2 -2
- package/src/styles/utils.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/phpunit/class-wp-style-engine-css-declarations-test.php +0 -281
- package/phpunit/class-wp-style-engine-css-rule-test.php +0 -156
- package/phpunit/class-wp-style-engine-css-rules-store-test.php +0 -188
- package/phpunit/class-wp-style-engine-processor-test.php +0 -314
- package/phpunit/style-engine-test.php +0 -688
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
/**
|
|
3
|
-
* Tests the Style Engine CSS declarations class.
|
|
4
|
-
*
|
|
5
|
-
* @package Gutenberg
|
|
6
|
-
* @subpackage style-engine
|
|
7
|
-
*/
|
|
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_CSS_Declarations' ) ) {
|
|
14
|
-
require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Tests registering, storing and generating CSS declarations.
|
|
19
|
-
*
|
|
20
|
-
* @coversDefaultClass WP_Style_Engine_CSS_Declarations
|
|
21
|
-
*/
|
|
22
|
-
class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
|
|
23
|
-
/**
|
|
24
|
-
* Tests setting declarations on instantiation.
|
|
25
|
-
*
|
|
26
|
-
* @covers ::__construct
|
|
27
|
-
*/
|
|
28
|
-
public function test_should_instantiate_with_declarations() {
|
|
29
|
-
$input_declarations = array(
|
|
30
|
-
'margin-top' => '10px',
|
|
31
|
-
'font-size' => '2rem',
|
|
32
|
-
);
|
|
33
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
34
|
-
$this->assertSame( $input_declarations, $css_declarations->get_declarations() );
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Tests that declarations are added.
|
|
39
|
-
*
|
|
40
|
-
* @covers ::add_declarations
|
|
41
|
-
* @covers ::add_declaration
|
|
42
|
-
*/
|
|
43
|
-
public function test_should_add_declarations() {
|
|
44
|
-
$input_declarations = array(
|
|
45
|
-
'padding' => '20px',
|
|
46
|
-
'color' => 'var(--wp--preset--elbow-patches)',
|
|
47
|
-
);
|
|
48
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations();
|
|
49
|
-
$css_declarations->add_declarations( $input_declarations );
|
|
50
|
-
|
|
51
|
-
$this->assertSame( $input_declarations, $css_declarations->get_declarations() );
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Tests that new declarations are added to existing declarations.
|
|
56
|
-
*
|
|
57
|
-
* @covers ::add_declarations
|
|
58
|
-
* @covers ::add_declaration
|
|
59
|
-
*/
|
|
60
|
-
public function test_should_add_new_declarations_to_existing() {
|
|
61
|
-
$input_declarations = array(
|
|
62
|
-
'border-width' => '1%',
|
|
63
|
-
'background-color' => 'var(--wp--preset--english-mustard)',
|
|
64
|
-
);
|
|
65
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
66
|
-
$extra_declaration = array(
|
|
67
|
-
'letter-spacing' => '1.5px',
|
|
68
|
-
);
|
|
69
|
-
$css_declarations->add_declarations( $extra_declaration );
|
|
70
|
-
|
|
71
|
-
$this->assertSame( array_merge( $input_declarations, $extra_declaration ), $css_declarations->get_declarations() );
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Tests that properties are sanitized before storing.
|
|
76
|
-
*
|
|
77
|
-
* @covers ::filter_declaration
|
|
78
|
-
* @covers ::sanitize_property
|
|
79
|
-
*/
|
|
80
|
-
public function test_should_sanitize_properties() {
|
|
81
|
-
$input_declarations = array(
|
|
82
|
-
'^--wp--style--sleepy-potato$' => '40px',
|
|
83
|
-
'<background-//color>' => 'var(--wp--preset--english-mustard)',
|
|
84
|
-
);
|
|
85
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
86
|
-
|
|
87
|
-
$this->assertSame(
|
|
88
|
-
array(
|
|
89
|
-
'--wp--style--sleepy-potato' => '40px',
|
|
90
|
-
'background-color' => 'var(--wp--preset--english-mustard)',
|
|
91
|
-
),
|
|
92
|
-
$css_declarations->get_declarations()
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
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
|
|
101
|
-
*/
|
|
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',
|
|
109
|
-
);
|
|
110
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
111
|
-
$safe_style_css_mock_action = new MockAction();
|
|
112
|
-
|
|
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();
|
|
116
|
-
|
|
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.'
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
$this->assertSame(
|
|
124
|
-
'margin-right:10em;',
|
|
125
|
-
$css_declarations_string,
|
|
126
|
-
'Unallowed CSS properties or values with HTML tags were not removed.'
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Tests that calc, clamp, min, max, and minmax CSS functions are allowed.
|
|
133
|
-
*
|
|
134
|
-
* @covers ::get_declarations_string
|
|
135
|
-
* @covers ::filter_declaration
|
|
136
|
-
*/
|
|
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)',
|
|
148
|
-
);
|
|
149
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
150
|
-
$safecss_filter_attr_allow_css_mock_action = new MockAction();
|
|
151
|
-
|
|
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();
|
|
155
|
-
|
|
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.'
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
$this->assertSame(
|
|
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'
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
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.
|
|
179
|
-
*/
|
|
180
|
-
public function test_should_compile_css_declarations_to_css_declarations_string( $expected, $should_prettify = false, $indent_count = 0 ) {
|
|
181
|
-
$input_declarations = array(
|
|
182
|
-
'color' => 'red',
|
|
183
|
-
'border-top-left-radius' => '99px',
|
|
184
|
-
'text-decoration' => 'underline',
|
|
185
|
-
);
|
|
186
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
187
|
-
|
|
188
|
-
$this->assertSame(
|
|
189
|
-
$expected,
|
|
190
|
-
$css_declarations->get_declarations_string( $should_prettify, $indent_count )
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Data provider for test_should_compile_css_declarations_to_css_declarations_string().
|
|
196
|
-
*
|
|
197
|
-
* @return array
|
|
198
|
-
*/
|
|
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
|
-
),
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Tests removing a single declaration.
|
|
228
|
-
*
|
|
229
|
-
* @covers ::remove_declaration
|
|
230
|
-
*/
|
|
231
|
-
public function test_should_remove_single_declaration() {
|
|
232
|
-
$input_declarations = array(
|
|
233
|
-
'color' => 'tomato',
|
|
234
|
-
'margin' => '10em 10em 20em 1px',
|
|
235
|
-
'font-family' => 'Happy Font serif',
|
|
236
|
-
);
|
|
237
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
238
|
-
|
|
239
|
-
$this->assertSame(
|
|
240
|
-
'color:tomato;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
241
|
-
$css_declarations->get_declarations_string(),
|
|
242
|
-
'CSS declarations string does not match the values of `$declarations` passed to the constructor.'
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
$css_declarations->remove_declaration( 'color' );
|
|
246
|
-
|
|
247
|
-
$this->assertSame(
|
|
248
|
-
'margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
249
|
-
$css_declarations->get_declarations_string(),
|
|
250
|
-
'Output after removing "color" declaration via `remove_declaration()` does not match expectations'
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Tests that multiple declarations are removed.
|
|
256
|
-
*
|
|
257
|
-
* @covers ::remove_declarations
|
|
258
|
-
*/
|
|
259
|
-
public function test_should_remove_multiple_declarations() {
|
|
260
|
-
$input_declarations = array(
|
|
261
|
-
'color' => 'cucumber',
|
|
262
|
-
'margin' => '10em 10em 20em 1px',
|
|
263
|
-
'font-family' => 'Happy Font serif',
|
|
264
|
-
);
|
|
265
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
266
|
-
|
|
267
|
-
$this->assertSame(
|
|
268
|
-
'color:cucumber;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
269
|
-
$css_declarations->get_declarations_string(),
|
|
270
|
-
'CSS declarations string does not match the values of `$declarations` passed to the constructor.'
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
$css_declarations->remove_declarations( array( 'color', 'margin' ) );
|
|
274
|
-
|
|
275
|
-
$this->assertSame(
|
|
276
|
-
'font-family:Happy Font serif;',
|
|
277
|
-
$css_declarations->get_declarations_string(),
|
|
278
|
-
'Output after removing "color" and "margin" declarations via `remove_declarations()` does not match expectations'
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
/**
|
|
3
|
-
* Tests the Style Engine CSS Rule class.
|
|
4
|
-
*
|
|
5
|
-
* @package Gutenberg
|
|
6
|
-
* @subpackage style-engine
|
|
7
|
-
*/
|
|
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_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
|
-
/**
|
|
22
|
-
* Tests for registering, storing and generating CSS rules.
|
|
23
|
-
*
|
|
24
|
-
* @coversDefaultClass WP_Style_Engine_CSS_Rule
|
|
25
|
-
*/
|
|
26
|
-
class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
27
|
-
/**
|
|
28
|
-
* Tests that declarations are set on instantiation.
|
|
29
|
-
*
|
|
30
|
-
* @covers ::__construct
|
|
31
|
-
*/
|
|
32
|
-
public function test_should_instantiate_with_selector_and_rules() {
|
|
33
|
-
$selector = '.law-and-order';
|
|
34
|
-
$input_declarations = array(
|
|
35
|
-
'margin-top' => '10px',
|
|
36
|
-
'font-size' => '2rem',
|
|
37
|
-
);
|
|
38
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
39
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
40
|
-
|
|
41
|
-
$this->assertSame( $selector, $css_rule->get_selector(), 'Return value of get_selector() does not match value passed to constructor.' );
|
|
42
|
-
|
|
43
|
-
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
44
|
-
|
|
45
|
-
$this->assertSame( $expected, $css_rule->get_css(), 'Value returned by get_css() does not match expected declarations string.' );
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Tests that declaration properties are deduplicated.
|
|
50
|
-
*
|
|
51
|
-
* @covers ::add_declarations
|
|
52
|
-
* @covers ::get_css
|
|
53
|
-
*/
|
|
54
|
-
public function test_should_dedupe_properties_in_rules() {
|
|
55
|
-
$selector = '.taggart';
|
|
56
|
-
$first_declaration = array(
|
|
57
|
-
'font-size' => '2rem',
|
|
58
|
-
);
|
|
59
|
-
$overwrite_first_declaration = array(
|
|
60
|
-
'font-size' => '4px',
|
|
61
|
-
);
|
|
62
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $first_declaration );
|
|
63
|
-
$css_rule->add_declarations( new WP_Style_Engine_CSS_Declarations( $overwrite_first_declaration ) );
|
|
64
|
-
|
|
65
|
-
$expected = '.taggart{font-size:4px;}';
|
|
66
|
-
$this->assertSame( $expected, $css_rule->get_css() );
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Tests that declarations can be added to existing rules.
|
|
71
|
-
*
|
|
72
|
-
* @covers ::add_declarations
|
|
73
|
-
* @covers ::get_css
|
|
74
|
-
*/
|
|
75
|
-
public function test_should_add_declarations_to_existing_rules() {
|
|
76
|
-
// Declarations using a WP_Style_Engine_CSS_Declarations object.
|
|
77
|
-
$some_css_declarations = new WP_Style_Engine_CSS_Declarations( array( 'margin-top' => '10px' ) );
|
|
78
|
-
// Declarations using a property => value array.
|
|
79
|
-
$some_more_css_declarations = array( 'font-size' => '1rem' );
|
|
80
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( '.hill-street-blues', $some_css_declarations );
|
|
81
|
-
$css_rule->add_declarations( $some_more_css_declarations );
|
|
82
|
-
|
|
83
|
-
$expected = '.hill-street-blues{margin-top:10px;font-size:1rem;}';
|
|
84
|
-
|
|
85
|
-
$this->assertSame( $expected, $css_rule->get_css() );
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Tests setting a selector to a rule.
|
|
90
|
-
*
|
|
91
|
-
* @covers ::set_selector
|
|
92
|
-
*/
|
|
93
|
-
public function test_should_set_selector() {
|
|
94
|
-
$selector = '.taggart';
|
|
95
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $selector );
|
|
96
|
-
|
|
97
|
-
$this->assertSame( $selector, $css_rule->get_selector(), 'Return value of get_selector() does not match value passed to constructor.' );
|
|
98
|
-
|
|
99
|
-
$css_rule->set_selector( '.law-and-order' );
|
|
100
|
-
|
|
101
|
-
$this->assertSame( '.law-and-order', $css_rule->get_selector(), 'Return value of get_selector() does not match value passed to set_selector().' );
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Tests generating a CSS rule string.
|
|
106
|
-
*
|
|
107
|
-
* @covers ::get_css
|
|
108
|
-
*/
|
|
109
|
-
public function test_should_generate_css_rule_string() {
|
|
110
|
-
$selector = '.chips';
|
|
111
|
-
$input_declarations = array(
|
|
112
|
-
'margin-top' => '10px',
|
|
113
|
-
'font-size' => '2rem',
|
|
114
|
-
);
|
|
115
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
116
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
117
|
-
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
118
|
-
|
|
119
|
-
$this->assertSame( $expected, $css_rule->get_css() );
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Tests that an empty string will be returned where there are no declarations in a CSS rule.
|
|
124
|
-
*
|
|
125
|
-
* @covers ::get_css
|
|
126
|
-
*/
|
|
127
|
-
public function test_should_return_empty_string_with_no_declarations() {
|
|
128
|
-
$selector = '.holmes';
|
|
129
|
-
$input_declarations = array();
|
|
130
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
131
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
132
|
-
|
|
133
|
-
$this->assertSame( '', $css_rule->get_css() );
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Tests that CSS rules are prettified.
|
|
138
|
-
*
|
|
139
|
-
* @covers ::get_css
|
|
140
|
-
*/
|
|
141
|
-
public function test_should_prettify_css_rule_output() {
|
|
142
|
-
$selector = '.baptiste';
|
|
143
|
-
$input_declarations = array(
|
|
144
|
-
'margin-left' => '0',
|
|
145
|
-
'font-family' => 'Detective Sans',
|
|
146
|
-
);
|
|
147
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
148
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
149
|
-
$expected = '.baptiste {
|
|
150
|
-
margin-left: 0;
|
|
151
|
-
font-family: Detective Sans;
|
|
152
|
-
}';
|
|
153
|
-
|
|
154
|
-
$this->assertSame( $expected, $css_rule->get_css( true ) );
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
/**
|
|
3
|
-
* Tests the Style Engine CSS Rules Store class.
|
|
4
|
-
*
|
|
5
|
-
* @package Gutenberg
|
|
6
|
-
* @subpackage style-engine
|
|
7
|
-
*/
|
|
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_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
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Tests for registering, storing and retrieving a collection of CSS Rules (a store).
|
|
27
|
-
*
|
|
28
|
-
* @coversDefaultClass WP_Style_Engine_CSS_Rules_Store
|
|
29
|
-
*/
|
|
30
|
-
class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
31
|
-
/**
|
|
32
|
-
* Cleans up stores after each test.
|
|
33
|
-
*/
|
|
34
|
-
public function tear_down() {
|
|
35
|
-
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
36
|
-
parent::tear_down();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Tests creating a new store on instantiation.
|
|
41
|
-
*
|
|
42
|
-
* @covers ::__construct
|
|
43
|
-
*/
|
|
44
|
-
public function test_should_create_new_store_on_instantiation() {
|
|
45
|
-
$new_pancakes_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'pancakes-with-strawberries' );
|
|
46
|
-
|
|
47
|
-
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $new_pancakes_store );
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Tests that a `$store_name` argument is required and no store will be created without one.
|
|
52
|
-
*
|
|
53
|
-
* @covers ::get_store
|
|
54
|
-
*/
|
|
55
|
-
public function test_should_not_create_store_without_a_store_name() {
|
|
56
|
-
$not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( '' );
|
|
57
|
-
|
|
58
|
-
$this->assertEmpty( $not_a_store, 'get_store() did not return an empty value with empty string as argument.' );
|
|
59
|
-
|
|
60
|
-
$also_not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( 123 );
|
|
61
|
-
|
|
62
|
-
$this->assertEmpty( $also_not_a_store, 'get_store() did not return an empty value with number as argument.' );
|
|
63
|
-
|
|
64
|
-
$definitely_not_a_store = WP_Style_Engine_CSS_Rules_Store::get_store( null );
|
|
65
|
-
|
|
66
|
-
$this->assertEmpty( $definitely_not_a_store, 'get_store() did not return an empty value with `null` as argument.' );
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Tests returning a previously created store when the same selector key is passed.
|
|
71
|
-
*
|
|
72
|
-
* @covers ::get_store
|
|
73
|
-
*/
|
|
74
|
-
public function test_should_return_existing_store() {
|
|
75
|
-
$new_fish_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'fish-n-chips' );
|
|
76
|
-
$selector = '.haddock';
|
|
77
|
-
|
|
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' );
|
|
81
|
-
|
|
82
|
-
$the_same_fish_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'fish-n-chips' );
|
|
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' );
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Tests returning all previously created stores.
|
|
89
|
-
*
|
|
90
|
-
* @covers ::get_stores
|
|
91
|
-
*/
|
|
92
|
-
public function test_should_get_all_existing_stores() {
|
|
93
|
-
$burrito_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'burrito' );
|
|
94
|
-
$quesadilla_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'quesadilla' );
|
|
95
|
-
|
|
96
|
-
$this->assertEquals(
|
|
97
|
-
array(
|
|
98
|
-
'burrito' => $burrito_store,
|
|
99
|
-
'quesadilla' => $quesadilla_store,
|
|
100
|
-
),
|
|
101
|
-
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Tests that all previously created stores are deleted.
|
|
107
|
-
*
|
|
108
|
-
* @covers ::remove_all_stores
|
|
109
|
-
*/
|
|
110
|
-
public function test_should_remove_all_stores() {
|
|
111
|
-
$dolmades_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'dolmades' );
|
|
112
|
-
$tzatziki_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'tzatziki' );
|
|
113
|
-
|
|
114
|
-
$this->assertEquals(
|
|
115
|
-
array(
|
|
116
|
-
'dolmades' => $dolmades_store,
|
|
117
|
-
'tzatziki' => $tzatziki_store,
|
|
118
|
-
),
|
|
119
|
-
WP_Style_Engine_CSS_Rules_Store::get_stores(),
|
|
120
|
-
'Return value of get_stores() does not match expectation'
|
|
121
|
-
);
|
|
122
|
-
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
123
|
-
|
|
124
|
-
$this->assertEquals(
|
|
125
|
-
array(),
|
|
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.'
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Tests adding rules to an existing store.
|
|
133
|
-
*
|
|
134
|
-
* @covers ::add_rule
|
|
135
|
-
*/
|
|
136
|
-
public function test_should_add_rule_to_existing_store() {
|
|
137
|
-
$new_pie_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'meat-pie' );
|
|
138
|
-
$selector = '.wp-block-sauce a:hover';
|
|
139
|
-
$store_rule = $new_pie_store->add_rule( $selector );
|
|
140
|
-
$expected = '';
|
|
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.' );
|
|
143
|
-
|
|
144
|
-
$pie_declarations = array(
|
|
145
|
-
'color' => 'brown',
|
|
146
|
-
'border-color' => 'yellow',
|
|
147
|
-
'border-radius' => '10rem',
|
|
148
|
-
);
|
|
149
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $pie_declarations );
|
|
150
|
-
$store_rule->add_declarations( $css_declarations );
|
|
151
|
-
|
|
152
|
-
$store_rule = $new_pie_store->add_rule( $selector );
|
|
153
|
-
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
154
|
-
|
|
155
|
-
$this->assertSame( $expected, $store_rule->get_css(), 'Return value of get_css() does not match expected CSS from existing store rules.' );
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Tests that all stored rule objects are returned.
|
|
160
|
-
*
|
|
161
|
-
* @covers ::get_all_rules
|
|
162
|
-
*/
|
|
163
|
-
public function test_should_get_all_rule_objects_for_a_store() {
|
|
164
|
-
$new_pizza_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'pizza-with-mozzarella' );
|
|
165
|
-
$selector = '.wp-block-anchovies a:hover';
|
|
166
|
-
$store_rule = $new_pizza_store->add_rule( $selector );
|
|
167
|
-
$expected = array(
|
|
168
|
-
$selector => $store_rule,
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
$this->assertSame( $expected, $new_pizza_store->get_all_rules(), 'Return value for get_all_rules() does not match expectations.' );
|
|
172
|
-
|
|
173
|
-
$new_selector = '.wp-block-mushroom a:hover';
|
|
174
|
-
$newer_pizza_declarations = array(
|
|
175
|
-
'padding' => '100px',
|
|
176
|
-
);
|
|
177
|
-
$new_store_rule = $new_pizza_store->add_rule( $new_selector );
|
|
178
|
-
$css_declarations = new WP_Style_Engine_CSS_Declarations( $newer_pizza_declarations );
|
|
179
|
-
$new_store_rule->add_declarations( array( $css_declarations ) );
|
|
180
|
-
|
|
181
|
-
$expected = array(
|
|
182
|
-
$selector => $store_rule,
|
|
183
|
-
$new_selector => $new_store_rule,
|
|
184
|
-
);
|
|
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.' );
|
|
187
|
-
}
|
|
188
|
-
}
|