mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Build/Test Tools: Expand unit tests for theme.json.
This changeset adds unit test coverage for the following features: - Gradients - `filter` (Duotones) - `blockGap` - `shadow` - `useRootPaddingAwareAlignments` - `appearanceTools` Props gunterer, johnregan3, audrasjb, mukesh27. Fixes #56611. git-svn-id: https://develop.svn.wordpress.org/trunk@54443 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -22,6 +22,13 @@
|
||||
"slug": "custom-gradient"
|
||||
}
|
||||
],
|
||||
"duotone": [
|
||||
{
|
||||
"colors": [ "#333333", "#aaaaaa" ],
|
||||
"slug": "custom-duotone",
|
||||
"name": "Custom Duotone"
|
||||
}
|
||||
],
|
||||
"custom": false,
|
||||
"customGradient": false
|
||||
},
|
||||
@@ -38,7 +45,8 @@
|
||||
},
|
||||
"spacing": {
|
||||
"units": ["rem"],
|
||||
"customPadding": true
|
||||
"customPadding": true,
|
||||
"blockGap": true
|
||||
},
|
||||
"blocks": {
|
||||
"core/paragraph": {
|
||||
@@ -54,6 +62,45 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"styles" : {
|
||||
"blocks" :{
|
||||
"core/post-featured-image": {
|
||||
"shadow": "10px 10px 5px 0px rgba(0,0,0,0.66)",
|
||||
"filter": {
|
||||
"duotone": "var(--wp--preset--duotone--custom-duotone)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"elements": {
|
||||
"button": {
|
||||
"shadow": "10px 10px 5px 0px rgba(0,0,0,0.66)"
|
||||
},
|
||||
"link": {
|
||||
"typography": {
|
||||
"textDecoration": "none"
|
||||
},
|
||||
"border": {
|
||||
"bottom": {
|
||||
"width": "2px",
|
||||
"color": "currentColor",
|
||||
"style": "solid"
|
||||
}
|
||||
},
|
||||
":hover": {
|
||||
"typography": {
|
||||
"textDecoration": "none"
|
||||
},
|
||||
"border": {
|
||||
"bottom": {
|
||||
"width": "2px",
|
||||
"color": "#000",
|
||||
"style": "dotted"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"customTemplates": [
|
||||
{
|
||||
"name": "page-home",
|
||||
@@ -72,4 +119,4 @@
|
||||
"area": "header"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -431,6 +431,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 53175
|
||||
* @ticket 54336
|
||||
* @ticket 56611
|
||||
*/
|
||||
public function test_get_stylesheet() {
|
||||
$theme_json = new WP_Theme_JSON(
|
||||
@@ -438,13 +439,27 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
'version' => WP_Theme_JSON::LATEST_SCHEMA,
|
||||
'settings' => array(
|
||||
'color' => array(
|
||||
'text' => 'value',
|
||||
'palette' => array(
|
||||
'text' => 'value',
|
||||
'palette' => array(
|
||||
array(
|
||||
'slug' => 'grey',
|
||||
'color' => 'grey',
|
||||
),
|
||||
),
|
||||
'gradients' => array(
|
||||
array(
|
||||
'gradient' => 'linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%)',
|
||||
'name' => 'Custom gradient',
|
||||
'slug' => 'custom-gradient',
|
||||
),
|
||||
),
|
||||
'duotone' => array(
|
||||
array(
|
||||
'colors' => array( '#333333', '#aaaaaa' ),
|
||||
'name' => 'Custom Duotone',
|
||||
'slug' => 'custom-duotone',
|
||||
),
|
||||
),
|
||||
),
|
||||
'typography' => array(
|
||||
'fontFamilies' => array(
|
||||
@@ -478,15 +493,21 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
),
|
||||
'misc' => 'value',
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => '#111',
|
||||
'background' => '#333',
|
||||
),
|
||||
),
|
||||
'button' => array(
|
||||
'shadow' => '10px 10px 5px 0px rgba(0,0,0,0.66)',
|
||||
),
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/group' => array(
|
||||
'color' => array(
|
||||
'gradient' => 'var:preset|gradient|custom-gradient',
|
||||
),
|
||||
'border' => array(
|
||||
'radius' => '10px',
|
||||
),
|
||||
@@ -542,6 +563,9 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
'bottom' => '30px',
|
||||
),
|
||||
),
|
||||
'filter' => array(
|
||||
'duotone' => 'var:preset|duotone|custom-duotone',
|
||||
),
|
||||
),
|
||||
),
|
||||
'spacing' => array(
|
||||
@@ -552,9 +576,9 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$variables = 'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
|
||||
$styles = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-block-group{border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button)){background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .wp-block-image__crop-area{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}';
|
||||
$presets = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}';
|
||||
$variables = "body{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--duotone--custom-duotone: url('#wp-duotone-custom-duotone');--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}";
|
||||
$styles = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-element-button, .wp-block-button__link{box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}.wp-block-group{background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button)){background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}.wp-block-image img, .wp-block-image .wp-block-image__crop-area{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}';
|
||||
$presets = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-custom-gradient-gradient-background{background: var(--wp--preset--gradient--custom-gradient) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}';
|
||||
$all = $variables . $styles . $presets;
|
||||
$this->assertSame( $all, $theme_json->get_stylesheet() );
|
||||
$this->assertSame( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
|
||||
@@ -676,7 +700,6 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
'.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-dark-grey-color{color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-color{color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-color{color: var(--wp--preset--color--white-2-black) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-dark-grey-background-color{background-color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-background-color{background-color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-background-color{background-color: var(--wp--preset--color--white-2-black) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-dark-grey-border-color{border-color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-border-color{border-color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-border-color{border-color: var(--wp--preset--color--white-2-black) !important;}',
|
||||
$theme_json->get_stylesheet( array( 'presets' ) )
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'body{--wp--preset--color--grey: grey;--wp--preset--color--dark-grey: grey;--wp--preset--color--light-grey: grey;--wp--preset--color--white-2-black: grey;--wp--custom--white-2-black: value;}',
|
||||
$theme_json->get_stylesheet( array( 'variables' ) )
|
||||
@@ -2946,6 +2969,41 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56611
|
||||
*/
|
||||
function test_export_data_sets_use_root_padding_aware_alignments() {
|
||||
$theme = new WP_Theme_JSON(
|
||||
array(
|
||||
'version' => 2,
|
||||
'settings' => array(
|
||||
'useRootPaddingAwareAlignments' => true,
|
||||
'blocks' => array(
|
||||
'core/paragraph' => array(
|
||||
'useRootPaddingAwareAlignments' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$actual = $theme->get_data();
|
||||
$expected = array(
|
||||
'version' => 2,
|
||||
'settings' => array(
|
||||
'useRootPaddingAwareAlignments' => true,
|
||||
'blocks' => array(
|
||||
'core/paragraph' => array(
|
||||
'useRootPaddingAwareAlignments' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ticket 56467
|
||||
*/
|
||||
@@ -3353,7 +3411,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
'default'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$this->assertEquals(
|
||||
'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: 1rem; }body { --wp--style--block-gap: 1rem; }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: 1rem;margin-block-end: 0;}body .is-layout-flex{gap: 1rem;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}.wp-block-post-content{color: gray;}.wp-block-social-links.is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links.is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links.is-layout-flex{gap: 0;}.wp-block-buttons.is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons.is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons.is-layout-flex{gap: 0;}',
|
||||
$theme_json->get_stylesheet()
|
||||
);
|
||||
@@ -3468,9 +3526,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$metadata = array(
|
||||
'path' => array(
|
||||
'0' => 'styles',
|
||||
),
|
||||
'path' => array( 'styles' ),
|
||||
'selector' => 'body',
|
||||
);
|
||||
|
||||
@@ -3501,9 +3557,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$metadata = array(
|
||||
'path' => array(
|
||||
'0' => 'styles',
|
||||
),
|
||||
'path' => array( 'styles' ),
|
||||
'selector' => 'body',
|
||||
);
|
||||
|
||||
@@ -3530,9 +3584,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$metadata = array(
|
||||
'path' => array(
|
||||
'0' => 'settings',
|
||||
),
|
||||
'path' => array( 'settings' ),
|
||||
'selector' => 'body',
|
||||
);
|
||||
|
||||
@@ -3542,6 +3594,29 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
$this->assertSame( $expected, $root_rules . $style_rules );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56611
|
||||
*/
|
||||
function test_get_styles_with_appearance_tools() {
|
||||
$theme_json = new WP_Theme_JSON(
|
||||
array(
|
||||
'version' => 2,
|
||||
'settings' => array(
|
||||
'appearanceTools' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$metadata = array(
|
||||
'path' => array( 'settings' ),
|
||||
'selector' => 'body',
|
||||
);
|
||||
|
||||
$expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: ; }body { --wp--style--block-gap: ; }';
|
||||
$root_rules = $theme_json->get_root_layout_rules( WP_Theme_JSON::ROOT_BLOCK_SELECTOR, $metadata );
|
||||
$this->assertSame( $expected, $root_rules );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests generating the spacing presets array based on the spacing scale provided.
|
||||
*
|
||||
@@ -3922,4 +3997,4 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 52991
|
||||
* @ticket 54336
|
||||
* @ticket 56611
|
||||
*/
|
||||
public function test_translations_are_applied() {
|
||||
add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
|
||||
@@ -118,6 +119,15 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
),
|
||||
),
|
||||
),
|
||||
'duotone' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'colors' => array( '#333333', '#aaaaaa' ),
|
||||
'slug' => 'custom-duotone',
|
||||
'name' => 'Custom Duotone',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'typography' => array(
|
||||
'customFontSize' => false,
|
||||
@@ -133,8 +143,9 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
),
|
||||
),
|
||||
'spacing' => array(
|
||||
'units' => array( 'rem' ),
|
||||
'padding' => true,
|
||||
'units' => array( 'rem' ),
|
||||
'padding' => true,
|
||||
'blockGap' => true,
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/paragraph' => array(
|
||||
@@ -244,6 +255,7 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 54336
|
||||
* @ticket 56611
|
||||
*/
|
||||
function test_merges_child_theme_json_into_parent_theme_json() {
|
||||
switch_theme( 'block-theme-child' );
|
||||
@@ -253,6 +265,15 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
'color' => array(
|
||||
'custom' => false,
|
||||
'customGradient' => false,
|
||||
'duotone' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'colors' => array( '#333333', '#aaaaaa' ),
|
||||
'name' => 'Custom Duotone',
|
||||
'slug' => 'custom-duotone',
|
||||
),
|
||||
),
|
||||
),
|
||||
'gradients' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
@@ -297,8 +318,9 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
),
|
||||
),
|
||||
'spacing' => array(
|
||||
'units' => array( 'rem' ),
|
||||
'padding' => true,
|
||||
'blockGap' => true,
|
||||
'units' => array( 'rem' ),
|
||||
'padding' => true,
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/paragraph' => array(
|
||||
@@ -366,7 +388,7 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
WP_Theme_JSON_Resolver::clean_cached_data();
|
||||
}
|
||||
$query_count = count( $this->queries ) - $query_count;
|
||||
$this->assertSame( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' );
|
||||
$this->assertEquals( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' );
|
||||
|
||||
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
|
||||
$this->assertEmpty( $user_cpt );
|
||||
@@ -381,7 +403,7 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
$this->assertSameSets( $user_cpt, $new_user_cpt );
|
||||
}
|
||||
$query_count = count( $this->queries ) - $query_count;
|
||||
$this->assertSame( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' );
|
||||
$this->assertEquals( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' );
|
||||
remove_filter( 'query', array( $this, 'filter_db_query' ) );
|
||||
}
|
||||
|
||||
@@ -430,4 +452,4 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
$this->assertIsArray( $post2 );
|
||||
$this->assertSameSets( array(), $post2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user