@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,688 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
/**
|
|
3
|
-
* Tests the Style Engine global functions that interact with the WP_Style_Engine 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_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
|
-
}
|
|
28
|
-
|
|
29
|
-
if ( ! class_exists( 'WP_Style_Engine' ) ) {
|
|
30
|
-
require __DIR__ . '/../class-wp-style-engine.php';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if ( ! function_exists( 'wp_style_engine_get_styles' ) ) {
|
|
34
|
-
require __DIR__ . '/../style-engine.php';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Tests for registering, storing and generating styles.
|
|
39
|
-
*/
|
|
40
|
-
class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
41
|
-
/**
|
|
42
|
-
* Cleans up stores after each test.
|
|
43
|
-
*/
|
|
44
|
-
public function tear_down() {
|
|
45
|
-
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
46
|
-
parent::tear_down();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Tests generating block styles and classnames based on various manifestations of the $block_styles argument.
|
|
51
|
-
*
|
|
52
|
-
* @covers ::wp_style_engine_get_styles
|
|
53
|
-
* @covers WP_Style_Engine::parse_block_styles
|
|
54
|
-
* @covers WP_Style_Engine::compile_css
|
|
55
|
-
*
|
|
56
|
-
* @dataProvider data_wp_style_engine_get_styles
|
|
57
|
-
*
|
|
58
|
-
* @param array $block_styles The incoming block styles object.
|
|
59
|
-
* @param array $options {
|
|
60
|
-
* An array of options to pass to `wp_style_engine_get_styles()`.
|
|
61
|
-
*
|
|
62
|
-
* @type string|null $context An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is `null`.
|
|
63
|
-
* When set, the Style Engine will attempt to store the CSS rules, where a selector is also passed.
|
|
64
|
-
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
65
|
-
* @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
|
|
66
|
-
* otherwise, the value will be a concatenated string of CSS declarations.
|
|
67
|
-
* }
|
|
68
|
-
* @param string $expected_output The expected output.
|
|
69
|
-
*/
|
|
70
|
-
public function test_wp_style_engine_get_styles( $block_styles, $options, $expected_output ) {
|
|
71
|
-
$generated_styles = wp_style_engine_get_styles( $block_styles, $options );
|
|
72
|
-
|
|
73
|
-
$this->assertSame( $expected_output, $generated_styles );
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Data provider for test_wp_style_engine_get_styles().
|
|
78
|
-
*
|
|
79
|
-
* @return array
|
|
80
|
-
*/
|
|
81
|
-
public function data_wp_style_engine_get_styles() {
|
|
82
|
-
return array(
|
|
83
|
-
'default_return_value' => array(
|
|
84
|
-
'block_styles' => array(),
|
|
85
|
-
'options' => null,
|
|
86
|
-
'expected_output' => array(),
|
|
87
|
-
),
|
|
88
|
-
|
|
89
|
-
'inline_invalid_block_styles_empty' => array(
|
|
90
|
-
'block_styles' => 'hello world!',
|
|
91
|
-
'options' => null,
|
|
92
|
-
'expected_output' => array(),
|
|
93
|
-
),
|
|
94
|
-
|
|
95
|
-
'inline_invalid_block_styles_unknown_style' => array(
|
|
96
|
-
'block_styles' => array(
|
|
97
|
-
'pageBreakAfter' => 'verso',
|
|
98
|
-
),
|
|
99
|
-
'options' => null,
|
|
100
|
-
'expected_output' => array(),
|
|
101
|
-
),
|
|
102
|
-
|
|
103
|
-
'inline_invalid_block_styles_unknown_definition' => array(
|
|
104
|
-
'block_styles' => array(
|
|
105
|
-
'pageBreakAfter' => 'verso',
|
|
106
|
-
),
|
|
107
|
-
'options' => null,
|
|
108
|
-
'expected_output' => array(),
|
|
109
|
-
),
|
|
110
|
-
|
|
111
|
-
'inline_invalid_block_styles_unknown_property' => array(
|
|
112
|
-
'block_styles' => array(
|
|
113
|
-
'spacing' => array(
|
|
114
|
-
'gap' => '1000vw',
|
|
115
|
-
),
|
|
116
|
-
),
|
|
117
|
-
'options' => null,
|
|
118
|
-
'expected_output' => array(),
|
|
119
|
-
),
|
|
120
|
-
|
|
121
|
-
'valid_inline_css_and_classnames_as_default_context' => array(
|
|
122
|
-
'block_styles' => array(
|
|
123
|
-
'color' => array(
|
|
124
|
-
'text' => 'var:preset|color|texas-flood',
|
|
125
|
-
),
|
|
126
|
-
'spacing' => array(
|
|
127
|
-
'margin' => '111px',
|
|
128
|
-
'padding' => '0',
|
|
129
|
-
),
|
|
130
|
-
'border' => array(
|
|
131
|
-
'color' => 'var:preset|color|cool-caramel',
|
|
132
|
-
'width' => '2rem',
|
|
133
|
-
'style' => 'dotted',
|
|
134
|
-
),
|
|
135
|
-
),
|
|
136
|
-
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
137
|
-
'expected_output' => array(
|
|
138
|
-
'css' => 'border-style:dotted;border-width:2rem;padding:0;margin:111px;',
|
|
139
|
-
'declarations' => array(
|
|
140
|
-
'border-style' => 'dotted',
|
|
141
|
-
'border-width' => '2rem',
|
|
142
|
-
'padding' => '0',
|
|
143
|
-
'margin' => '111px',
|
|
144
|
-
),
|
|
145
|
-
'classnames' => 'has-text-color has-texas-flood-color has-border-color has-cool-caramel-border-color',
|
|
146
|
-
),
|
|
147
|
-
),
|
|
148
|
-
|
|
149
|
-
'inline_valid_box_model_style' => array(
|
|
150
|
-
'block_styles' => array(
|
|
151
|
-
'spacing' => array(
|
|
152
|
-
'padding' => array(
|
|
153
|
-
'top' => '42px',
|
|
154
|
-
'left' => '2%',
|
|
155
|
-
'bottom' => '44px',
|
|
156
|
-
'right' => '5rem',
|
|
157
|
-
),
|
|
158
|
-
'margin' => array(
|
|
159
|
-
'top' => '12rem',
|
|
160
|
-
'left' => '2vh',
|
|
161
|
-
'bottom' => '2px',
|
|
162
|
-
'right' => '10em',
|
|
163
|
-
),
|
|
164
|
-
),
|
|
165
|
-
'border' => array(
|
|
166
|
-
'radius' => array(
|
|
167
|
-
'topLeft' => '99px',
|
|
168
|
-
'topRight' => '98px',
|
|
169
|
-
'bottomLeft' => '97px',
|
|
170
|
-
'bottomRight' => '96px',
|
|
171
|
-
),
|
|
172
|
-
),
|
|
173
|
-
),
|
|
174
|
-
'options' => null,
|
|
175
|
-
'expected_output' => array(
|
|
176
|
-
'css' => 'border-top-left-radius:99px;border-top-right-radius:98px;border-bottom-left-radius:97px;border-bottom-right-radius:96px;padding-top:42px;padding-left:2%;padding-bottom:44px;padding-right:5rem;margin-top:12rem;margin-left:2vh;margin-bottom:2px;margin-right:10em;',
|
|
177
|
-
'declarations' => array(
|
|
178
|
-
'border-top-left-radius' => '99px',
|
|
179
|
-
'border-top-right-radius' => '98px',
|
|
180
|
-
'border-bottom-left-radius' => '97px',
|
|
181
|
-
'border-bottom-right-radius' => '96px',
|
|
182
|
-
'padding-top' => '42px',
|
|
183
|
-
'padding-left' => '2%',
|
|
184
|
-
'padding-bottom' => '44px',
|
|
185
|
-
'padding-right' => '5rem',
|
|
186
|
-
'margin-top' => '12rem',
|
|
187
|
-
'margin-left' => '2vh',
|
|
188
|
-
'margin-bottom' => '2px',
|
|
189
|
-
'margin-right' => '10em',
|
|
190
|
-
),
|
|
191
|
-
),
|
|
192
|
-
),
|
|
193
|
-
|
|
194
|
-
'inline_valid_typography_style' => array(
|
|
195
|
-
'block_styles' => array(
|
|
196
|
-
'typography' => array(
|
|
197
|
-
'fontSize' => 'clamp(2em, 2vw, 4em)',
|
|
198
|
-
'fontFamily' => 'Roboto,Oxygen-Sans,Ubuntu,sans-serif',
|
|
199
|
-
'fontStyle' => 'italic',
|
|
200
|
-
'fontWeight' => '800',
|
|
201
|
-
'lineHeight' => '1.3',
|
|
202
|
-
'textDecoration' => 'underline',
|
|
203
|
-
'textTransform' => 'uppercase',
|
|
204
|
-
'letterSpacing' => '2',
|
|
205
|
-
),
|
|
206
|
-
),
|
|
207
|
-
'options' => null,
|
|
208
|
-
'expected_output' => array(
|
|
209
|
-
'css' => 'font-size:clamp(2em, 2vw, 4em);font-family:Roboto,Oxygen-Sans,Ubuntu,sans-serif;font-style:italic;font-weight:800;line-height:1.3;text-decoration:underline;text-transform:uppercase;letter-spacing:2;',
|
|
210
|
-
'declarations' => array(
|
|
211
|
-
'font-size' => 'clamp(2em, 2vw, 4em)',
|
|
212
|
-
'font-family' => 'Roboto,Oxygen-Sans,Ubuntu,sans-serif',
|
|
213
|
-
'font-style' => 'italic',
|
|
214
|
-
'font-weight' => '800',
|
|
215
|
-
'line-height' => '1.3',
|
|
216
|
-
'text-decoration' => 'underline',
|
|
217
|
-
'text-transform' => 'uppercase',
|
|
218
|
-
'letter-spacing' => '2',
|
|
219
|
-
),
|
|
220
|
-
),
|
|
221
|
-
),
|
|
222
|
-
|
|
223
|
-
'style_block_with_selector' => array(
|
|
224
|
-
'block_styles' => array(
|
|
225
|
-
'spacing' => array(
|
|
226
|
-
'padding' => array(
|
|
227
|
-
'top' => '42px',
|
|
228
|
-
'left' => '2%',
|
|
229
|
-
'bottom' => '44px',
|
|
230
|
-
'right' => '5rem',
|
|
231
|
-
),
|
|
232
|
-
),
|
|
233
|
-
),
|
|
234
|
-
'options' => array( 'selector' => '.wp-selector > p' ),
|
|
235
|
-
'expected_output' => array(
|
|
236
|
-
'css' => '.wp-selector > p{padding-top:42px;padding-left:2%;padding-bottom:44px;padding-right:5rem;}',
|
|
237
|
-
'declarations' => array(
|
|
238
|
-
'padding-top' => '42px',
|
|
239
|
-
'padding-left' => '2%',
|
|
240
|
-
'padding-bottom' => '44px',
|
|
241
|
-
'padding-right' => '5rem',
|
|
242
|
-
),
|
|
243
|
-
),
|
|
244
|
-
),
|
|
245
|
-
|
|
246
|
-
'elements_with_css_var_value' => array(
|
|
247
|
-
'block_styles' => array(
|
|
248
|
-
'color' => array(
|
|
249
|
-
'text' => 'var:preset|color|my-little-pony',
|
|
250
|
-
),
|
|
251
|
-
),
|
|
252
|
-
'options' => array(
|
|
253
|
-
'selector' => '.wp-selector',
|
|
254
|
-
),
|
|
255
|
-
'expected_output' => array(
|
|
256
|
-
'css' => '.wp-selector{color:var(--wp--preset--color--my-little-pony);}',
|
|
257
|
-
'declarations' => array(
|
|
258
|
-
'color' => 'var(--wp--preset--color--my-little-pony)',
|
|
259
|
-
),
|
|
260
|
-
'classnames' => 'has-text-color has-my-little-pony-color',
|
|
261
|
-
),
|
|
262
|
-
),
|
|
263
|
-
|
|
264
|
-
'elements_with_invalid_preset_style_property' => array(
|
|
265
|
-
'block_styles' => array(
|
|
266
|
-
'color' => array(
|
|
267
|
-
'text' => 'var:preset|invalid_property|my-little-pony',
|
|
268
|
-
),
|
|
269
|
-
),
|
|
270
|
-
'options' => array( 'selector' => '.wp-selector' ),
|
|
271
|
-
'expected_output' => array(
|
|
272
|
-
'classnames' => 'has-text-color',
|
|
273
|
-
),
|
|
274
|
-
),
|
|
275
|
-
|
|
276
|
-
'valid_classnames_deduped' => array(
|
|
277
|
-
'block_styles' => array(
|
|
278
|
-
'color' => array(
|
|
279
|
-
'text' => 'var:preset|color|copper-socks',
|
|
280
|
-
'background' => 'var:preset|color|splendid-carrot',
|
|
281
|
-
'gradient' => 'var:preset|gradient|like-wow-dude',
|
|
282
|
-
),
|
|
283
|
-
'typography' => array(
|
|
284
|
-
'fontSize' => 'var:preset|font-size|fantastic',
|
|
285
|
-
'fontFamily' => 'var:preset|font-family|totally-awesome',
|
|
286
|
-
),
|
|
287
|
-
),
|
|
288
|
-
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
289
|
-
'expected_output' => array(
|
|
290
|
-
'classnames' => 'has-text-color has-copper-socks-color has-background has-splendid-carrot-background-color has-like-wow-dude-gradient-background has-fantastic-font-size has-totally-awesome-font-family',
|
|
291
|
-
),
|
|
292
|
-
),
|
|
293
|
-
|
|
294
|
-
'valid_classnames_and_css_vars' => array(
|
|
295
|
-
'block_styles' => array(
|
|
296
|
-
'color' => array(
|
|
297
|
-
'text' => 'var:preset|color|teal-independents',
|
|
298
|
-
),
|
|
299
|
-
),
|
|
300
|
-
'options' => array(),
|
|
301
|
-
'expected_output' => array(
|
|
302
|
-
'css' => 'color:var(--wp--preset--color--teal-independents);',
|
|
303
|
-
'declarations' => array(
|
|
304
|
-
'color' => 'var(--wp--preset--color--teal-independents)',
|
|
305
|
-
),
|
|
306
|
-
'classnames' => 'has-text-color has-teal-independents-color',
|
|
307
|
-
),
|
|
308
|
-
),
|
|
309
|
-
|
|
310
|
-
'valid_classnames_with_null_style_values' => array(
|
|
311
|
-
'block_styles' => array(
|
|
312
|
-
'color' => array(
|
|
313
|
-
'text' => '#fff',
|
|
314
|
-
'background' => null,
|
|
315
|
-
),
|
|
316
|
-
),
|
|
317
|
-
'options' => array(),
|
|
318
|
-
'expected_output' => array(
|
|
319
|
-
'css' => 'color:#fff;',
|
|
320
|
-
'declarations' => array(
|
|
321
|
-
'color' => '#fff',
|
|
322
|
-
),
|
|
323
|
-
'classnames' => 'has-text-color',
|
|
324
|
-
),
|
|
325
|
-
),
|
|
326
|
-
|
|
327
|
-
'invalid_classnames_preset_value' => array(
|
|
328
|
-
'block_styles' => array(
|
|
329
|
-
'color' => array(
|
|
330
|
-
'text' => 'var:cheese|color|fantastic',
|
|
331
|
-
'background' => 'var:preset|fromage|fantastic',
|
|
332
|
-
),
|
|
333
|
-
'spacing' => array(
|
|
334
|
-
'margin' => 'var:cheese|spacing|margin',
|
|
335
|
-
'padding' => 'var:preset|spacing|padding',
|
|
336
|
-
),
|
|
337
|
-
),
|
|
338
|
-
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
339
|
-
'expected_output' => array(
|
|
340
|
-
'classnames' => 'has-text-color has-background',
|
|
341
|
-
),
|
|
342
|
-
),
|
|
343
|
-
|
|
344
|
-
'valid_spacing_single_preset_values' => array(
|
|
345
|
-
'block_styles' => array(
|
|
346
|
-
'spacing' => array(
|
|
347
|
-
'margin' => 'var:preset|spacing|10',
|
|
348
|
-
'padding' => 'var:preset|spacing|20',
|
|
349
|
-
),
|
|
350
|
-
),
|
|
351
|
-
'options' => array(),
|
|
352
|
-
'expected_output' => array(
|
|
353
|
-
'css' => 'padding:var(--wp--preset--spacing--20);margin:var(--wp--preset--spacing--10);',
|
|
354
|
-
'declarations' => array(
|
|
355
|
-
'padding' => 'var(--wp--preset--spacing--20)',
|
|
356
|
-
'margin' => 'var(--wp--preset--spacing--10)',
|
|
357
|
-
),
|
|
358
|
-
),
|
|
359
|
-
),
|
|
360
|
-
|
|
361
|
-
'valid_spacing_multi_preset_values' => array(
|
|
362
|
-
'block_styles' => array(
|
|
363
|
-
'spacing' => array(
|
|
364
|
-
'margin' => array(
|
|
365
|
-
'left' => 'var:preset|spacing|10',
|
|
366
|
-
'right' => 'var:preset|spacing|3XL',
|
|
367
|
-
'top' => '1rem',
|
|
368
|
-
'bottom' => '1rem',
|
|
369
|
-
),
|
|
370
|
-
'padding' => array(
|
|
371
|
-
'left' => 'var:preset|spacing|30',
|
|
372
|
-
'right' => 'var:preset|spacing|3XL',
|
|
373
|
-
'top' => '14px',
|
|
374
|
-
'bottom' => '14px',
|
|
375
|
-
),
|
|
376
|
-
),
|
|
377
|
-
),
|
|
378
|
-
'options' => array(),
|
|
379
|
-
'expected_output' => array(
|
|
380
|
-
'css' => 'padding-left:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--3-xl);padding-top:14px;padding-bottom:14px;margin-left:var(--wp--preset--spacing--10);margin-right:var(--wp--preset--spacing--3-xl);margin-top:1rem;margin-bottom:1rem;',
|
|
381
|
-
'declarations' => array(
|
|
382
|
-
'padding-left' => 'var(--wp--preset--spacing--30)',
|
|
383
|
-
'padding-right' => 'var(--wp--preset--spacing--3-xl)',
|
|
384
|
-
'padding-top' => '14px',
|
|
385
|
-
'padding-bottom' => '14px',
|
|
386
|
-
'margin-left' => 'var(--wp--preset--spacing--10)',
|
|
387
|
-
'margin-right' => 'var(--wp--preset--spacing--3-xl)',
|
|
388
|
-
'margin-top' => '1rem',
|
|
389
|
-
'margin-bottom' => '1rem',
|
|
390
|
-
),
|
|
391
|
-
),
|
|
392
|
-
),
|
|
393
|
-
|
|
394
|
-
'invalid_spacing_multi_preset_values' => array(
|
|
395
|
-
'block_styles' => array(
|
|
396
|
-
'spacing' => array(
|
|
397
|
-
'margin' => array(
|
|
398
|
-
'left' => 'var:preset|spaceman|10',
|
|
399
|
-
'right' => 'var:preset|spaceman|20',
|
|
400
|
-
'top' => '1rem',
|
|
401
|
-
'bottom' => '0',
|
|
402
|
-
),
|
|
403
|
-
),
|
|
404
|
-
),
|
|
405
|
-
'options' => array(),
|
|
406
|
-
'expected_output' => array(
|
|
407
|
-
'css' => 'margin-top:1rem;margin-bottom:0;',
|
|
408
|
-
'declarations' => array(
|
|
409
|
-
'margin-top' => '1rem',
|
|
410
|
-
'margin-bottom' => '0',
|
|
411
|
-
),
|
|
412
|
-
),
|
|
413
|
-
),
|
|
414
|
-
|
|
415
|
-
'invalid_classnames_options' => array(
|
|
416
|
-
'block_styles' => array(
|
|
417
|
-
'typography' => array(
|
|
418
|
-
'fontSize' => array(
|
|
419
|
-
'tomodachi' => 'friends',
|
|
420
|
-
),
|
|
421
|
-
'fontFamily' => array(
|
|
422
|
-
'oishii' => 'tasty',
|
|
423
|
-
),
|
|
424
|
-
),
|
|
425
|
-
),
|
|
426
|
-
'options' => array(),
|
|
427
|
-
'expected_output' => array(),
|
|
428
|
-
),
|
|
429
|
-
|
|
430
|
-
'inline_valid_box_model_style_with_sides' => array(
|
|
431
|
-
'block_styles' => array(
|
|
432
|
-
'border' => array(
|
|
433
|
-
'top' => array(
|
|
434
|
-
'color' => '#fe1',
|
|
435
|
-
'width' => '1.5rem',
|
|
436
|
-
'style' => 'dashed',
|
|
437
|
-
),
|
|
438
|
-
'right' => array(
|
|
439
|
-
'color' => '#fe2',
|
|
440
|
-
'width' => '1.4rem',
|
|
441
|
-
'style' => 'solid',
|
|
442
|
-
),
|
|
443
|
-
'bottom' => array(
|
|
444
|
-
'color' => '#fe3',
|
|
445
|
-
'width' => '1.3rem',
|
|
446
|
-
),
|
|
447
|
-
'left' => array(
|
|
448
|
-
'color' => 'var:preset|color|swampy-yellow',
|
|
449
|
-
'width' => '0.5rem',
|
|
450
|
-
'style' => 'dotted',
|
|
451
|
-
),
|
|
452
|
-
),
|
|
453
|
-
),
|
|
454
|
-
'options' => array(),
|
|
455
|
-
'expected_output' => array(
|
|
456
|
-
'css' => 'border-top-color:#fe1;border-top-width:1.5rem;border-top-style:dashed;border-right-color:#fe2;border-right-width:1.4rem;border-right-style:solid;border-bottom-color:#fe3;border-bottom-width:1.3rem;border-left-color:var(--wp--preset--color--swampy-yellow);border-left-width:0.5rem;border-left-style:dotted;',
|
|
457
|
-
'declarations' => array(
|
|
458
|
-
'border-top-color' => '#fe1',
|
|
459
|
-
'border-top-width' => '1.5rem',
|
|
460
|
-
'border-top-style' => 'dashed',
|
|
461
|
-
'border-right-color' => '#fe2',
|
|
462
|
-
'border-right-width' => '1.4rem',
|
|
463
|
-
'border-right-style' => 'solid',
|
|
464
|
-
'border-bottom-color' => '#fe3',
|
|
465
|
-
'border-bottom-width' => '1.3rem',
|
|
466
|
-
'border-left-color' => 'var(--wp--preset--color--swampy-yellow)',
|
|
467
|
-
'border-left-width' => '0.5rem',
|
|
468
|
-
'border-left-style' => 'dotted',
|
|
469
|
-
),
|
|
470
|
-
),
|
|
471
|
-
),
|
|
472
|
-
|
|
473
|
-
'inline_invalid_box_model_style_with_sides' => array(
|
|
474
|
-
'block_styles' => array(
|
|
475
|
-
'border' => array(
|
|
476
|
-
'top' => array(
|
|
477
|
-
'top' => '#fe1',
|
|
478
|
-
'right' => '1.5rem',
|
|
479
|
-
'cheese' => 'dashed',
|
|
480
|
-
),
|
|
481
|
-
'right' => array(
|
|
482
|
-
'right' => '#fe2',
|
|
483
|
-
'top' => '1.4rem',
|
|
484
|
-
'bacon' => 'solid',
|
|
485
|
-
),
|
|
486
|
-
'bottom' => array(
|
|
487
|
-
'color' => 'var:preset|color|terrible-lizard',
|
|
488
|
-
'bottom' => '1.3rem',
|
|
489
|
-
),
|
|
490
|
-
'left' => array(
|
|
491
|
-
'left' => null,
|
|
492
|
-
'width' => null,
|
|
493
|
-
'top' => 'dotted',
|
|
494
|
-
),
|
|
495
|
-
),
|
|
496
|
-
),
|
|
497
|
-
'options' => array(),
|
|
498
|
-
'expected_output' => array(
|
|
499
|
-
'css' => 'border-bottom-color:var(--wp--preset--color--terrible-lizard);',
|
|
500
|
-
'declarations' => array(
|
|
501
|
-
'border-bottom-color' => 'var(--wp--preset--color--terrible-lizard)',
|
|
502
|
-
),
|
|
503
|
-
),
|
|
504
|
-
),
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Tests adding rules to a store and retrieving a generated stylesheet.
|
|
510
|
-
*
|
|
511
|
-
* @covers ::wp_style_engine_get_styles
|
|
512
|
-
* @covers WP_Style_Engine::store_css_rule
|
|
513
|
-
*/
|
|
514
|
-
public function test_should_store_block_styles_using_context() {
|
|
515
|
-
$block_styles = array(
|
|
516
|
-
'spacing' => array(
|
|
517
|
-
'padding' => array(
|
|
518
|
-
'top' => '42px',
|
|
519
|
-
'left' => '2%',
|
|
520
|
-
'bottom' => '44px',
|
|
521
|
-
'right' => '5rem',
|
|
522
|
-
),
|
|
523
|
-
),
|
|
524
|
-
);
|
|
525
|
-
|
|
526
|
-
$generated_styles = wp_style_engine_get_styles(
|
|
527
|
-
$block_styles,
|
|
528
|
-
array(
|
|
529
|
-
'context' => 'block-supports',
|
|
530
|
-
'selector' => 'article',
|
|
531
|
-
)
|
|
532
|
-
);
|
|
533
|
-
$store = WP_Style_Engine::get_store( 'block-supports' );
|
|
534
|
-
$rule = $store->get_all_rules()['article'];
|
|
535
|
-
|
|
536
|
-
$this->assertSame( $generated_styles['css'], $rule->get_css() );
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Tests that passing no context does not store styles.
|
|
541
|
-
*
|
|
542
|
-
* @covers ::wp_style_engine_get_styles
|
|
543
|
-
*/
|
|
544
|
-
public function test_should_not_store_block_styles_without_context() {
|
|
545
|
-
$block_styles = array(
|
|
546
|
-
'typography' => array(
|
|
547
|
-
'fontSize' => '999px',
|
|
548
|
-
),
|
|
549
|
-
);
|
|
550
|
-
|
|
551
|
-
wp_style_engine_get_styles(
|
|
552
|
-
$block_styles,
|
|
553
|
-
array(
|
|
554
|
-
'selector' => '#font-size-rulez',
|
|
555
|
-
)
|
|
556
|
-
);
|
|
557
|
-
|
|
558
|
-
$all_stores = WP_Style_Engine_CSS_Rules_Store::get_stores();
|
|
559
|
-
|
|
560
|
-
$this->assertEmpty( $all_stores );
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* Tests adding rules to a store and retrieving a generated stylesheet.
|
|
565
|
-
*
|
|
566
|
-
* @covers ::wp_style_engine_get_stylesheet_from_context
|
|
567
|
-
*/
|
|
568
|
-
public function test_should_get_stored_stylesheet_from_context() {
|
|
569
|
-
$css_rules = array(
|
|
570
|
-
array(
|
|
571
|
-
'selector' => '.frodo',
|
|
572
|
-
'declarations' => array(
|
|
573
|
-
'color' => 'brown',
|
|
574
|
-
'height' => '10px',
|
|
575
|
-
'width' => '30px',
|
|
576
|
-
'border-style' => 'dotted',
|
|
577
|
-
),
|
|
578
|
-
),
|
|
579
|
-
array(
|
|
580
|
-
'selector' => '.samwise',
|
|
581
|
-
'declarations' => array(
|
|
582
|
-
'color' => 'brown',
|
|
583
|
-
'height' => '20px',
|
|
584
|
-
'width' => '50px',
|
|
585
|
-
'border-style' => 'solid',
|
|
586
|
-
),
|
|
587
|
-
),
|
|
588
|
-
);
|
|
589
|
-
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules(
|
|
590
|
-
$css_rules,
|
|
591
|
-
array(
|
|
592
|
-
'context' => 'test-store',
|
|
593
|
-
)
|
|
594
|
-
);
|
|
595
|
-
|
|
596
|
-
$this->assertSame( $compiled_stylesheet, wp_style_engine_get_stylesheet_from_context( 'test-store' ) );
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Tests returning a generated stylesheet from a set of rules.
|
|
601
|
-
*
|
|
602
|
-
* @covers ::wp_style_engine_get_stylesheet_from_css_rules
|
|
603
|
-
* @covers WP_Style_Engine::compile_stylesheet_from_css_rules
|
|
604
|
-
*/
|
|
605
|
-
public function test_should_return_stylesheet_from_css_rules() {
|
|
606
|
-
$css_rules = array(
|
|
607
|
-
array(
|
|
608
|
-
'selector' => '.saruman',
|
|
609
|
-
'declarations' => array(
|
|
610
|
-
'color' => 'white',
|
|
611
|
-
'height' => '100px',
|
|
612
|
-
'border-style' => 'solid',
|
|
613
|
-
'align-self' => 'unset',
|
|
614
|
-
),
|
|
615
|
-
),
|
|
616
|
-
array(
|
|
617
|
-
'selector' => '.gandalf',
|
|
618
|
-
'declarations' => array(
|
|
619
|
-
'color' => 'grey',
|
|
620
|
-
'height' => '90px',
|
|
621
|
-
'border-style' => 'dotted',
|
|
622
|
-
'align-self' => 'safe center',
|
|
623
|
-
),
|
|
624
|
-
),
|
|
625
|
-
array(
|
|
626
|
-
'selector' => '.radagast',
|
|
627
|
-
'declarations' => array(
|
|
628
|
-
'color' => 'brown',
|
|
629
|
-
'height' => '60px',
|
|
630
|
-
'border-style' => 'dashed',
|
|
631
|
-
'align-self' => 'stretch',
|
|
632
|
-
),
|
|
633
|
-
),
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules, array( 'prettify' => false ) );
|
|
637
|
-
|
|
638
|
-
$this->assertSame( '.saruman{color:white;height:100px;border-style:solid;align-self:unset;}.gandalf{color:grey;height:90px;border-style:dotted;align-self:safe center;}.radagast{color:brown;height:60px;border-style:dashed;align-self:stretch;}', $compiled_stylesheet );
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* Tests that incoming styles are deduped and merged.
|
|
643
|
-
*
|
|
644
|
-
* @covers ::wp_style_engine_get_stylesheet_from_css_rules
|
|
645
|
-
* @covers WP_Style_Engine::compile_stylesheet_from_css_rules
|
|
646
|
-
*/
|
|
647
|
-
public function test_should_dedupe_and_merge_css_rules() {
|
|
648
|
-
$css_rules = array(
|
|
649
|
-
array(
|
|
650
|
-
'selector' => '.gandalf',
|
|
651
|
-
'declarations' => array(
|
|
652
|
-
'color' => 'grey',
|
|
653
|
-
'height' => '90px',
|
|
654
|
-
'border-style' => 'dotted',
|
|
655
|
-
),
|
|
656
|
-
),
|
|
657
|
-
array(
|
|
658
|
-
'selector' => '.gandalf',
|
|
659
|
-
'declarations' => array(
|
|
660
|
-
'color' => 'white',
|
|
661
|
-
'height' => '190px',
|
|
662
|
-
'padding' => '10px',
|
|
663
|
-
'margin-bottom' => '100px',
|
|
664
|
-
),
|
|
665
|
-
),
|
|
666
|
-
array(
|
|
667
|
-
'selector' => '.dumbledore',
|
|
668
|
-
'declarations' => array(
|
|
669
|
-
'color' => 'grey',
|
|
670
|
-
'height' => '90px',
|
|
671
|
-
'border-style' => 'dotted',
|
|
672
|
-
),
|
|
673
|
-
),
|
|
674
|
-
array(
|
|
675
|
-
'selector' => '.rincewind',
|
|
676
|
-
'declarations' => array(
|
|
677
|
-
'color' => 'grey',
|
|
678
|
-
'height' => '90px',
|
|
679
|
-
'border-style' => 'dotted',
|
|
680
|
-
),
|
|
681
|
-
),
|
|
682
|
-
);
|
|
683
|
-
|
|
684
|
-
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules, array( 'prettify' => false ) );
|
|
685
|
-
|
|
686
|
-
$this->assertSame( '.gandalf{color:white;height:190px;border-style:dotted;padding:10px;margin-bottom:100px;}.dumbledore,.rincewind{color:grey;height:90px;border-style:dotted;}', $compiled_stylesheet );
|
|
687
|
-
}
|
|
688
|
-
}
|