<!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>[57491] trunk: Editor: introduce `dimensions.aspectRatio` block support.</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/57491">57491</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/57491","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>isabel_brison</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-01-31 02:52:25 +0000 (Wed, 31 Jan 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'>Editor: introduce `dimensions.aspectRatio` block support.

Adds front end rendering logic for the `dimensions.aspectRatio` block support as well as the required logic in `WP_Theme_JSON` and the style engine.

Props andrewserong.
Fixes <a href="https://core.trac.wordpress.org/ticket/60365">#60365</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportsdimensionsphp">trunk/src/wp-includes/block-supports/dimensions.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunksrcwpincludesstyleengineclasswpstyleenginephp">trunk/src/wp-includes/style-engine/class-wp-style-engine.php</a></li>
<li><a href="#trunktestsphpunittestsstyleenginestyleEnginephp">trunk/tests/phpunit/tests/style-engine/styleEngine.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonphp">trunk/tests/phpunit/tests/theme/wpThemeJson.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsblocksupportswpRenderDimensionsSupportphp">trunk/tests/phpunit/tests/block-supports/wpRenderDimensionsSupport.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportsdimensionsphp"></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/dimensions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/dimensions.php       2024-01-30 23:49:09 UTC (rev 57490)
+++ trunk/src/wp-includes/block-supports/dimensions.php 2024-01-31 02:52:25 UTC (rev 57491)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,6 +83,86 @@
</span><span class="cx" style="display: block; padding: 0 10px">        return $attributes;
</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">+/**
+ * Renders server-side dimensions styles to the block wrapper.
+ * This block support uses the `render_block` hook to ensure that
+ * it is also applied to non-server-rendered blocks.
+ *
+ * @since 6.5.0
+ * @access private
+ *
+ * @param  string $block_content Rendered block content.
+ * @param  array  $block         Block object.
+ * @return string                Filtered block content.
+ */
+function wp_render_dimensions_support( $block_content, $block ) {
+       $block_type               = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
+       $block_attributes         = ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) ? $block['attrs'] : array();
+       $has_aspect_ratio_support = block_has_support( $block_type, array( 'dimensions', 'aspectRatio' ), false );
+
+       if (
+               ! $has_aspect_ratio_support ||
+               wp_should_skip_block_supports_serialization( $block_type, 'dimensions', 'aspectRatio' )
+       ) {
+               return $block_content;
+       }
+
+       $dimensions_block_styles                = array();
+       $dimensions_block_styles['aspectRatio'] = $block_attributes['style']['dimensions']['aspectRatio'] ?? null;
+
+       // To ensure the aspect ratio does not get overridden by `minHeight` unset any existing rule.
+       if (
+               isset( $dimensions_block_styles['aspectRatio'] )
+       ) {
+               $dimensions_block_styles['minHeight'] = 'unset';
+       } elseif (
+               isset( $block_attributes['style']['dimensions']['minHeight'] ) ||
+               isset( $block_attributes['minHeight'] )
+       ) {
+               $dimensions_block_styles['aspectRatio'] = 'unset';
+       }
+
+       $styles = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
+
+       if ( ! empty( $styles['css'] ) ) {
+               // Inject dimensions styles to the first element, presuming it's the wrapper, if it exists.
+               $tags = new WP_HTML_Tag_Processor( $block_content );
+
+               if ( $tags->next_tag() ) {
+                       $existing_style = $tags->get_attribute( 'style' );
+                       $updated_style  = '';
+
+                       if ( ! empty( $existing_style ) ) {
+                               $updated_style = $existing_style;
+                               if ( ! str_ends_with( $existing_style, ';' ) ) {
+                                       $updated_style .= ';';
+                               }
+                       }
+
+                       $updated_style .= $styles['css'];
+                       $tags->set_attribute( 'style', $updated_style );
+
+                       if ( ! empty( $styles['classnames'] ) ) {
+                               foreach ( explode( ' ', $styles['classnames'] ) as $class_name ) {
+                                       if (
+                                               str_contains( $class_name, 'aspect-ratio' ) &&
+                                               ! isset( $block_attributes['style']['dimensions']['aspectRatio'] )
+                                       ) {
+                                               continue;
+                                       }
+                                       $tags->add_class( $class_name );
+                               }
+                       }
+               }
+
+               return $tags->get_updated_html();
+       }
+
+       return $block_content;
+}
+
+add_filter( 'render_block', 'wp_render_dimensions_support', 10, 2 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Register the block support.
</span><span class="cx" style="display: block; padding: 0 10px"> WP_Block_Supports::get_instance()->register(
</span><span class="cx" style="display: block; padding: 0 10px">        'dimensions',
</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-01-30 23:49:09 UTC (rev 57490)
+++ trunk/src/wp-includes/class-wp-theme-json.php       2024-01-31 02:52:25 UTC (rev 57491)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -204,10 +204,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.2.0 Added `outline-*`, and `min-height` properties.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.3.0 Added `column-count` property.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.4.0 Added `writing-mode` property.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.5.0 Added `aspect-ratio` property.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        const PROPERTIES_METADATA = array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'aspect-ratio'                      => array( 'dimensions', 'aspectRatio' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 'background'                        => array( 'color', 'gradient' ),
</span><span class="cx" style="display: block; padding: 0 10px">                'background-color'                  => array( 'color', 'background' ),
</span><span class="cx" style="display: block; padding: 0 10px">                'border-radius'                     => array( 'border', 'radius' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,8 +346,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.3.0 Added support for `typography.textColumns`, removed `layout.definitions`.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.4.0 Added support for `layout.allowEditing`, `background.backgroundImage`,
</span><span class="cx" style="display: block; padding: 0 10px">         *              `typography.writingMode`, `lightbox.enabled` and `lightbox.allowEditing`.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 6.5.0 Added support for `layout.allowCustomContentAndWideSize` and
-        *              `background.backgroundSize`.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 6.5.0 Added support for `layout.allowCustomContentAndWideSize`,
+        *              `background.backgroundSize` and `dimensions.aspectRatio`.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        const VALID_SETTINGS = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -380,7 +382,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><span class="cx" style="display: block; padding: 0 10px">                'custom'                        => null,
</span><span class="cx" style="display: block; padding: 0 10px">                'dimensions'                    => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'minHeight' => null,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'aspectRatio' => null,
+                       'minHeight'   => null,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'layout'                        => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'contentSize'                   => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -438,6 +441,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *              updated `blockGap` to be allowed at any level.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.2.0 Added `outline`, and `minHeight` properties.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.3.0 Added support for `typography.textColumns`.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.5.0 Added support for `dimensions.aspectRatio`.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -458,7 +462,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'text'       => null,
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><span class="cx" style="display: block; padding: 0 10px">                'dimensions' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'minHeight' => null,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'aspectRatio' => null,
+                       'minHeight'   => null,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'filter'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'duotone' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -575,7 +580,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.0.0
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.2.0 Added `dimensions.minHeight` and `position.sticky`.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.4.0 Added `background.backgroundImage`.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 6.5.0 Added `background.backgroundSize`.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 6.5.0 Added `background.backgroundSize` and `dimensions.aspectRatio`.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        const APPEARANCE_TOOLS_OPT_INS = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -589,6 +594,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                array( 'color', 'heading' ),
</span><span class="cx" style="display: block; padding: 0 10px">                array( 'color', 'button' ),
</span><span class="cx" style="display: block; padding: 0 10px">                array( 'color', 'caption' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                array( 'dimensions', 'aspectRatio' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 array( 'dimensions', 'minHeight' ),
</span><span class="cx" style="display: block; padding: 0 10px">                array( 'position', 'sticky' ),
</span><span class="cx" style="display: block; padding: 0 10px">                array( 'spacing', 'blockGap' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1921,6 +1927,7 @@
</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 Added the `$settings` and `$properties` parameters.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.1.0 Added `$theme_json`, `$selector`, and `$use_root_padding` parameters.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set.
</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">@@ -1992,6 +1999,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $value = wp_get_typography_font_size_value( array( 'size' => $value ) );
</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">+                        if ( 'aspect-ratio' === $css_property ) {
+                               // For aspect ratio to work, other dimensions rules must be unset.
+                               // This ensures that a fixed height does not override the aspect ratio.
+                               $declarations[] = array(
+                                       'name'  => 'min-height',
+                                       'value' => 'unset',
+                               );
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         $declarations[] = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'name'  => $css_property,
</span><span class="cx" style="display: block; padding: 0 10px">                                'value' => $value,
</span></span></pre></div>
<a id="trunksrcwpincludesstyleengineclasswpstyleenginephp"></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/style-engine/class-wp-style-engine.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/style-engine/class-wp-style-engine.php      2024-01-30 23:49:09 UTC (rev 57490)
+++ trunk/src/wp-includes/style-engine/class-wp-style-engine.php        2024-01-31 02:52:25 UTC (rev 57491)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,7 +23,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.1.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.3.0 Added support for text-columns.
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.4.0 Added support for background.backgroundImage.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 6.5.0 Added support for background.backgroundPosition and background.backgroundRepeat.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.5.0 Added support for background.backgroundPosition,
+ *              background.backgroundRepeat and dimensions.aspectRatio.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> #[AllowDynamicProperties]
</span><span class="cx" style="display: block; padding: 0 10px"> final class WP_Style_Engine {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -190,8 +191,17 @@
</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">                'dimensions' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'minHeight' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'aspectRatio' => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'property_keys' => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'default' => 'aspect-ratio',
+                               ),
+                               'path'          => array( 'dimensions', 'aspectRatio' ),
+                               'classnames'    => array(
+                                       'has-aspect-ratio' => true,
+                               ),
+                       ),
+                       'minHeight'   => array(
+                               'property_keys' => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                         'default' => 'min-height',
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'path'          => array( 'dimensions', 'minHeight' ),
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportswpRenderDimensionsSupportphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/block-supports/wpRenderDimensionsSupport.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/wpRenderDimensionsSupport.php                            (rev 0)
+++ trunk/tests/phpunit/tests/block-supports/wpRenderDimensionsSupport.php      2024-01-31 02:52:25 UTC (rev 57491)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,176 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * @group block-supports
+ *
+ * @covers ::wp_render_dimensions_support
+ */
+class Tests_Block_Supports_WpRenderDimensionsSupport extends WP_UnitTestCase {
+       /**
+        * @var string|null
+        */
+       private $test_block_name;
+
+       /**
+        * Theme root directory.
+        *
+        * @var string
+        */
+       private $theme_root;
+
+       /**
+        * Original theme directory.
+        *
+        * @var string
+        */
+       private $orig_theme_dir;
+
+       public function set_up() {
+               parent::set_up();
+               $this->test_block_name = null;
+               $this->theme_root      = realpath( DIR_TESTDATA . '/themedir1' );
+               $this->orig_theme_dir  = $GLOBALS['wp_theme_directories'];
+
+               // /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
+               $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
+
+               add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) );
+               add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) );
+               add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
+
+               // Clear caches.
+               wp_clean_themes_cache();
+               unset( $GLOBALS['wp_themes'] );
+               WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
+       }
+
+       public function tear_down() {
+               $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
+
+               // Clear up the filters to modify the theme root.
+               remove_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) );
+               remove_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) );
+               remove_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
+
+               wp_clean_themes_cache();
+               unset( $GLOBALS['wp_themes'] );
+               WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
+               unregister_block_type( $this->test_block_name );
+               $this->test_block_name = null;
+               parent::tear_down();
+       }
+
+       public function filter_set_theme_root() {
+               return $this->theme_root;
+       }
+
+       /**
+        * Tests that dimensions block support works as expected.
+        *
+        * @ticket 60365
+        *
+        * @covers ::wp_render_dimensions_support
+        *
+        * @dataProvider data_dimensions_block_support
+        *
+        * @param string $theme_name          The theme to switch to.
+        * @param string $block_name          The test block name to register.
+        * @param mixed  $dimensions_settings The dimensions block support settings.
+        * @param mixed  $dimensions_style    The dimensions styles within the block attributes.
+        * @param string $expected_wrapper    Expected markup for the block wrapper.
+        * @param string $wrapper             Existing markup for the block wrapper.
+        */
+       public function test_dimensions_block_support( $theme_name, $block_name, $dimensions_settings, $dimensions_style, $expected_wrapper, $wrapper ) {
+               switch_theme( $theme_name );
+               $this->test_block_name = $block_name;
+
+               register_block_type(
+                       $this->test_block_name,
+                       array(
+                               'api_version' => 2,
+                               'attributes'  => array(
+                                       'style' => array(
+                                               'type' => 'object',
+                                       ),
+                               ),
+                               'supports'    => array(
+                                       'dimensions' => $dimensions_settings,
+                               ),
+                       )
+               );
+
+               $block = array(
+                       'blockName' => $block_name,
+                       'attrs'     => array(
+                               'style' => array(
+                                       'dimensions' => $dimensions_style,
+                               ),
+                       ),
+               );
+
+               $actual = wp_render_dimensions_support( $wrapper, $block );
+
+               $this->assertEquals(
+                       $expected_wrapper,
+                       $actual,
+                       'Dimensions block wrapper markup should be correct'
+               );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array
+        */
+       public function data_dimensions_block_support() {
+               return array(
+                       'aspect ratio style is applied, with min-height unset' => array(
+                               'theme_name'          => 'block-theme-child-with-fluid-typography',
+                               'block_name'          => 'test/dimensions-rules-are-output',
+                               'dimensions_settings' => array(
+                                       'aspectRatio' => true,
+                               ),
+                               'dimensions_style'    => array(
+                                       'aspectRatio' => '16/9',
+                               ),
+                               'expected_wrapper'    => '<div class="has-aspect-ratio" style="aspect-ratio:16/9;min-height:unset;">Content</div>',
+                               'wrapper'             => '<div>Content</div>',
+                       ),
+                       'dimensions style is appended if a style attribute already exists' => array(
+                               'theme_name'          => 'block-theme-child-with-fluid-typography',
+                               'block_name'          => 'test/dimensions-rules-are-output',
+                               'dimensions_settings' => array(
+                                       'aspectRatio' => true,
+                               ),
+                               'dimensions_style'    => array(
+                                       'aspectRatio' => '16/9',
+                               ),
+                               'expected_wrapper'    => '<div class="wp-block-test has-aspect-ratio" style="color:red;aspect-ratio:16/9;min-height:unset;">Content</div>',
+                               'wrapper'             => '<div class="wp-block-test" style="color:red;">Content</div>',
+                       ),
+                       'aspect ratio style is unset if block has min-height set' => array(
+                               'theme_name'          => 'block-theme-child-with-fluid-typography',
+                               'block_name'          => 'test/dimensions-rules-are-output',
+                               'dimensions_settings' => array(
+                                       'aspectRatio' => true,
+                               ),
+                               'dimensions_style'    => array(
+                                       'minHeight' => '100px',
+                               ),
+                               'expected_wrapper'    => '<div style="min-height:100px;aspect-ratio:unset;">Content</div>',
+                               'wrapper'             => '<div style="min-height:100px">Content</div>',
+                       ),
+                       'aspect ratio style is not applied if the block does not support aspect ratio' => array(
+                               'theme_name'          => 'block-theme-child-with-fluid-typography',
+                               'block_name'          => 'test/background-rules-are-not-output',
+                               'dimensions_settings' => array(
+                                       'aspectRatio' => false,
+                               ),
+                               'dimensions_style'    => array(
+                                       'aspectRatio' => '16/9',
+                               ),
+                               'expected_wrapper'    => '<div>Content</div>',
+                               'wrapper'             => '<div>Content</div>',
+                       ),
+               );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-supports/wpRenderDimensionsSupport.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestsstyleenginestyleEnginephp"></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/style-engine/styleEngine.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/style-engine/styleEngine.php    2024-01-30 23:49:09 UTC (rev 57490)
+++ trunk/tests/phpunit/tests/style-engine/styleEngine.php      2024-01-31 02:52:25 UTC (rev 57491)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -184,6 +184,24 @@
</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">+                        'inline_valid_aspect_ratio_style'              => array(
+                               'block_styles'    => array(
+                                       'dimensions' => array(
+                                               'aspectRatio' => '4/3',
+                                               'minHeight'   => 'unset',
+                                       ),
+                               ),
+                               'options'         => null,
+                               'expected_output' => array(
+                                       'css'          => 'aspect-ratio:4/3;min-height:unset;',
+                                       'declarations' => array(
+                                               'aspect-ratio' => '4/3',
+                                               'min-height'   => 'unset',
+                                       ),
+                                       'classnames'   => 'has-aspect-ratio',
+                               ),
+                       ),
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         'inline_valid_shadow_style'                    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'block_styles'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'shadow' => 'inset 5em 1em gold',
</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-01-30 23:49:09 UTC (rev 57490)
+++ trunk/tests/phpunit/tests/theme/wpThemeJson.php     2024-01-31 02:52:25 UTC (rev 57491)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -279,7 +279,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'caption' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'dimensions' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'minHeight' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'aspectRatio' => true,
+                               'minHeight'   => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'position'   => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'sticky' => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -316,7 +317,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                'caption' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'dimensions' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                'minHeight' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         'aspectRatio' => true,
+                                               'minHeight'   => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'position'   => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                'sticky' => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -495,6 +497,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 56611
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58549
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58550
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 60365
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_stylesheet() {
</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">@@ -567,6 +570,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">                                        'blocks'   => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                'core/cover'        => array(
+                                                       'dimensions' => array(
+                                                               'aspectRatio' => '16/9',
+                                                       ),
+                                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'core/group'        => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'color'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                                'gradient' => 'var:preset|gradient|custom-gradient',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -645,7 +653,7 @@
</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">                $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--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;}';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $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; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}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-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-lef
 t: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width: var(--wp--style--global--content-size);margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignwide{max-width: var(--wp--style--global--wide-size);}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}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;}.wp-block-heading{color: #123456;}.wp-block-heading a:where(:not(.wp-e
 lement-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-post-excerpt{column-count: 2;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $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; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}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-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left
 : auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width: var(--wp--style--global--content-size);margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignwide{max-width: var(--wp--style--global--wide-size);}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}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-cover{min-height: unset;aspect-ratio: 16/9;}.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;}.wp-block-heading
 {color: #123456;}.wp-block-heading 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-post-excerpt{column-count: 2;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}';
</ins><span class="cx" style="display: block; padding: 0 10px">                 $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;}';
</span><span class="cx" style="display: block; padding: 0 10px">                $all       = $variables . $styles . $presets;
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $all, $theme_json->get_stylesheet() );
</span></span></pre>
</div>
</div>

</body>
</html>