<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[58936] trunk: Background images: resolve theme.json dynamic ref values and ensure appropriate style default values </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/58936">58936</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/58936","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ramonopoly</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-08-26 05:38:05 +0000 (Mon, 26 Aug 2024)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Background images: resolve theme.json dynamic ref values and ensure appropriate style default values
The commit syncs the following changes from Gutenberg:
- Background images: add support for theme.json ref value resolution gutenberg<a href="https://core.trac.wordpress.org/ticket/64128">#64128</a>
- Background images: ensure appropriate default values gutenberg<a href="https://core.trac.wordpress.org/ticket/64192">#64192</a>
- Background image: ensure consistency with defaults and fix reset/remove functionality gutenberg<a href="https://core.trac.wordpress.org/ticket/64328">#64328</a>
These changes brings consistency to the default background image styles WordPress applies to user uploaded images, and adds support for ref resolution to "background" style properties.
Props andrewserong, aaronrobertshaw.
Fixes <a href="https://core.trac.wordpress.org/ticket/61858">#61858</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportsbackgroundphp">trunk/src/wp-includes/block-supports/background.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportswpRenderBackgroundSupportphp">trunk/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonphp">trunk/tests/phpunit/tests/theme/wpThemeJson.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportsbackgroundphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/background.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/background.php 2024-08-25 23:47:01 UTC (rev 58935)
+++ trunk/src/wp-includes/block-supports/background.php 2024-08-26 05:38:05 UTC (rev 58936)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -75,7 +75,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If the background size is set to `contain` and no position is set, set the position to `center`.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $background_styles['backgroundPosition'] = 'center';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $background_styles['backgroundPosition'] = '50% 50%';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme-json.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json.php 2024-08-25 23:47:01 UTC (rev 58935)
+++ trunk/src/wp-includes/class-wp-theme-json.php 2024-08-26 05:38:05 UTC (rev 58936)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2295,7 +2295,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * array(
</span><span class="cx" style="display: block; padding: 0 10px"> * 'name' => 'property_name',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 'value' => 'property_value,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 'value' => 'property_value',
</ins><span class="cx" style="display: block; padding: 0 10px"> * )
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2303,6 +2303,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set.
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.6.0 Pass current theme JSON settings to wp_get_typography_font_size_value(), and process background properties.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.7.0 `ref` resolution of background properties, and assigning custom default values.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $styles Styles to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $settings Theme settings.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2356,11 +2357,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Processes background styles.
- if ( 'background' === $value_path[0] && isset( $styles['background'] ) ) {
- $background_styles = wp_style_engine_get_styles( array( 'background' => $styles['background'] ) );
- $value = isset( $background_styles['declarations'][ $css_property ] ) ? $background_styles['declarations'][ $css_property ] : $value;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Processes background image styles.
+ * If the value is a URL, it will be converted to a CSS `url()` value.
+ * For uploaded image (images with a database ID), apply size and position defaults,
+ * equal to those applied in block supports in lib/background.php.
+ */
+ if ( 'background-image' === $css_property && ! empty( $value ) ) {
+ $background_styles = wp_style_engine_get_styles(
+ array( 'background' => array( 'backgroundImage' => $value ) )
+ );
+ $value = $background_styles['declarations'][ $css_property ];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $value ) && static::ROOT_BLOCK_SELECTOR !== $selector && ! empty( $styles['background']['backgroundImage']['id'] ) ) {
+ if ( 'background-size' === $css_property ) {
+ $value = 'cover';
+ }
+ // If the background size is set to `contain` and no position is set, set the position to `center`.
+ if ( 'background-position' === $css_property ) {
+ $background_size = $styles['background']['backgroundSize'] ?? null;
+ $value = 'contain' === $background_size ? '50% 50%' : null;
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Skip if empty and not "0" or value represents array of longhand values.
</span><span class="cx" style="display: block; padding: 0 10px"> $has_missing_value = empty( $value ) && ! is_numeric( $value );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2421,6 +2439,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * to the standard form "--wp--preset--color--secondary".
</span><span class="cx" style="display: block; padding: 0 10px"> * This is already done by the sanitize method,
</span><span class="cx" style="display: block; padding: 0 10px"> * so every property will be in the standard form.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.7.0 Added support for background image refs.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $styles Styles subtree.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $path Which property to process.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2437,14 +2456,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * This converts references to a path to the value at that path
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * where the values is an array with a "ref" key, pointing to a path.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * where the value is an array with a "ref" key, pointing to a path.
</ins><span class="cx" style="display: block; padding: 0 10px"> * For example: { "ref": "style.color.background" } => "#fff".
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * In the case of backgroundImage, if both a ref and a URL are present in the value,
+ * the URL takes precedence and the ref is ignored.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_array( $value ) && isset( $value['ref'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $value_path = explode( '.', $value['ref'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $ref_value = _wp_array_get( $theme_json, $value_path );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Background Image refs can refer to a string or an array containing a URL string.
+ $ref_value_url = $ref_value['url'] ?? null;
</ins><span class="cx" style="display: block; padding: 0 10px"> // Only use the ref value if we find anything.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $ref_value ) && is_string( $ref_value ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $ref_value ) && ( is_string( $ref_value ) || is_string( $ref_value_url ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $value = $ref_value;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3083,6 +3106,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0 Duotone preset also has origins.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.7.0 Replace background image objects during merge.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Theme_JSON $incoming Data to merge.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3206,6 +3230,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /*
+ * Style values are merged at the leaf level, however
+ * some values provide exceptions, namely style values that are
+ * objects and represent unique definitions for the style.
+ */
+ $style_nodes = static::get_styles_block_nodes();
+ foreach ( $style_nodes as $style_node ) {
+ $path = $style_node['path'];
+ /*
+ * Background image styles should be replaced, not merged,
+ * as they themselves are specific object definitions for the style.
+ */
+ $background_image_path = array_merge( $path, static::PROPERTIES_METADATA['background-image'] );
+ $content = _wp_array_get( $incoming_data, $background_image_path, null );
+ if ( isset( $content ) ) {
+ _wp_array_set( $this->theme_json, $background_image_path, $content );
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportswpRenderBackgroundSupportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php 2024-08-25 23:47:01 UTC (rev 58935)
+++ trunk/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php 2024-08-26 05:38:05 UTC (rev 58936)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,6 +70,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60175
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61123
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61720
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 61858
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::wp_render_background_support
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -154,7 +155,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundSize' => 'contain',
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundAttachment' => 'fixed',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'expected_wrapper' => '<div class="has-background" style="background-image:url('https://example.com/image.jpg');background-position:center;background-repeat:no-repeat;background-size:contain;background-attachment:fixed;">Content</div>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'expected_wrapper' => '<div class="has-background" style="background-image:url('https://example.com/image.jpg');background-position:50% 50%;background-repeat:no-repeat;background-size:contain;background-attachment:fixed;">Content</div>',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wrapper' => '<div>Content</div>',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'background image style is appended if a style attribute already exists' => array(
</span></span></pre></div>
<a id="trunktestsphpunitteststhemewpThemeJsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/wpThemeJson.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpThemeJson.php 2024-08-25 23:47:01 UTC (rev 58935)
+++ trunk/tests/phpunit/tests/theme/wpThemeJson.php 2024-08-26 05:38:05 UTC (rev 58936)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2335,6 +2335,115 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 61858
+ */
+ public function test_merge_incoming_background_styles() {
+ $theme_json = new WP_Theme_JSON(
+ array(
+ 'version' => WP_Theme_JSON::LATEST_SCHEMA,
+ 'styles' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/quote.png',
+ ),
+ 'backgroundSize' => 'cover',
+ ),
+ 'blocks' => array(
+ 'core/group' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'ref' => 'styles.blocks.core/verse.background.backgroundImage',
+ ),
+ 'backgroundAttachment' => 'fixed',
+ ),
+ ),
+ 'core/quote' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/quote.png',
+ ),
+ 'backgroundAttachment' => array(
+ 'ref' => 'styles.blocks.core/group.background.backgroundAttachment',
+ ),
+ ),
+ ),
+ ),
+ ),
+ )
+ );
+
+ $update_background_image_styles = array(
+ 'version' => WP_Theme_JSON::LATEST_SCHEMA,
+ 'styles' => array(
+ 'background' => array(
+ 'backgroundSize' => 'contain',
+ ),
+ 'blocks' => array(
+ 'core/group' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/group.png',
+ ),
+ ),
+ ),
+ 'core/quote' => array(
+ 'background' => array(
+ 'backgroundAttachment' => 'fixed',
+ ),
+ ),
+ 'core/verse' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'ref' => 'styles.blocks.core/group.background.backgroundImage',
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ $expected = array(
+ 'version' => WP_Theme_JSON::LATEST_SCHEMA,
+ 'styles' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/quote.png',
+ ),
+ 'backgroundSize' => 'contain',
+ ),
+ 'blocks' => array(
+ 'core/group' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/group.png',
+ ),
+ 'backgroundAttachment' => 'fixed',
+ ),
+ ),
+ 'core/quote' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/quote.png',
+ ),
+ 'backgroundAttachment' => 'fixed',
+ ),
+ ),
+ 'core/verse' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'ref' => 'styles.blocks.core/group.background.backgroundImage',
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ $theme_json->merge( new WP_Theme_JSON( $update_background_image_styles ) );
+ $actual = $theme_json->get_raw_data();
+
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 54336
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_remove_insecure_properties_removes_unsafe_styles() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5006,12 +5115,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Tests that theme background image styles are correctly generated.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Tests that theme background image styles are correctly generated,
+ * and that default background size of "cover" isn't
+ * applied (it's only applied to blocks).
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61123
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61165
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61720
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61704
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 61858
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_top_level_background_image_styles() {
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_json = new WP_Theme_JSON(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5022,7 +5134,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundImage' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'url' => 'http://example.org/image.png',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'backgroundSize' => 'contain',
</del><span class="cx" style="display: block; padding: 0 10px"> 'backgroundRepeat' => 'no-repeat',
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundPosition' => 'center center',
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundAttachment' => 'fixed',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5036,7 +5147,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'selector' => 'body',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;background-attachment: fixed;}";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-attachment: fixed;}";
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type do not match expectations' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_json = new WP_Theme_JSON(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5059,8 +5170,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Block-level global background image styles.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61588
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61720
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 61858
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_block_background_image_styles() {
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_json = new WP_Theme_JSON(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5071,7 +5185,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'core/group' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'background' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundImage' => "url('http://example.org/group.png')",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'backgroundSize' => 'cover',
</del><span class="cx" style="display: block; padding: 0 10px"> 'backgroundRepeat' => 'no-repeat',
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundPosition' => 'center center',
</span><span class="cx" style="display: block; padding: 0 10px"> 'backgroundAttachment' => 'fixed',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5079,19 +5192,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'core/quote' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'background' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'backgroundImage' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'backgroundImage' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'url' => 'http://example.org/quote.png',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'id' => 321,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'backgroundSize' => 'cover',
- 'backgroundRepeat' => 'no-repeat',
- 'backgroundPosition' => 'center center',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'backgroundSize' => 'contain',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'core/verse' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/verse.png',
+ 'id' => 123,
+ ),
+ ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $group_node = array(
+ 'name' => 'core/group',
+ 'path' => array( 'styles', 'blocks', 'core/group' ),
+ 'selector' => '.wp-block-group',
+ 'selectors' => array(
+ 'root' => '.wp-block-group',
+ ),
+ );
+
+ $group_styles = ":root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-position: center center;background-repeat: no-repeat;background-attachment: fixed;}";
+ $this->assertSame( $group_styles, $theme_json->get_styles_for_block( $group_node ), 'Styles returned from "::get_styles_for_block()" with core/group background styles as string type do not match expectations.' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $quote_node = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => 'core/quote',
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'styles', 'blocks', 'core/quote' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5101,23 +5233,79 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $quote_styles = ":root :where(.wp-block-quote){background-image: url('http://example.org/quote.png');background-position: center center;background-repeat: no-repeat;background-size: cover;}";
- $this->assertSame( $quote_styles, $theme_json->get_styles_for_block( $quote_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles do not match expectations' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $quote_styles = ":root :where(.wp-block-quote){background-image: url('http://example.org/quote.png');background-position: 50% 50%;background-size: contain;}";
+ $this->assertSame( $quote_styles, $theme_json->get_styles_for_block( $quote_node ), 'Styles returned from "::get_styles_for_block()" with core/quote default background styles do not match expectations.' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $group_node = array(
- 'name' => 'core/group',
- 'path' => array( 'styles', 'blocks', 'core/group' ),
- 'selector' => '.wp-block-group',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $verse_node = array(
+ 'name' => 'core/verse',
+ 'path' => array( 'styles', 'blocks', 'core/verse' ),
+ 'selector' => '.wp-block-verse',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'selectors' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'root' => '.wp-block-group',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'root' => '.wp-block-verse',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $group_styles = ":root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-position: center center;background-repeat: no-repeat;background-size: cover;background-attachment: fixed;}";
- $this->assertSame( $group_styles, $theme_json->get_styles_for_block( $group_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles as string type do not match expectations' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $verse_styles = ":root :where(.wp-block-verse){background-image: url('http://example.org/verse.png');background-size: cover;}";
+ $this->assertSame( $verse_styles, $theme_json->get_styles_for_block( $verse_node ), 'Styles returned from "::get_styles_for_block()" with default core/verse background styles as string type do not match expectations.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Testing background dynamic properties in theme.json.
+ *
+ * @ticket 61858
+ */
+ public function test_get_resolved_background_image_styles() {
+ $theme_json = new WP_Theme_JSON(
+ array(
+ 'version' => WP_Theme_JSON::LATEST_SCHEMA,
+ 'styles' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'url' => 'http://example.org/top.png',
+ ),
+ 'backgroundSize' => 'contain',
+ 'backgroundRepeat' => 'repeat',
+ 'backgroundPosition' => '10% 20%',
+ 'backgroundAttachment' => 'scroll',
+ ),
+ 'blocks' => array(
+ 'core/group' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'id' => 123,
+ 'url' => 'http://example.org/group.png',
+ ),
+ ),
+ ),
+ 'core/post-content' => array(
+ 'background' => array(
+ 'backgroundImage' => array(
+ 'ref' => 'styles.background.backgroundImage',
+ ),
+ 'backgroundSize' => array(
+ 'ref' => 'styles.background.backgroundSize',
+ ),
+ 'backgroundRepeat' => array(
+ 'ref' => 'styles.background.backgroundRepeat',
+ ),
+ 'backgroundPosition' => array(
+ 'ref' => 'styles.background.backgroundPosition',
+ ),
+ 'backgroundAttachment' => array(
+ 'ref' => 'styles.background.backgroundAttachment',
+ ),
+ ),
+ ),
+ ),
+ ),
+ )
+ );
+
+ $expected = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/top.png');background-position: 10% 20%;background-repeat: repeat;background-size: contain;background-attachment: scroll;}:root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-size: cover;}:root :where(.wp-block-post-content){background-image: url('http://example.org/top.png');background-position: 10% 20%;background-repeat: repeat;background-size: contain;background-attachment: scroll;}";
+ $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ), null, array( 'skip_root_layout_styles' => true ) ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Tests that base custom CSS is generated correctly.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 61395
</span></span></pre>
</div>
</div>
</body>
</html>