@wordpress/style-engine 0.12.0 → 0.14.1-next.d6164808d3.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 +61 -10
- package/class-wp-style-engine-css-rule.php +125 -0
- package/class-wp-style-engine-css-rules-store.php +144 -0
- package/class-wp-style-engine-processor.php +143 -0
- package/class-wp-style-engine.php +265 -144
- package/package.json +2 -2
- package/phpunit/class-wp-style-engine-css-declarations-test.php +129 -3
- package/phpunit/class-wp-style-engine-css-rule-test.php +127 -0
- package/phpunit/class-wp-style-engine-css-rules-store-test.php +171 -0
- package/phpunit/class-wp-style-engine-processor-test.php +266 -0
- 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 +64 -11
- package/src/types.ts +3 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -84,24 +84,150 @@ 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");',
|
|
185
|
+
$css_declarations->get_declarations_string()
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Should remove a declaration
|
|
191
|
+
*/
|
|
192
|
+
public function test_remove_declaration() {
|
|
193
|
+
$input_declarations = array(
|
|
194
|
+
'color' => 'tomato',
|
|
195
|
+
'margin' => '10em 10em 20em 1px',
|
|
196
|
+
'font-family' => 'Happy Font serif',
|
|
197
|
+
);
|
|
198
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
199
|
+
|
|
200
|
+
$this->assertSame(
|
|
201
|
+
'color:tomato;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
202
|
+
$css_declarations->get_declarations_string()
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
$css_declarations->remove_declaration( 'color' );
|
|
206
|
+
$this->assertSame(
|
|
207
|
+
'margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
208
|
+
$css_declarations->get_declarations_string()
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Should remove declarations
|
|
214
|
+
*/
|
|
215
|
+
public function test_remove_declarations() {
|
|
216
|
+
$input_declarations = array(
|
|
217
|
+
'color' => 'cucumber',
|
|
218
|
+
'margin' => '10em 10em 20em 1px',
|
|
219
|
+
'font-family' => 'Happy Font serif',
|
|
220
|
+
);
|
|
221
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
222
|
+
|
|
223
|
+
$this->assertSame(
|
|
224
|
+
'color:cucumber;margin:10em 10em 20em 1px;font-family:Happy Font serif;',
|
|
225
|
+
$css_declarations->get_declarations_string()
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
$css_declarations->remove_declarations( array( 'color', 'margin' ) );
|
|
229
|
+
$this->assertSame(
|
|
230
|
+
'font-family:Happy Font serif;',
|
|
105
231
|
$css_declarations->get_declarations_string()
|
|
106
232
|
);
|
|
107
233
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Tests the Style Engine CSS Rule class.
|
|
4
|
+
*
|
|
5
|
+
* @package Gutenberg
|
|
6
|
+
* @subpackage style-engine
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
require __DIR__ . '/../class-wp-style-engine-css-rule.php';
|
|
10
|
+
require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Tests for registering, storing and generating CSS declarations.
|
|
14
|
+
*/
|
|
15
|
+
class WP_Style_Engine_CSS_Rule_Test extends WP_UnitTestCase {
|
|
16
|
+
/**
|
|
17
|
+
* Should set declarations on instantiation.
|
|
18
|
+
*/
|
|
19
|
+
public function test_instantiate_with_selector_and_rules() {
|
|
20
|
+
$selector = '.law-and-order';
|
|
21
|
+
$input_declarations = array(
|
|
22
|
+
'margin-top' => '10px',
|
|
23
|
+
'font-size' => '2rem',
|
|
24
|
+
);
|
|
25
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
26
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
27
|
+
|
|
28
|
+
$this->assertSame( $selector, $css_rule->get_selector() );
|
|
29
|
+
|
|
30
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
31
|
+
$this->assertSame( $expected, $css_rule->get_css() );
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Test dedupe declaration properties.
|
|
36
|
+
*/
|
|
37
|
+
public function test_dedupe_properties_in_rules() {
|
|
38
|
+
$selector = '.taggart';
|
|
39
|
+
$first_declaration = array(
|
|
40
|
+
'font-size' => '2rem',
|
|
41
|
+
);
|
|
42
|
+
$overwrite_first_declaration = array(
|
|
43
|
+
'font-size' => '4px',
|
|
44
|
+
);
|
|
45
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $first_declaration );
|
|
46
|
+
$css_rule->add_declarations( new WP_Style_Engine_CSS_Declarations( $overwrite_first_declaration ) );
|
|
47
|
+
|
|
48
|
+
$expected = '.taggart{font-size:4px;}';
|
|
49
|
+
$this->assertSame( $expected, $css_rule->get_css() );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Should add declarations.
|
|
54
|
+
*/
|
|
55
|
+
public function test_add_declarations() {
|
|
56
|
+
// Declarations using a WP_Style_Engine_CSS_Declarations object.
|
|
57
|
+
$some_css_declarations = new WP_Style_Engine_CSS_Declarations( array( 'margin-top' => '10px' ) );
|
|
58
|
+
// Declarations using a property => value array.
|
|
59
|
+
$some_more_css_declarations = array( 'font-size' => '1rem' );
|
|
60
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( '.hill-street-blues', $some_css_declarations );
|
|
61
|
+
$css_rule->add_declarations( $some_more_css_declarations );
|
|
62
|
+
|
|
63
|
+
$expected = '.hill-street-blues{margin-top:10px;font-size:1rem;}';
|
|
64
|
+
$this->assertSame( $expected, $css_rule->get_css() );
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Should set selector.
|
|
69
|
+
*/
|
|
70
|
+
public function test_set_selector() {
|
|
71
|
+
$selector = '.taggart';
|
|
72
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $selector );
|
|
73
|
+
|
|
74
|
+
$this->assertSame( $selector, $css_rule->get_selector() );
|
|
75
|
+
|
|
76
|
+
$css_rule->set_selector( '.law-and-order' );
|
|
77
|
+
|
|
78
|
+
$this->assertSame( '.law-and-order', $css_rule->get_selector() );
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Should generate CSS rules.
|
|
83
|
+
*/
|
|
84
|
+
public function test_get_css() {
|
|
85
|
+
$selector = '.chips';
|
|
86
|
+
$input_declarations = array(
|
|
87
|
+
'margin-top' => '10px',
|
|
88
|
+
'font-size' => '2rem',
|
|
89
|
+
);
|
|
90
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
91
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $selector, $css_declarations );
|
|
92
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
93
|
+
|
|
94
|
+
$this->assertSame( $expected, $css_rule->get_css() );
|
|
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
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Tests the Style Engine CSS Rules Store class.
|
|
4
|
+
*
|
|
5
|
+
* @package Gutenberg
|
|
6
|
+
* @subpackage style-engine
|
|
7
|
+
*/
|
|
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';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tests for registering, storing and retrieving CSS Rules.
|
|
15
|
+
*/
|
|
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
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Should create a new store.
|
|
26
|
+
*/
|
|
27
|
+
public function test_create_new_store() {
|
|
28
|
+
$new_pancakes_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'pancakes-with-strawberries' );
|
|
29
|
+
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $new_pancakes_store );
|
|
30
|
+
}
|
|
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
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Should return previously created store when the same selector key is passed.
|
|
48
|
+
*/
|
|
49
|
+
public function test_get_store() {
|
|
50
|
+
$new_fish_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'fish-n-chips' );
|
|
51
|
+
$selector = '.haddock';
|
|
52
|
+
|
|
53
|
+
$new_fish_store->add_rule( $selector )->get_selector();
|
|
54
|
+
$this->assertEquals( $selector, $new_fish_store->add_rule( $selector )->get_selector() );
|
|
55
|
+
|
|
56
|
+
$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() );
|
|
58
|
+
}
|
|
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
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Should return a stored rule.
|
|
97
|
+
*/
|
|
98
|
+
public function test_add_rule() {
|
|
99
|
+
$new_pie_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'meat-pie' );
|
|
100
|
+
$selector = '.wp-block-sauce a:hover';
|
|
101
|
+
$store_rule = $new_pie_store->add_rule( $selector );
|
|
102
|
+
$expected = '';
|
|
103
|
+
$this->assertEquals( $expected, $store_rule->get_css() );
|
|
104
|
+
|
|
105
|
+
$pie_declarations = array(
|
|
106
|
+
'color' => 'brown',
|
|
107
|
+
'border-color' => 'yellow',
|
|
108
|
+
'border-radius' => '10rem',
|
|
109
|
+
);
|
|
110
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $pie_declarations );
|
|
111
|
+
$store_rule->add_declarations( $css_declarations );
|
|
112
|
+
|
|
113
|
+
$store_rule = $new_pie_store->add_rule( $selector );
|
|
114
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
115
|
+
$this->assertEquals( $expected, $store_rule->get_css() );
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Should return all stored rules.
|
|
120
|
+
*/
|
|
121
|
+
public function test_get_all_rules() {
|
|
122
|
+
$new_pizza_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'pizza-with-mozzarella' );
|
|
123
|
+
$selector = '.wp-block-anchovies a:hover';
|
|
124
|
+
$store_rule = $new_pizza_store->add_rule( $selector );
|
|
125
|
+
$expected = array(
|
|
126
|
+
$selector => $store_rule,
|
|
127
|
+
);
|
|
128
|
+
|
|
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() );
|
|
156
|
+
|
|
157
|
+
$new_selector = '.wp-block-mushroom a:hover';
|
|
158
|
+
$newer_pizza_declarations = array(
|
|
159
|
+
'padding' => '100px',
|
|
160
|
+
);
|
|
161
|
+
$new_store_rule = $new_pizza_store->add_rule( $new_selector );
|
|
162
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $newer_pizza_declarations );
|
|
163
|
+
$new_store_rule->add_declarations( array( $css_declarations ) );
|
|
164
|
+
|
|
165
|
+
$expected = array(
|
|
166
|
+
$selector => $store_rule,
|
|
167
|
+
$new_selector => $new_store_rule,
|
|
168
|
+
);
|
|
169
|
+
$this->assertEquals( $expected, $new_pizza_store->get_all_rules() );
|
|
170
|
+
}
|
|
171
|
+
}
|