<!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>[54272] trunk: Editor: Introduce spacing presets in global style properties.</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/54272">54272</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/54272","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>audrasjb</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-09-21 11:41:44 +0000 (Wed, 21 Sep 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: Introduce spacing presets in global style properties.

This changeset is part of the Gutenberg changes merged into WP 6.1. It adds spacing presets support in global style properties.

Follow-up to <a href="https://core.trac.wordpress.org/changeset/54211">[54211]</a>.

Props glendaviesnz, andrewserong, costdev, audrasjb, mukesh27.
See <a href="https://core.trac.wordpress.org/ticket/56467">#56467</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblockeditorphp">trunk/src/wp-includes/block-editor.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonresolverphp">trunk/src/wp-includes/class-wp-theme-json-resolver.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunksrcwpincludesthemei18njson">trunk/src/wp-includes/theme-i18n.json</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonphp">trunk/tests/phpunit/tests/theme/wpThemeJson.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblockeditorphp"></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-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-editor.php    2022-09-21 05:27:12 UTC (rev 54271)
+++ trunk/src/wp-includes/block-editor.php      2022-09-21 11:41:44 UTC (rev 54272)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -488,7 +488,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                unset( $editor_settings['__experimentalFeatures']['spacing']['padding'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px">        if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $editor_settings['disableCustomSpacingSizes'] = ! $editor_ettings['__experimentalFeatures']['spacing']['customSpacingSize'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $editor_settings['disableCustomSpacingSizes'] = ! $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'];
</ins><span class="cx" style="display: block; padding: 0 10px">                 unset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonresolverphp"></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-resolver.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-resolver.php    2022-09-21 05:27:12 UTC (rev 54271)
+++ trunk/src/wp-includes/class-wp-theme-json-resolver.php      2022-09-21 11:41:44 UTC (rev 54272)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -470,7 +470,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 user data, removed the `$settings` parameter,
</span><span class="cx" style="display: block; padding: 0 10px">         *              added the `$origin` parameter.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 6.1.0 Added block data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 6.1.0 Added block data and generation of spacingSizes array.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $origin Optional. To what level should we merge data.
</span><span class="cx" style="display: block; padding: 0 10px">         *                       Valid values are 'theme' or 'custom'. Default 'custom'.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -490,6 +490,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $result->merge( static::get_user_data() );
</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">+                // Generate the default spacingSizes array based on the merged spacingScale settings.
+               $result->set_spacing_sizes();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return $result;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme-json.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json.php     2022-09-21 05:27:12 UTC (rev 54271)
+++ trunk/src/wp-includes/class-wp-theme-json.php       2022-09-21 11:41:44 UTC (rev 54272)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -164,6 +164,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'classes'           => array( '.has-$slug-font-family' => 'font-family' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'properties'        => array( 'font-family' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                array(
+                       'path'              => array( 'spacing', 'spacingSizes' ),
+                       'prevent_override'  => false,
+                       'use_default_names' => true,
+                       'value_key'         => 'size',
+                       'css_vars'          => '--wp--preset--spacing--$slug',
+                       'classes'           => array(),
+                       'properties'        => array( 'padding', 'margin' ),
+               ),
+               array(
+                       'path'              => array( 'spacing', 'spacingScale' ),
+                       'prevent_override'  => false,
+                       'use_default_names' => true,
+                       'value_key'         => 'size',
+                       'css_vars'          => '--wp--preset--spacing--$slug',
+                       'classes'           => array(),
+                       'properties'        => array( 'padding', 'margin' ),
+               ),
</ins><span class="cx" style="display: block; padding: 0 10px">         );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -307,10 +325,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'wideSize'    => null,
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><span class="cx" style="display: block; padding: 0 10px">                'spacing'                       => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'blockGap' => null,
-                       'margin'   => null,
-                       'padding'  => null,
-                       'units'    => null,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'customSpacingSize' => null,
+                       'spacingSizes'      => null,
+                       'spacingScale'      => null,
+                       'blockGap'          => null,
+                       'margin'            => null,
+                       'padding'           => null,
+                       'units'             => null,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'typography'                    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'customFontSize' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2890,4 +2911,122 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return $output;
</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">+        /**
+        * Sets the spacingSizes array based on the spacingScale values from theme.json.
+        *
+        * @since 6.1.0
+        *
+        * @return null|void
+        */
+       public function set_spacing_sizes() {
+               $spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() );
+
+               if ( ! is_numeric( $spacing_scale['steps'] )
+                       || ! isset( $spacing_scale['mediumStep'] )
+                       || ! isset( $spacing_scale['unit'] )
+                       || ! isset( $spacing_scale['operator'] )
+                       || ! isset( $spacing_scale['increment'] )
+                       || ! isset( $spacing_scale['steps'] )
+                       || ! is_numeric( $spacing_scale['increment'] )
+                       || ! is_numeric( $spacing_scale['mediumStep'] )
+                       || ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ) {
+                       if ( ! empty( $spacing_scale ) ) {
+                               trigger_error( __( 'Some of the theme.json settings.spacing.spacingScale values are invalid' ), E_USER_NOTICE );
+                       }
+                       return null;
+               }
+
+               // If theme authors want to prevent the generation of the core spacing scale they can set their theme.json spacingScale.steps to 0.
+               if ( 0 === $spacing_scale['steps'] ) {
+                       return null;
+               }
+
+               $unit            = '%' === $spacing_scale['unit'] ? '%' : sanitize_title( $spacing_scale['unit'] );
+               $current_step    = $spacing_scale['mediumStep'];
+               $steps_mid_point = round( $spacing_scale['steps'] / 2, 0 );
+               $x_small_count   = null;
+               $below_sizes     = array();
+               $slug            = 40;
+               $remainder       = 0;
+
+               for ( $below_midpoint_count = $steps_mid_point - 1; $spacing_scale['steps'] > 1 && $slug > 0 && $below_midpoint_count > 0; $below_midpoint_count-- ) {
+                       if ( '+' === $spacing_scale['operator'] ) {
+                               $current_step -= $spacing_scale['increment'];
+                       } elseif ( $spacing_scale['increment'] > 1 ) {
+                               $current_step /= $spacing_scale['increment'];
+                       } else {
+                               $current_step *= $spacing_scale['increment'];
+                       }
+
+                       if ( $current_step <= 0 ) {
+                               $remainder = $below_midpoint_count;
+                               break;
+                       }
+
+                       $below_sizes[] = array(
+                               /* translators: %s: Digit to indicate multiple of sizing, eg. 2X-Small. */
+                               'name' => $below_midpoint_count === $steps_mid_point - 1 ? __( 'Small' ) : sprintf( __( '%sX-Small' ), (string) $x_small_count ),
+                               'slug' => (string) $slug,
+                               'size' => round( $current_step, 2 ) . $unit,
+                       );
+
+                       if ( $below_midpoint_count === $steps_mid_point - 2 ) {
+                               $x_small_count = 2;
+                       }
+
+                       if ( $below_midpoint_count < $steps_mid_point - 2 ) {
+                               $x_small_count++;
+                       }
+
+                       $slug -= 10;
+               }
+
+               $below_sizes = array_reverse( $below_sizes );
+
+               $below_sizes[] = array(
+                       'name' => __( 'Medium' ),
+                       'slug' => '50',
+                       'size' => $spacing_scale['mediumStep'] . $unit,
+               );
+
+               $current_step  = $spacing_scale['mediumStep'];
+               $x_large_count = null;
+               $above_sizes   = array();
+               $slug          = 60;
+               $steps_above   = ( $spacing_scale['steps'] - $steps_mid_point ) + $remainder;
+
+               for ( $above_midpoint_count = 0; $above_midpoint_count < $steps_above; $above_midpoint_count++ ) {
+                       $current_step = '+' === $spacing_scale['operator']
+                               ? $current_step + $spacing_scale['increment']
+                               : ( $spacing_scale['increment'] >= 1 ? $current_step * $spacing_scale['increment'] : $current_step / $spacing_scale['increment'] );
+
+                       $above_sizes[] = array(
+                               /* translators: %s: Digit to indicate multiple of sizing, eg. 2X-Large. */
+                               'name' => 0 === $above_midpoint_count ? __( 'Large' ) : sprintf( __( '%sX-Large' ), (string) $x_large_count ),
+                               'slug' => (string) $slug,
+                               'size' => round( $current_step, 2 ) . $unit,
+                       );
+
+                       if ( 1 === $above_midpoint_count ) {
+                               $x_large_count = 2;
+                       }
+
+                       if ( $above_midpoint_count > 1 ) {
+                               $x_large_count++;
+                       }
+
+                       $slug += 10;
+               }
+
+               $spacing_sizes = array_merge( $below_sizes, $above_sizes );
+
+               // If there are 7 or less steps in the scale revert to numbers for labels instead of t-shirt sizes.
+               if ( $spacing_scale['steps'] <= 7 ) {
+                       for ( $spacing_sizes_count = 0; $spacing_sizes_count < count( $spacing_sizes ); $spacing_sizes_count++ ) {
+                               $spacing_sizes[ $spacing_sizes_count ]['name'] = (string) ( $spacing_sizes_count + 1 );
+                       }
+               }
+
+               _wp_array_set( $this->theme_json, array( 'settings', 'spacing', 'spacingSizes', 'default' ), $spacing_sizes );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesthemei18njson"></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/theme-i18n.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme-i18n.json     2022-09-21 05:27:12 UTC (rev 54271)
+++ trunk/src/wp-includes/theme-i18n.json       2022-09-21 11:41:44 UTC (rev 54272)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,6 +30,13 @@
</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">+                "spacing": {
+                       "spacingSizes": [
+                               {
+                                       "name": "Space size name"
+                               }
+                       ]
+               },
</ins><span class="cx" style="display: block; padding: 0 10px">                 "blocks": {
</span><span class="cx" style="display: block; padding: 0 10px">                        "*": {
</span><span class="cx" style="display: block; padding: 0 10px">                                "typography": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,6 +62,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                        "name": "Gradient name"
</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">+                                },
+                               "spacing": {
+                                       "spacingSizes": [
+                                               {
+                                                       "name": "Space size name"
+                                               }
+                                       ]
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span></span></pre></div>
<a id="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   2022-09-21 05:27:12 UTC (rev 54271)
+++ trunk/tests/phpunit/tests/theme/wpThemeJson.php     2022-09-21 11:41:44 UTC (rev 54272)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3493,4 +3493,385 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $style_rules = $theme_json->get_styles_for_block( $metadata );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $expected, $root_rules . $style_rules );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Tests generating the spacing presets array based on the spacing scale provided.
+        *
+        * @ticket 56467
+        *
+        * @dataProvider data_generate_spacing_scale_fixtures
+        *
+        * @param array $spacing_scale   Example spacing scale definitions from the data provider.
+        * @param array $expected_output Expected output from data provider.
+        */
+       function test_should_set_spacing_sizes( $spacing_scale, $expected_output ) {
+               $theme_json = new WP_Theme_JSON(
+                       array(
+                               'version'  => 2,
+                               'settings' => array(
+                                       'spacing' => array(
+                                               'spacingScale' => $spacing_scale,
+                                       ),
+                               ),
+                       )
+               );
+
+               $theme_json->set_spacing_sizes();
+               $this->assertSame( $expected_output, _wp_array_get( $theme_json->get_raw_data(), array( 'settings', 'spacing', 'spacingSizes', 'default' ) ) );
+       }
+
+       /**
+        * Data provider for spacing scale tests.
+        *
+        * @ticket 56467
+        *
+        * @return array
+        */
+       function data_generate_spacing_scale_fixtures() {
+               return array(
+                       'only one value when single step in spacing scale' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 1,
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '50',
+                                               'size' => '4rem',
+                                       ),
+                               ),
+                       ),
+                       'one step above medium when two steps in spacing scale' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 2,
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '50',
+                                               'size' => '4rem',
+                                       ),
+                                       array(
+                                               'name' => '2',
+                                               'slug' => '60',
+                                               'size' => '5.5rem',
+                                       ),
+                               ),
+                       ),
+                       'one step above medium and one below when three steps in spacing scale' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 3,
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '40',
+                                               'size' => '2.5rem',
+                                       ),
+                                       array(
+                                               'name' => '2',
+                                               'slug' => '50',
+                                               'size' => '4rem',
+                                       ),
+                                       array(
+                                               'name' => '3',
+                                               'slug' => '60',
+                                               'size' => '5.5rem',
+                                       ),
+                               ),
+                       ),
+                       'extra step added above medium when an even number of steps > 2 specified' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 4,
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '40',
+                                               'size' => '2.5rem',
+                                       ),
+                                       array(
+                                               'name' => '2',
+                                               'slug' => '50',
+                                               'size' => '4rem',
+                                       ),
+                                       array(
+                                               'name' => '3',
+                                               'slug' => '60',
+                                               'size' => '5.5rem',
+                                       ),
+                                       array(
+                                               'name' => '4',
+                                               'slug' => '70',
+                                               'size' => '7rem',
+                                       ),
+                               ),
+                       ),
+                       'extra steps above medium if bottom end will go below zero' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 2.5,
+                                       'steps'      => 5,
+                                       'mediumStep' => 5,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '40',
+                                               'size' => '2.5rem',
+                                       ),
+                                       array(
+                                               'name' => '2',
+                                               'slug' => '50',
+                                               'size' => '5rem',
+                                       ),
+                                       array(
+                                               'name' => '3',
+                                               'slug' => '60',
+                                               'size' => '7.5rem',
+                                       ),
+                                       array(
+                                               'name' => '4',
+                                               'slug' => '70',
+                                               'size' => '10rem',
+                                       ),
+                                       array(
+                                               'name' => '5',
+                                               'slug' => '80',
+                                               'size' => '12.5rem',
+                                       ),
+                               ),
+                       ),
+                       'multiplier correctly calculated above and below medium' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '*',
+                                       'increment'  => 1.5,
+                                       'steps'      => 5,
+                                       'mediumStep' => 1.5,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '30',
+                                               'size' => '0.67rem',
+                                       ),
+                                       array(
+                                               'name' => '2',
+                                               'slug' => '40',
+                                               'size' => '1rem',
+                                       ),
+                                       array(
+                                               'name' => '3',
+                                               'slug' => '50',
+                                               'size' => '1.5rem',
+                                       ),
+                                       array(
+                                               'name' => '4',
+                                               'slug' => '60',
+                                               'size' => '2.25rem',
+                                       ),
+                                       array(
+                                               'name' => '5',
+                                               'slug' => '70',
+                                               'size' => '3.38rem',
+                                       ),
+                               ),
+                       ),
+                       'increment < 1 combined showing * operator acting as divisor above and below medium' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '*',
+                                       'increment'  => 0.25,
+                                       'steps'      => 5,
+                                       'mediumStep' => 1.5,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '1',
+                                               'slug' => '30',
+                                               'size' => '0.09rem',
+                                       ),
+                                       array(
+                                               'name' => '2',
+                                               'slug' => '40',
+                                               'size' => '0.38rem',
+                                       ),
+                                       array(
+                                               'name' => '3',
+                                               'slug' => '50',
+                                               'size' => '1.5rem',
+                                       ),
+                                       array(
+                                               'name' => '4',
+                                               'slug' => '60',
+                                               'size' => '6rem',
+                                       ),
+                                       array(
+                                               'name' => '5',
+                                               'slug' => '70',
+                                               'size' => '24rem',
+                                       ),
+                               ),
+                       ),
+                       't-shirt sizing used if more than 7 steps in scale' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '*',
+                                       'increment'  => 1.5,
+                                       'steps'      => 8,
+                                       'mediumStep' => 1.5,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => array(
+                                       array(
+                                               'name' => '2X-Small',
+                                               'slug' => '20',
+                                               'size' => '0.44rem',
+                                       ),
+                                       array(
+                                               'name' => 'X-Small',
+                                               'slug' => '30',
+                                               'size' => '0.67rem',
+                                       ),
+                                       array(
+                                               'name' => 'Small',
+                                               'slug' => '40',
+                                               'size' => '1rem',
+                                       ),
+                                       array(
+                                               'name' => 'Medium',
+                                               'slug' => '50',
+                                               'size' => '1.5rem',
+                                       ),
+                                       array(
+                                               'name' => 'Large',
+                                               'slug' => '60',
+                                               'size' => '2.25rem',
+                                       ),
+                                       array(
+                                               'name' => 'X-Large',
+                                               'slug' => '70',
+                                               'size' => '3.38rem',
+                                       ),
+                                       array(
+                                               'name' => '2X-Large',
+                                               'slug' => '80',
+                                               'size' => '5.06rem',
+                                       ),
+                                       array(
+                                               'name' => '3X-Large',
+                                               'slug' => '90',
+                                               'size' => '7.59rem',
+                                       ),
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * Tests generating the spacing presets array based on the spacing scale provided.
+        *
+        * @ticket 56467
+        *
+        * @dataProvider data_set_spacing_sizes_when_invalid
+        *
+        * @param array $spacing_scale   Example spacing scale definitions from the data provider.
+        * @param array $expected_output Expected output from data provider.
+        */
+       public function test_set_spacing_sizes_should_detect_invalid_spacing_scale( $spacing_scale, $expected_output ) {
+               $this->expectNotice();
+               $this->expectNoticeMessage( 'Some of the theme.json settings.spacing.spacingScale values are invalid' );
+
+               $theme_json = new WP_Theme_JSON(
+                       array(
+                               'version'  => 2,
+                               'settings' => array(
+                                       'spacing' => array(
+                                               'spacingScale' => $spacing_scale,
+                                       ),
+                               ),
+                       )
+               );
+
+               $theme_json->set_spacing_sizes();
+               $this->assertSame( $expected_output, _wp_array_get( $theme_json->get_raw_data(), array( 'settings', 'spacing', 'spacingSizes', 'default' ) ) );
+       }
+
+       /**
+        * Data provider for spacing scale tests.
+        *
+        * @ticket 56467
+        *
+        * @return array
+        */
+       function data_set_spacing_sizes_when_invalid() {
+               return array(
+                       'missing operator value'  => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '',
+                                       'increment'  => 1.5,
+                                       'steps'      => 1,
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => null,
+                       ),
+                       'non numeric increment'   => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 'add two to previous value',
+                                       'steps'      => 1,
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => null,
+                       ),
+                       'non numeric steps'       => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 'spiral staircase preferred',
+                                       'mediumStep' => 4,
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => null,
+                       ),
+                       'non numeric medium step' => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 5,
+                                       'mediumStep' => 'That which is just right',
+                                       'unit'       => 'rem',
+                               ),
+                               'expected_output' => null,
+                       ),
+                       'missing unit value'      => array(
+                               'spacing_scale'   => array(
+                                       'operator'   => '+',
+                                       'increment'  => 1.5,
+                                       'steps'      => 5,
+                                       'mediumStep' => 4,
+                               ),
+                               'expected_output' => null,
+                       ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>