<!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>[53085] trunk: Editor: Update layout handling for block supports</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/53085">53085</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/53085","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>gziolo</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-04-06 11:39:55 +0000 (Wed, 06 Apr 2022)</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: Update layout handling for block supports

Backports changes applied in the Gutenberg plugin planned for WordPress 6.0 release. See https://github.com/WordPress/gutenberg/issues/39889.

Props ramonopoly, youknowriad.
See <a href="https://core.trac.wordpress.org/ticket/55505">#55505</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportslayoutphp">trunk/src/wp-includes/block-supports/layout.php</a></li>
</ul>

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

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportslayoutphp"></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/layout.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/layout.php   2022-04-06 09:45:31 UTC (rev 53084)
+++ trunk/src/wp-includes/block-supports/layout.php     2022-04-06 11:39:55 UTC (rev 53085)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -35,14 +35,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @access private
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $selector              CSS selector.
- * @param array  $layout                Layout object. The one that is passed has already checked
- *                                      the existence of default block layout.
- * @param bool   $has_block_gap_support Whether the theme has support for the block gap.
- * @param string $gap_value             The block gap value to apply.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string  $selector                      CSS selector.
+ * @param array   $layout                        Layout object. The one that is passed has already checked
+ *                                               the existence of default block layout.
+ * @param boolean $has_block_gap_support         Whether the theme has support for the block gap.
+ * @param string  $gap_value                     The block gap value to apply.
+ * @param boolean $should_skip_gap_serialization Whether to skip applying the user-defined value set in the editor.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return string CSS style.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         $layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $style = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,9 +58,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $all_max_width_value  = safecss_filter_attr( explode( ';', $all_max_width_value )[0] );
</span><span class="cx" style="display: block; padding: 0 10px">                $wide_max_width_value = safecss_filter_attr( explode( ';', $wide_max_width_value )[0] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style = '';
</del><span class="cx" style="display: block; padding: 0 10px">                 if ( $content_size || $wide_size ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $style  = "$selector > * {";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $style  = "$selector > :where(:not(.alignleft):not(.alignright)) {";
</ins><span class="cx" style="display: block; padding: 0 10px">                         $style .= 'max-width: ' . esc_html( $all_max_width_value ) . ';';
</span><span class="cx" style="display: block; padding: 0 10px">                        $style .= 'margin-left: auto !important;';
</span><span class="cx" style="display: block; padding: 0 10px">                        $style .= 'margin-right: auto !important;';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,12 +69,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $style .= "$selector .alignfull { max-width: none; }";
</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">-                $style .= "$selector .alignleft { float: left; margin-right: 2em; }";
-               $style .= "$selector .alignright { float: right; margin-left: 2em; }";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $style .= "$selector > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }";
+               $style .= "$selector > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }";
+               $style .= "$selector > .aligncenter { margin-left: auto !important; margin-right: auto !important; }";
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $has_block_gap_support ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $gap_style = $gap_value ? $gap_value : 'var( --wp--style--block-gap )';
-                       $style    .= "$selector > * { margin-top: 0; margin-bottom: 0; }";
-                       $style    .= "$selector > * + * { margin-top: $gap_style;  margin-bottom: 0; }";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( is_array( $gap_value ) ) {
+                               $gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
+                       }
+                       $gap_style = $gap_value && ! $should_skip_gap_serialization ? $gap_value : 'var( --wp--style--block-gap )';
+                       $style    .= "$selector > * { margin-block-start: 0; margin-block-end: 0; }";
+                       $style    .= "$selector > * + * { margin-block-start: $gap_style; margin-block-end: 0; }";
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        } elseif ( 'flex' === $layout_type ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $layout_orientation = isset( $layout['orientation'] ) ? $layout['orientation'] : 'horizontal';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -97,13 +101,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $style  = "$selector {";
</span><span class="cx" style="display: block; padding: 0 10px">                $style .= 'display: flex;';
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $has_block_gap_support ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $gap_style = $gap_value ? $gap_value : 'var( --wp--style--block-gap, 0.5em )';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( is_array( $gap_value ) ) {
+                               $gap_row    = isset( $gap_value['top'] ) ? $gap_value['top'] : '0.5em';
+                               $gap_column = isset( $gap_value['left'] ) ? $gap_value['left'] : '0.5em';
+                               $gap_value  = $gap_row === $gap_column ? $gap_row : $gap_row . ' ' . $gap_column;
+                       }
+                       $gap_style = $gap_value && ! $should_skip_gap_serialization ? $gap_value : 'var( --wp--style--block-gap, 0.5em )';
</ins><span class="cx" style="display: block; padding: 0 10px">                         $style    .= "gap: $gap_style;";
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        $style .= 'gap: 0.5em;';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $style .= "flex-wrap: $flex_wrap;";
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $style .= 'align-items: center;';
</del><span class="cx" style="display: block; padding: 0 10px">                 if ( 'horizontal' === $layout_orientation ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $style .= 'align-items: center;';
</span><span class="cx" style="display: block; padding: 0 10px">                        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,6 +127,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $style .= 'flex-direction: column;';
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $layout['justifyContent'] ) && array_key_exists( $layout['justifyContent'], $justify_content_options ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $style .= "align-items: {$justify_content_options[ $layout['justifyContent'] ]};";
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        } else {
+                               $style .= 'align-items: flex-start;';
</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">                $style .= '}';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,8 +174,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">        // Skip if gap value contains unsupported characters.
</span><span class="cx" style="display: block; padding: 0 10px">        // Regex for CSS value borrowed from `safecss_filter_attr`, and used here
</span><span class="cx" style="display: block; padding: 0 10px">        // because we only want to match against the value, not the CSS attribute.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $gap_value = preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
-       $style     = wp_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $gap_value ) ) {
+               foreach ( $gap_value as $key => $value ) {
+                       $gap_value[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
+               }
+       } else {
+               $gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
+       }
+
+       // If a block's block.json skips serialization for spacing or spacing.blockGap,
+       // don't apply the user-defined value to the styles.
+       $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
+       $style                         = wp_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization );
</ins><span class="cx" style="display: block; padding: 0 10px">         // This assumes the hook only applies to blocks with a single wrapper.
</span><span class="cx" style="display: block; padding: 0 10px">        // I think this is a reasonable limitation for that particular hook.
</span><span class="cx" style="display: block; padding: 0 10px">        $content = preg_replace(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -208,7 +229,6 @@
</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">        if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                'core/group' !== $block['blockName'] ||
</del><span class="cx" style="display: block; padding: 0 10px">                 WP_Theme_JSON_Resolver::theme_has_support() ||
</span><span class="cx" style="display: block; padding: 0 10px">                1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
</span><span class="cx" style="display: block; padding: 0 10px">                ( isset( $block['attrs']['layout']['type'] ) && 'default' !== $block['attrs']['layout']['type'] )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -230,4 +250,65 @@
</span><span class="cx" style="display: block; padding: 0 10px">        return $updated_content;
</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">-add_filter( 'render_block', 'wp_restore_group_inner_container', 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'render_block_core/group', 'wp_restore_group_inner_container', 10, 2 );
+
+/**
+ * For themes without theme.json file, make sure
+ * to restore the outer div for the aligned image block
+ * to avoid breaking styles relying on that div.
+ *
+ * @since 6.0.0
+ * @access private
+ *
+ * @param string $block_content Rendered block content.
+ * @param  array  $block        Block object.
+ * @return string Filtered block content.
+ */
+function wp_restore_image_outer_container( $block_content, $block ) {
+       $image_with_align = "
+/# 1) everything up to the class attribute contents
+(
+       ^\s*
+       <figure\b
+       [^>]*
+       \bclass=
+       [\"']
+)
+# 2) the class attribute contents
+(
+       [^\"']*
+       \bwp-block-image\b
+       [^\"']*
+       \b(?:alignleft|alignright|aligncenter)\b
+       [^\"']*
+)
+# 3) everything after the class attribute contents
+(
+       [\"']
+       [^>]*
+       >
+       .*
+       <\/figure>
+)/iUx";
+
+       if (
+               WP_Theme_JSON_Resolver::theme_has_support() ||
+               0 === preg_match( $image_with_align, $block_content, $matches )
+       ) {
+               return $block_content;
+       }
+
+       $wrapper_classnames = array( 'wp-block-image' );
+
+       // If the block has a classNames attribute these classnames need to be removed from the content and added back
+       // to the new wrapper div also.
+       if ( ! empty( $block['attrs']['className'] ) ) {
+               $wrapper_classnames = array_merge( $wrapper_classnames, explode( ' ', $block['attrs']['className'] ) );
+       }
+       $content_classnames          = explode( ' ', $matches[2] );
+       $filtered_content_classnames = array_diff( $content_classnames, $wrapper_classnames );
+
+       return '<div class="' . implode( ' ', $wrapper_classnames ) . '">' . $matches[1] . implode( ' ', $filtered_content_classnames ) . $matches[3] . '</div>';
+}
+
+add_filter( 'render_block_core/image', 'wp_restore_image_outer_container', 10, 2 );
</ins></span></pre></div>
<a id="trunktestsphpunittestsblocksupportslayoutphp"></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/layout.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/layout.php                               (rev 0)
+++ trunk/tests/phpunit/tests/block-supports/layout.php 2022-04-06 11:39:55 UTC (rev 53085)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,160 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Block supports tests for the layout.
+ *
+ * @package WordPress
+ * @subpackage Block Supports
+ * @since 6.0.0
+ */
+
+/**
+ * Tests for block supports related to layout.
+ *
+ * @since 6.0.0
+ *
+ * @group block-supports
+ */
+class Test_Block_Supports_Layout extends WP_UnitTestCase {
+       function set_up() {
+               parent::set_up();
+               $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 );
+
+               // Set up the new 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' ) );
+
+               $this->queries = array();
+               // Clear caches.
+               wp_clean_themes_cache();
+               unset( $GLOBALS['wp_themes'] );
+       }
+
+       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'] );
+               parent::tear_down();
+       }
+
+       function filter_set_theme_root() {
+               return $this->theme_root;
+       }
+
+       /**
+        * @ticket 55505
+        */
+       function test_outer_container_not_restored_for_non_aligned_image_block_with_non_themejson_theme() {
+               // The "default" theme doesn't have theme.json support.
+               switch_theme( 'default' );
+               $block         = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array(),
+               );
+               $block_content = '<figure class="wp-block-image size-full"><img src="/my-image.jpg"/></figure>';
+               $expected      = '<figure class="wp-block-image size-full"><img src="/my-image.jpg"/></figure>';
+
+               $this->assertSame( $expected, wp_restore_image_outer_container( $block_content, $block ) );
+       }
+
+       /**
+        * @ticket 55505
+        */
+       function test_outer_container_restored_for_aligned_image_block_with_non_themejson_theme() {
+               // The "default" theme doesn't have theme.json support.
+               switch_theme( 'default' );
+               $block         = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array(),
+               );
+               $block_content = '<figure class="wp-block-image alignright size-full"><img src="/my-image.jpg"/></figure>';
+               $expected      = '<div class="wp-block-image"><figure class="alignright size-full"><img src="/my-image.jpg"/></figure></div>';
+
+               $this->assertSame( $expected, wp_restore_image_outer_container( $block_content, $block ) );
+       }
+
+       /**
+        * @ticket 55505
+        *
+        * @dataProvider data_block_image_html_restored_outer_container
+        *
+        * @param string $block_image_html The block image HTML passed to `wp_restore_image_outer_container`.
+        * @param string $expected         The expected block image HTML.
+        */
+       function test_additional_styles_moved_to_restored_outer_container_for_aligned_image_block_with_non_themejson_theme( $block_image_html, $expected ) {
+               // The "default" theme doesn't have theme.json support.
+               switch_theme( 'default' );
+               $block = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array(
+                               'className' => 'is-style-round my-custom-classname',
+                       ),
+               );
+
+               $this->assertSame( $expected, wp_restore_image_outer_container( $block_image_html, $block ) );
+       }
+
+       /**
+        * Data provider for test_additional_styles_moved_to_restored_outer_container_for_aligned_image_block_with_non_themejson_theme().
+        *
+        * @return array {
+        *     @type array {
+        *         @type string $block_image_html The block image HTML passed to `wp_restore_image_outer_container`.
+        *         @type string $expected         The expected block image HTML.
+        *     }
+        * }
+        */
+       public function data_block_image_html_restored_outer_container() {
+               $expected = '<div class="wp-block-image is-style-round my-custom-classname"><figure class="alignright size-full"><img src="/my-image.jpg"/></figure></div>';
+
+               return array(
+                       array(
+                               '<figure class="wp-block-image alignright size-full is-style-round my-custom-classname"><img src="/my-image.jpg"/></figure>',
+                               $expected,
+                       ),
+                       array(
+                               '<figure class="is-style-round my-custom-classname wp-block-image alignright size-full"><img src="/my-image.jpg"/></figure>',
+                               $expected,
+                       ),
+                       array(
+                               '<figure class="wp-block-image is-style-round my-custom-classname alignright size-full"><img src="/my-image.jpg"/></figure>',
+                               $expected,
+                       ),
+                       array(
+                               '<figure class="is-style-round wp-block-image alignright my-custom-classname size-full"><img src="/my-image.jpg"/></figure>',
+                               $expected,
+                       ),
+                       array(
+                               '<figure style="color: red" class=\'is-style-round wp-block-image alignright my-custom-classname size-full\' data-random-tag=">"><img src="/my-image.jpg"/></figure>',
+                               '<div class="wp-block-image is-style-round my-custom-classname"><figure style="color: red" class=\'alignright size-full\' data-random-tag=">"><img src="/my-image.jpg"/></figure></div>',
+                       ),
+               );
+       }
+
+       /**
+        * @ticket 55505
+        */
+       function test_outer_container_not_restored_for_aligned_image_block_with_themejson_theme() {
+               switch_theme( 'block-theme' );
+               $block         = array(
+                       'blockName' => 'core/image',
+                       'attrs'     => array(
+                               'className' => 'is-style-round my-custom-classname',
+                       ),
+               );
+               $block_content = '<figure class="wp-block-image alignright size-full is-style-round my-custom-classname"><img src="/my-image.jpg"/></figure>';
+               $expected      = '<figure class="wp-block-image alignright size-full is-style-round my-custom-classname"><img src="/my-image.jpg"/></figure>';
+
+               $this->assertSame( $expected, wp_restore_image_outer_container( $block_content, $block ) );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-supports/layout.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></div>

</body>
</html>