<!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>[60038] trunk: Editor: Fix layout support classes to be generated with a stable ID.</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/60038">60038</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/60038","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>joemcgill</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2025-03-18 12:41:31 +0000 (Tue, 18 Mar 2025)</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: Fix layout support classes to be generated with a stable ID.

This fixes a bug reported in https://github.com/WordPress/gutenberg/issues/67308 related to the Interactivity API's client-side navigation feature by replacing the incrementally generated IDs with stable hashes derived from the block's layout style definition.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportslayoutphp">trunk/src/wp-includes/block-supports/layout.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__columnsserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html</a></li>
<li><a href="#trunktestsphpunitdatablocksfixturescore__columns__deprecatedserverhtml">trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html</a></li>
<li><a href="#trunktestsphpunittestsblocksupportslayoutphp">trunk/tests/phpunit/tests/block-supports/layout.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfunctionswpUniqueIdFromValuesphp">trunk/tests/phpunit/tests/functions/wpUniqueIdFromValues.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   2025-03-18 12:28:17 UTC (rev 60037)
+++ trunk/src/wp-includes/block-supports/layout.php     2025-03-18 12:41:31 UTC (rev 60038)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -580,7 +580,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Child layout specific logic.
</span><span class="cx" style="display: block; padding: 0 10px">        if ( $child_layout ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $container_content_class   = wp_unique_prefixed_id( 'wp-container-content-' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * Generates a unique class for child block layout styles.
+                *
+                * To ensure consistent class generation across different page renders,
+                * only properties that affect layout styling are used. These properties
+                * come from `$block['attrs']['style']['layout']` and `$block['parentLayout']`.
+                *
+                * As long as these properties coincide, the generated class will be the same.
+                */
+               $container_content_class = wp_unique_id_from_values(
+                       array(
+                               'layout'       => array_intersect_key(
+                                       $block['attrs']['style']['layout'] ?? array(),
+                                       array_flip(
+                                               array( 'selfStretch', 'flexSize', 'columnStart', 'columnSpan', 'rowStart', 'rowSpan' )
+                                       )
+                               ),
+                               'parentLayout' => array_intersect_key(
+                                       $block['parentLayout'] ?? array(),
+                                       array_flip(
+                                               array( 'minimumColumnWidth', 'columnCount' )
+                                       )
+                               ),
+                       ),
+                       'wp-container-content-'
+               );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $child_layout_declarations = array();
</span><span class="cx" style="display: block; padding: 0 10px">                $child_layout_styles       = array();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -706,16 +732,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $class_names        = array();
</span><span class="cx" style="display: block; padding: 0 10px">        $layout_definitions = wp_get_layout_definitions();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /*
-        * Uses an incremental ID that is independent per prefix to make sure that
-        * rendering different numbers of blocks doesn't affect the IDs of other
-        * blocks. Makes the CSS class names stable across paginations
-        * for features like the enhanced pagination of the Query block.
-        */
-       $container_class = wp_unique_prefixed_id(
-               'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-'
-       );
-
</del><span class="cx" style="display: block; padding: 0 10px">         // Set the correct layout type for blocks using legacy content width.
</span><span class="cx" style="display: block; padding: 0 10px">        if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $used_layout['type'] = 'constrained';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -806,6 +822,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        : null;
</span><span class="cx" style="display: block; padding: 0 10px">                $has_block_gap_support = isset( $block_gap );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                /*
+                * Generates a unique ID based on all the data required to obtain the
+                * corresponding layout style. Keeps the CSS class names the same
+                * even for different blocks on different places, as long as they have
+                * the same layout definition. Makes the CSS class names stable across
+                * paginations for features like the enhanced pagination of the Query block.
+                */
+               $container_class = wp_unique_id_from_values(
+                       array(
+                               $used_layout,
+                               $has_block_gap_support,
+                               $gap_value,
+                               $should_skip_gap_serialization,
+                               $fallback_gap_value,
+                               $block_spacing,
+                       ),
+                       'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-'
+               );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $style = wp_get_layout_style(
</span><span class="cx" style="display: block; padding: 0 10px">                        ".$container_class",
</span><span class="cx" style="display: block; padding: 0 10px">                        $used_layout,
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></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/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php       2025-03-18 12:28:17 UTC (rev 60037)
+++ trunk/src/wp-includes/functions.php 2025-03-18 12:41:31 UTC (rev 60038)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9174,3 +9174,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return hash_equals( $hash, wp_fast_hash( $message ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Generates a unique ID based on the structure and values of a given array.
+ *
+ * This function serializes the array into a JSON string and generates a hash
+ * that serves as a unique identifier. Optionally, a prefix can be added to
+ * the generated ID for context or categorization.
+ *
+ * @since 6.8.0
+ *
+ * @param array  $data   The input array to generate an ID from.
+ * @param string $prefix Optional. A prefix to prepend to the generated ID. Default ''.
+ *
+ * @return string The generated unique ID for the array.
+ */
+function wp_unique_id_from_values( array $data, string $prefix = '' ): string {
+       if ( empty( $data ) ) {
+               _doing_it_wrong(
+                       __FUNCTION__,
+                       sprintf(
+                               __( 'The $data argument must not be empty.' ),
+                               gettype( $data )
+                       ),
+                       '6.8.0'
+               );
+       }
+       $serialized = wp_json_encode( $data );
+       $hash       = substr( md5( $serialized ), 0, 8 );
+       return $prefix . $hash;
+}
</ins></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__columnsserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html        2025-03-18 12:28:17 UTC (rev 60037)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__columns.server.html  2025-03-18 12:41:31 UTC (rev 60038)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<div class="wp-block-columns has-3-columns is-layout-flex wp-container-1 wp-block-columns-is-layout-flex">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="wp-block-columns has-3-columns is-layout-flex wp-container-1d6595d7 wp-block-columns-is-layout-flex">
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><span class="cx" style="display: block; padding: 0 10px">        <div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
</span><span class="cx" style="display: block; padding: 0 10px">                
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksfixturescore__columns__deprecatedserverhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html    2025-03-18 12:28:17 UTC (rev 60037)
+++ trunk/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html      2025-03-18 12:41:31 UTC (rev 60038)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<div class="wp-block-columns has-3-columns is-layout-flex wp-container-1 wp-block-columns-is-layout-flex">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="wp-block-columns has-3-columns is-layout-flex wp-container-1d6595d7 wp-block-columns-is-layout-flex">
</ins><span class="cx" style="display: block; padding: 0 10px">         
</span><span class="cx" style="display: block; padding: 0 10px">        <p class="layout-column-1">Column One, Paragraph One</p>
</span><span class="cx" style="display: block; padding: 0 10px">        
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportslayoutphp"></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/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       2025-03-18 12:28:17 UTC (rev 60037)
+++ trunk/tests/phpunit/tests/block-supports/layout.php 2025-03-18 12:41:31 UTC (rev 60038)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,8 +272,48 @@
</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">-                                'expected_output' => '<p class="wp-container-content-1">Some text.</p>', // The generated classname number assumes `wp_unique_prefixed_id( 'wp-container-content-' )` will not have run previously in this test.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'expected_output' => '<p class="wp-container-content-b7aa651c">Some text.</p>',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'single wrapper block layout with flex type'   => array(
+                               'args'            => array(
+                                       'block_content' => '<div class="wp-block-group"></div>',
+                                       'block'         => array(
+                                               'blockName'    => 'core/group',
+                                               'attrs'        => array(
+                                                       'layout' => array(
+                                                               'type'        => 'flex',
+                                                               'orientation' => 'horizontal',
+                                                               'flexWrap'    => 'nowrap',
+                                                       ),
+                                               ),
+                                               'innerBlocks'  => array(),
+                                               'innerHTML'    => '<div class="wp-block-group"></div>',
+                                               'innerContent' => array(
+                                                       '<div class="wp-block-group"></div>',
+                                               ),
+                                       ),
+                               ),
+                               'expected_output' => '<div class="wp-block-group is-horizontal is-nowrap is-layout-flex wp-container-core-group-is-layout-67f0b8e2 wp-block-group-is-layout-flex"></div>',
+                       ),
+                       'single wrapper block layout with grid type'   => array(
+                               'args'            => array(
+                                       'block_content' => '<div class="wp-block-group"></div>',
+                                       'block'         => array(
+                                               'blockName'    => 'core/group',
+                                               'attrs'        => array(
+                                                       'layout' => array(
+                                                               'type' => 'grid',
+                                                       ),
+                                               ),
+                                               'innerBlocks'  => array(),
+                                               'innerHTML'    => '<div class="wp-block-group"></div>',
+                                               'innerContent' => array(
+                                                       '<div class="wp-block-group"></div>',
+                                               ),
+                                       ),
+                               ),
+                               'expected_output' => '<div class="wp-block-group is-layout-grid wp-container-core-group-is-layout-9649a0d9 wp-block-group-is-layout-grid"></div>',
+                       ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'skip classname output if block does not support layout and there are no child layout classes to be output' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'args'            => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'block_content' => '<p>A paragraph</p>',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -463,4 +503,138 @@
</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">+
+       /**
+        * Check that wp_render_layout_support_flag() renders consistent hashes
+        * for the container class when the relevant layout properties are the same.
+        *
+        * @dataProvider data_layout_support_flag_renders_consistent_container_hash
+        *
+        * @covers ::wp_render_layout_support_flag
+        *
+        * @param array $block_attrs     Dataset to test.
+        * @param array $expected_class  Class generated for the passed dataset.
+        */
+       public function test_layout_support_flag_renders_consistent_container_hash( $block_attrs, $expected_class ) {
+               switch_theme( 'default' );
+
+               $block_content = '<div class="wp-block-group"></div>';
+               $block         = array(
+                       'blockName'    => 'core/group',
+                       'innerBlocks'  => array(),
+                       'innerHTML'    => '<div class="wp-block-group"></div>',
+                       'innerContent' => array(
+                               '<div class="wp-block-group"></div>',
+                       ),
+                       'attrs'        => $block_attrs,
+               );
+
+               /*
+                * The `appearance-tools` theme support is temporarily added to ensure
+                * that the block gap support is enabled during rendering, which is
+                * necessary to compute styles for layouts with block gap values.
+                */
+               add_theme_support( 'appearance-tools' );
+               $output = wp_render_layout_support_flag( $block_content, $block );
+               remove_theme_support( 'appearance-tools' );
+
+               // Process the output and look for the expected class in the first rendered element.
+               $processor = new WP_HTML_Tag_Processor( $output );
+               $processor->next_tag();
+
+               $this->assertTrue(
+                       $processor->has_class( $expected_class ),
+                       "Expected class '$expected_class' not found in the rendered output, probably because of a different hash."
+               );
+       }
+
+       /**
+        * Data provider for test_layout_support_flag_renders_consistent_container_hash.
+        *
+        * @return array
+        */
+       public function data_layout_support_flag_renders_consistent_container_hash() {
+               return array(
+                       'default type block gap 12px'      => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type' => 'default',
+                                       ),
+                                       'style'  => array(
+                                               'spacing' => array(
+                                                       'blockGap' => '12px',
+                                               ),
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-c5c7d83f',
+                       ),
+                       'default type block gap 24px'      => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type' => 'default',
+                                       ),
+                                       'style'  => array(
+                                               'spacing' => array(
+                                                       'blockGap' => '24px',
+                                               ),
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-634f0b9d',
+                       ),
+                       'constrained type justified left'  => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type'           => 'constrained',
+                                               'justifyContent' => 'left',
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-12dd3699',
+                       ),
+                       'constrained type justified right' => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type'           => 'constrained',
+                                               'justifyContent' => 'right',
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-f1f2ed93',
+                       ),
+                       'flex type horizontal'             => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type'        => 'flex',
+                                               'orientation' => 'horizontal',
+                                               'flexWrap'    => 'nowrap',
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-2487dcaa',
+                       ),
+                       'flex type vertical'               => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type'        => 'flex',
+                                               'orientation' => 'vertical',
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-fe9cc265',
+                       ),
+                       'grid type'                        => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type' => 'grid',
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-478b6e6b',
+                       ),
+                       'grid type 3 columns'              => array(
+                               'block_attributes' => array(
+                                       'layout' => array(
+                                               'type'        => 'grid',
+                                               'columnCount' => 3,
+                                       ),
+                               ),
+                               'expected_class'   => 'wp-container-core-group-is-layout-d3b710ac',
+                       ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsfunctionswpUniqueIdFromValuesphp"></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/functions/wpUniqueIdFromValues.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/functions/wpUniqueIdFromValues.php                              (rev 0)
+++ trunk/tests/phpunit/tests/functions/wpUniqueIdFromValues.php        2025-03-18 12:41:31 UTC (rev 60038)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,172 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test cases for the `wp_unique_id_from_values()` function.
+ *
+ * @package WordPress\UnitTests
+ *
+ * @since 6.8.0
+ *
+ * @group functions.php
+ * @covers ::wp_unique_id_from_values
+ */
+class Tests_Functions_WpUniqueIdFromValues extends WP_UnitTestCase {
+
+       /**
+        * Test that the function returns consistent ids for the passed params.
+        *
+        * @ticket 62985
+        *
+        * @dataProvider data_wp_unique_id_from_values
+        *
+        * @since 6.8.0
+        */
+       public function test_wp_unique_id_from_values( $expected, $data, $prefix ) {
+               $output1 = wp_unique_id_from_values( $data );
+               $output2 = wp_unique_id_from_values( $data, $prefix );
+               $this->assertSame( $expected, $output1 );
+               $this->assertSame( $prefix . $expected, $output2 );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[]
+        */
+       public function data_wp_unique_id_from_values() {
+               return array(
+                       'string'          => array(
+                               'expected' => '469f5989',
+                               'data'     => array(
+                                       'value' => 'text',
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'integer'         => array(
+                               'expected' => 'b2f0842e',
+                               'data'     => array(
+                                       'value' => 123,
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'float'           => array(
+                               'expected' => 'a756f54d',
+                               'data'     => array(
+                                       'value' => 1.23,
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'boolean'         => array(
+                               'expected' => 'bdae8be3',
+                               'data'     => array(
+                                       'value' => true,
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'object'          => array(
+                               'expected' => '477bd670',
+                               'data'     => array(
+                                       'value' => new StdClass(),
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'null'            => array(
+                               'expected' => 'a860dd95',
+                               'data'     => array(
+                                       'value' => null,
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'multiple values' => array(
+                               'expected' => 'ef258a5d',
+                               'data'     => array(
+                                       'value1' => 'text',
+                                       'value2' => 123,
+                                       'value3' => 1.23,
+                                       'value4' => true,
+                                       'value5' => new StdClass(),
+                                       'value6' => null,
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+                       'nested arrays'   => array(
+                               'expected' => '4345cae5',
+                               'data'     => array(
+                                       'list1' => array(
+                                               'value1' => 'text',
+                                               'value2' => 123,
+                                               'value3' => 1.23,
+                                       ),
+                                       'list2' => array(
+                                               'value4' => true,
+                                               'value5' => new StdClass(),
+                                               'value6' => null,
+                                       ),
+                               ),
+                               'prefix'   => 'my-prefix-',
+                       ),
+               );
+       }
+
+       /**
+        * Test that passing an empty array is not allowed.
+        *
+        * @ticket 62985
+        *
+        * @expectedIncorrectUsage wp_unique_id_from_values
+        *
+        * @since 6.8.0
+        */
+       public function test_wp_unique_id_from_values_empty_array() {
+               wp_unique_id_from_values( array(), 'my-prefix-' );
+       }
+
+       /**
+        * Test that passing non-array data throws an error.
+        *
+        * @ticket 62985
+        *
+        * @dataProvider data_wp_unique_id_from_values_invalid_data
+        *
+        * @since 6.8.0
+        */
+       public function test_wp_unique_id_from_values_invalid_data( $data, $prefix ) {
+               $this->expectException( TypeError::class );
+
+               wp_unique_id_from_values( $data, $prefix );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[]
+        */
+       public function data_wp_unique_id_from_values_invalid_data() {
+               return array(
+                       'string'  => array(
+                               'data'   => 'text',
+                               'prefix' => '',
+                       ),
+                       'integer' => array(
+                               'data'   => 123,
+                               'prefix' => '',
+                       ),
+                       'float'   => array(
+                               'data'   => 1.23,
+                               'prefix' => '',
+                       ),
+                       'boolean' => array(
+                               'data'   => true,
+                               'prefix' => '',
+                       ),
+                       'object'  => array(
+                               'data'   => new StdClass(),
+                               'prefix' => '',
+                       ),
+                       'null'    => array(
+                               'data'   => null,
+                               'prefix' => '',
+                       ),
+               );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/functions/wpUniqueIdFromValues.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>