<!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>[56058] trunk: Editor: refactor and stabilize selectors API.</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/56058">56058</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/56058","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>isabel_brison</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-27 08:46:45 +0000 (Tue, 27 Jun 2023)</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: refactor and stabilize selectors API.

Restructures the block.json selectors API by moving `__experimentalSelector` props into their own config, stabilizing the selectors API, and enabling more flexible styling options.

Props ramonopoly, spacedmonkey, aaronrobertshaw, onemaggie.
Fixes <a href="https://core.trac.wordpress.org/ticket/58586">#58586</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportssettingsphp">trunk/src/wp-includes/block-supports/settings.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunksrcwpincludesglobalstylesandsettingsphp">trunk/src/wp-includes/global-styles-and-settings.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunitteststhemewpGetBlockCssSelectorphp">trunk/tests/phpunit/tests/theme/wpGetBlockCssSelector.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportssettingsphp"></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/settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/settings.php 2023-06-27 08:09:29 UTC (rev 56057)
+++ trunk/src/wp-includes/block-supports/settings.php   2023-06-27 08:46:45 UTC (rev 56058)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,6 +66,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @internal
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.2.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.3.0 Updated preset styles to use Selectors API.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @access private
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string|null $pre_render   The pre-rendered content. Default null.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,11 +96,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">        $registry                = WP_Block_Type_Registry::get_instance();
</span><span class="cx" style="display: block; padding: 0 10px">        $blocks                  = $registry->get_all_registered();
</span><span class="cx" style="display: block; padding: 0 10px">        foreach ( $blocks as $block_type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if (
-                       isset( $block_type->supports['__experimentalSelector'] ) &&
-                       is_string( $block_type->supports['__experimentalSelector'] )
-               ) {
-                       $variables_root_selector .= ',' . $block_type->supports['__experimentalSelector'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+               * We only want to append selectors for block's using custom selectors
+               * i.e. not `wp-block-<name>`.
+               */
+               $has_custom_selector =
+                       ( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) ||
+                       ( isset( $block_type->selectors['root'] ) && is_string( $block_type->selectors['root'] ) );
+
+               if ( $has_custom_selector ) {
+                       $variables_root_selector .= ',' . wp_get_block_css_selector( $block_type );
</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">        $variables_root_selector = WP_Theme_JSON::scope_selector( $class_name, $variables_root_selector );
</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     2023-06-27 08:09:29 UTC (rev 56057)
+++ trunk/src/wp-includes/class-wp-theme-json.php       2023-06-27 08:46:45 UTC (rev 56058)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -879,6 +879,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 `duotone` key with CSS selector.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.1.0 Added `features` key with block support feature level selectors.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.3.0 Refactored and stabilized selectors API.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array Block metadata.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -893,56 +894,33 @@
</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">                foreach ( $blocks as $block_name => $block_type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if (
-                               isset( $block_type->supports['__experimentalSelector'] ) &&
-                               is_string( $block_type->supports['__experimentalSelector'] )
-                       ) {
-                               static::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector'];
-                       } else {
-                               static::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) );
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $root_selector = wp_get_block_css_selector( $block_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if (
-                               isset( $block_type->supports['color']['__experimentalDuotone'] ) &&
-                               is_string( $block_type->supports['color']['__experimentalDuotone'] )
-                       ) {
-                               static::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 static::$blocks_metadata[ $block_name ]['selector']  = $root_selector;
+                       static::$blocks_metadata[ $block_name ]['selectors'] = static::get_block_selectors( $block_type, $root_selector );
+
+                       $elements = static::get_block_element_selectors( $root_selector );
+                       if ( ! empty( $elements ) ) {
+                               static::$blocks_metadata[ $block_name ]['elements'] = $elements;
</ins><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">-                        // Generate block support feature level selectors if opted into
-                       // for the current block.
-                       $features = array();
-                       foreach ( static::BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS as $key => $feature ) {
-                               if (
-                                       isset( $block_type->supports[ $key ]['__experimentalSelector'] ) &&
-                                       $block_type->supports[ $key ]['__experimentalSelector']
-                               ) {
-                                       $features[ $feature ] = static::scope_selector(
-                                               static::$blocks_metadata[ $block_name ]['selector'],
-                                               $block_type->supports[ $key ]['__experimentalSelector']
-                                       );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // The block may or may not have a duotone selector.
+                       $duotone_selector = wp_get_block_css_selector( $block_type, 'filter.duotone' );
+
+                       // Keep backwards compatibility for support.color.__experimentalDuotone.
+                       if ( null === $duotone_selector ) {
+                               $duotone_support = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null );
+
+                               if ( $duotone_support ) {
+                                       $root_selector    = wp_get_block_css_selector( $block_type );
+                                       $duotone_selector = WP_Theme_JSON::scope_selector( $root_selector, $duotone_support );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! empty( $features ) ) {
-                               static::$blocks_metadata[ $block_name ]['features'] = $features;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( null !== $duotone_selector ) {
+                               static::$blocks_metadata[ $block_name ]['duotone'] = $duotone_selector;
</ins><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">-                        // Assign defaults, then overwrite those that the block sets by itself.
-                       // If the block selector is compounded, will append the element to each
-                       // individual block selector.
-                       $block_selectors = explode( ',', static::$blocks_metadata[ $block_name ]['selector'] );
-                       foreach ( static::ELEMENTS as $el_name => $el_selector ) {
-                               $element_selector = array();
-                               foreach ( $block_selectors as $selector ) {
-                                       if ( $selector === $el_selector ) {
-                                               $element_selector = array( $el_selector );
-                                               break;
-                                       }
-                                       $element_selector[] = static::prepend_to_selector( $el_selector, $selector . ' ' );
-                               }
-                               static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector );
-                       }
</del><span class="cx" style="display: block; padding: 0 10px">                         // If the block has style variations, append their selectors to the block metadata.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $block_type->styles ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $style_selectors = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2223,6 +2201,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * An internal method to get the block nodes from a theme.json file.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.1.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.3.0 Refactored and stabilized selectors API.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param array $theme_json The theme.json converted to an array.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array The block nodes in theme.json.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2251,8 +2230,8 @@
</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">                        $feature_selectors = null;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( isset( $selectors[ $name ]['features'] ) ) {
-                               $feature_selectors = $selectors[ $name ]['features'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( isset( $selectors[ $name ]['selectors'] ) ) {
+                               $feature_selectors = $selectors[ $name ]['selectors'];
</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">                        $variation_selectors = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2269,6 +2248,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'name'       => $name,
</span><span class="cx" style="display: block; padding: 0 10px">                                'path'       => array( 'styles', 'blocks', $name ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'selector'   => $selector,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'selectors'  => $feature_selectors,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'duotone'    => $duotone_selector,
</span><span class="cx" style="display: block; padding: 0 10px">                                'features'   => $feature_selectors,
</span><span class="cx" style="display: block; padding: 0 10px">                                'variations' => $variation_selectors,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2311,92 +2291,43 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string Styles for the block.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_styles_for_block( $block_metadata ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $node             = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
-               $use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
-               $selector         = $block_metadata['selector'];
-               $settings         = _wp_array_get( $this->theme_json, array( 'settings' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $node                 = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
+               $use_root_padding     = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
+               $selector             = $block_metadata['selector'];
+               $settings             = _wp_array_get( $this->theme_json, array( 'settings' ) );
+               $feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                /*
-                * Process style declarations for block support features the current
-                * block contains selectors for. Values for a feature with a custom
-                * selector are filtered from the theme.json node before it is
-                * processed as normal.
-               */
-               $feature_declarations = array();
-
-               if ( ! empty( $block_metadata['features'] ) ) {
-                       foreach ( $block_metadata['features'] as $feature_name => $feature_selector ) {
-                               if ( ! empty( $node[ $feature_name ] ) ) {
-                                       // Create temporary node containing only the feature data
-                                       // to leverage existing `compute_style_properties` function.
-                                       $feature = array( $feature_name => $node[ $feature_name ] );
-                                       // Generate the feature's declarations only.
-                                       $new_feature_declarations = static::compute_style_properties( $feature, $settings, null, $this->theme_json );
-
-                                       // Merge new declarations with any that already exist for
-                                       // the feature selector. This may occur when multiple block
-                                       // support features use the same custom selector.
-                                       if ( isset( $feature_declarations[ $feature_selector ] ) ) {
-                                               foreach ( $new_feature_declarations as $new_feature_declaration ) {
-                                                       $feature_declarations[ $feature_selector ][] = $new_feature_declaration;
-                                               }
-                                       } else {
-                                               $feature_declarations[ $feature_selector ] = $new_feature_declarations;
-                                       }
-
-                                       // Remove the feature from the block's node now the
-                                       // styles will be included under the feature level selector.
-                                       unset( $node[ $feature_name ] );
-                               }
-                       }
-               }
-
</del><span class="cx" style="display: block; padding: 0 10px">                 // If there are style variations, generate the declarations for them, including any feature selectors the block may have.
</span><span class="cx" style="display: block; padding: 0 10px">                $style_variation_declarations = array();
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $block_metadata['variations'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( $block_metadata['variations'] as $style_variation ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $style_variation_node     = _wp_array_get( $this->theme_json, $style_variation['path'], array() );
-                               $style_variation_selector = $style_variation['selector'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $style_variation_node           = _wp_array_get( $this->theme_json, $style_variation['path'], array() );
+                               $clean_style_variation_selector = trim( $style_variation['selector'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // If the block has feature selectors, generate the declarations for them within the current style variation.
-                               if ( ! empty( $block_metadata['features'] ) ) {
-                                       $clean_style_variation_selector = trim( $style_variation_selector );
-                                       foreach ( $block_metadata['features'] as $feature_name => $feature_selector ) {
-                                               if ( empty( $style_variation_node[ $feature_name ] ) ) {
-                                                       continue;
-                                               }
-                                               // Prepend the variation selector to the feature selector.
-                                               $split_feature_selectors    = explode( ',', $feature_selector );
-                                               $feature_selectors          = array_map(
-                                                       static function( $split_feature_selector ) use ( $clean_style_variation_selector ) {
-                                                               return $clean_style_variation_selector . trim( $split_feature_selector );
-                                                       },
-                                                       $split_feature_selectors
-                                               );
-                                               $combined_feature_selectors = implode( ',', $feature_selectors );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // Generate any feature/subfeature style declarations for the current style variation.
+                               $variation_declarations = static::get_feature_declarations_for_node( $block_metadata, $style_variation_node );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                // Compute declarations for the feature.
-                                               $new_feature_declarations = static::compute_style_properties( array( $feature_name => $style_variation_node[ $feature_name ] ), $settings, null, $this->theme_json );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // Combine selectors with style variation's selector and add to overall style variation declarations.
+                               foreach ( $variation_declarations as $current_selector => $new_declarations ) {
+                                       // If current selector includes block classname, remove it but leave the whitespace in.
+                                       $shortened_selector = str_replace( $block_metadata['selector'] . ' ', ' ', $current_selector );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                /*
-                                                * Merge new declarations with any that already exist for
-                                                * the feature selector. This may occur when multiple block
-                                                * support features use the same custom selector.
-                                                */
-                                               if ( isset( $style_variation_declarations[ $combined_feature_selectors ] ) ) {
-                                                       $style_variation_declarations[ $combined_feature_selectors ] = array_merge( $style_variation_declarations[ $combined_feature_selectors ], $new_feature_declarations );
-                                               } else {
-                                                       $style_variation_declarations[ $combined_feature_selectors ] = $new_feature_declarations;
-                                               }
-                                               /*
-                                                * Remove the feature from the variation's node now the
-                                                * styles will be included under the feature level selector.
-                                                */
-                                               unset( $style_variation_node[ $feature_name ] );
-                                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Prepend the variation selector to the current selector.
+                                       $split_selectors    = explode( ',', $shortened_selector );
+                                       $updated_selectors  = array_map(
+                                               static function( $split_selector ) use ( $clean_style_variation_selector ) {
+                                                       return $clean_style_variation_selector . $split_selector;
+                                               },
+                                               $split_selectors
+                                       );
+                                       $combined_selectors = implode( ',', $updated_selectors );
+
+                                       // Add the new declarations to the overall results under the modified selector.
+                                       $style_variation_declarations[ $combined_selectors ] = $new_declarations;
</ins><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">                                 // Compute declarations for remaining styles not covered by feature level selectors.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $style_variation_declarations[ $style_variation_selector ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json );
</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">@@ -2472,8 +2403,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // 3. Generate and append the rules that use the duotone selector.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $block_metadata['duotone'] ) && ! empty( $declarations_duotone ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $selector_duotone = static::scope_selector( $block_metadata['selector'], $block_metadata['duotone'] );
-                       $block_rules     .= static::to_ruleset( $selector_duotone, $declarations_duotone );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $block_rules .= static::to_ruleset( $block_metadata['duotone'], $declarations_duotone );
</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">                // 4. Generate Layout block gap styles.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3537,6 +3467,159 @@
</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">+         * Returns the selectors metadata for a block.
+        *
+        * @since 6.3.0
+        *
+        * @param object $block_type    The block type.
+        * @param string $root_selector The block's root selector.
+        *
+        * @return array The custom selectors set by the block.
+        */
+       protected static function get_block_selectors( $block_type, $root_selector ) {
+               if ( ! empty( $block_type->selectors ) ) {
+                       return $block_type->selectors;
+               }
+
+               $selectors = array( 'root' => $root_selector );
+               foreach ( static::BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS as $key => $feature ) {
+                       $feature_selector = wp_get_block_css_selector( $block_type, $key );
+                       if ( null !== $feature_selector ) {
+                               $selectors[ $feature ] = array( 'root' => $feature_selector );
+                       }
+               }
+
+               return $selectors;
+       }
+
+       /**
+        * Generates all the element selectors for a block.
+        *
+        * @since 6.3.0
+        *
+        * @param string $root_selector The block's root CSS selector.
+        * @return array The block's element selectors.
+        */
+       protected static function get_block_element_selectors( $root_selector ) {
+               // Assign defaults, then override those that the block sets by itself.
+               // If the block selector is compounded, will append the element to each
+               // individual block selector.
+               $block_selectors   = explode( ',', $root_selector );
+               $element_selectors = array();
+
+               foreach ( static::ELEMENTS as $el_name => $el_selector ) {
+                       $element_selector = array();
+                       foreach ( $block_selectors as $selector ) {
+                               if ( $selector === $el_selector ) {
+                                       $element_selector = array( $el_selector );
+                                       break;
+                               }
+                               $element_selector[] = static::prepend_to_selector( $el_selector, $selector . ' ' );
+                       }
+                       $element_selectors[ $el_name ] = implode( ',', $element_selector );
+               }
+
+               return $element_selectors;
+       }
+
+       /**
+        * Generates style declarations for a node's features e.g., color, border,
+        * typography etc. that have custom selectors in their related block's
+        * metadata.
+        *
+        * @since 6.3.0
+        *
+        * @param object $metadata The related block metadata containing selectors.
+        * @param object $node     A merged theme.json node for block or variation.
+        *
+        * @return array The style declarations for the node's features with custom
+        * selectors.
+        */
+       protected function get_feature_declarations_for_node( $metadata, &$node ) {
+               $declarations = array();
+
+               if ( ! isset( $metadata['selectors'] ) ) {
+                       return $declarations;
+               }
+
+               $settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
+
+               foreach ( $metadata['selectors'] as $feature => $feature_selectors ) {
+                       // Skip if this is the block's root selector or the block doesn't
+                       // have any styles for the feature.
+                       if ( 'root' === $feature || empty( $node[ $feature ] ) ) {
+                               continue;
+                       }
+
+                       if ( is_array( $feature_selectors ) ) {
+                               foreach ( $feature_selectors as $subfeature => $subfeature_selector ) {
+                                       if ( 'root' === $subfeature || empty( $node[ $feature ][ $subfeature ] ) ) {
+                                               continue;
+                                       }
+
+                                       // Create temporary node containing only the subfeature data
+                                       // to leverage existing `compute_style_properties` function.
+                                       $subfeature_node = array(
+                                               $feature => array(
+                                                       $subfeature => $node[ $feature ][ $subfeature ],
+                                               ),
+                                       );
+
+                                       // Generate style declarations.
+                                       $new_declarations = static::compute_style_properties( $subfeature_node, $settings, null, $this->theme_json );
+
+                                       // Merge subfeature declarations into feature declarations.
+                                       if ( isset( $declarations[ $subfeature_selector ] ) ) {
+                                               foreach ( $new_declarations as $new_declaration ) {
+                                                       $declarations[ $subfeature_selector ][] = $new_declaration;
+                                               }
+                                       } else {
+                                               $declarations[ $subfeature_selector ] = $new_declarations;
+                                       }
+
+                                       // Remove the subfeature from the block's node now its
+                                       // styles will be included under its own selector not the
+                                       // block's.
+                                       unset( $node[ $feature ][ $subfeature ] );
+                               }
+                       }
+
+                       // Now subfeatures have been processed and removed we can process
+                       // feature root selector or simple string selector.
+                       if (
+                               is_string( $feature_selectors ) ||
+                               ( isset( $feature_selectors['root'] ) && $feature_selectors['root'] )
+                       ) {
+                               $feature_selector = is_string( $feature_selectors ) ? $feature_selectors : $feature_selectors['root'];
+
+                               // Create temporary node containing only the feature data
+                               // to leverage existing `compute_style_properties` function.
+                               $feature_node = array( $feature => $node[ $feature ] );
+
+                               // Generate the style declarations.
+                               $new_declarations = static::compute_style_properties( $feature_node, $settings, null, $this->theme_json );
+
+                               // Merge new declarations with any that already exist for
+                               // the feature selector. This may occur when multiple block
+                               // support features use the same custom selector.
+                               if ( isset( $declarations[ $feature_selector ] ) ) {
+                                       foreach ( $new_declarations as $new_declaration ) {
+                                               $declarations[ $feature_selector ][] = $new_declaration;
+                                       }
+                               } else {
+                                       $declarations[ $feature_selector ] = $new_declarations;
+                               }
+
+                               // Remove the feature from the block's node now its styles
+                               // will be included under its own selector not the block's.
+                               unset( $node[ $feature ] );
+                       }
+               }
+
+               return $declarations;
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Replaces CSS variables with their values in place.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.3.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3608,5 +3691,4 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $theme_json->theme_json['styles'] = self::convert_variables_to_value( $styles, $vars );
</span><span class="cx" style="display: block; padding: 0 10px">                return $theme_json;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesglobalstylesandsettingsphp"></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/global-styles-and-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/global-styles-and-settings.php      2023-06-27 08:09:29 UTC (rev 56057)
+++ trunk/src/wp-includes/global-styles-and-settings.php        2023-06-27 08:46:45 UTC (rev 56058)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -443,3 +443,108 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_theme_directory_pattern_slugs() {
</span><span class="cx" style="display: block; padding: 0 10px">        return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_patterns();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Determines the CSS selector for the block type and property provided,
+ * returning it if available.
+ *
+ * @since 6.3.0
+ *
+ * @param WP_Block_Type $block_type The block's type.
+ * @param string|array  $target     The desired selector's target, `root` or array path.
+ * @param boolean       $fallback   Whether to fall back to broader selector.
+ *
+ * @return string|null CSS selector or `null` if no selector available.
+ */
+function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = false ) {
+       if ( empty( $target ) ) {
+               return null;
+       }
+
+       $has_selectors = ! empty( $block_type->selectors );
+
+       // Root Selector.
+
+       // Calculated before returning as it can be used as fallback for
+       // feature selectors later on.
+       $root_selector = null;
+
+       if ( $has_selectors && isset( $block_type->selectors['root'] ) ) {
+               // Use the selectors API if available.
+               $root_selector = $block_type->selectors['root'];
+       } elseif ( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) {
+               // Use the old experimental selector supports property if set.
+               $root_selector = $block_type->supports['__experimentalSelector'];
+       } else {
+               // If no root selector found, generate default block class selector.
+               $block_name    = str_replace( '/', '-', str_replace( 'core/', '', $block_type->name ) );
+               $root_selector = ".wp-block-{$block_name}";
+       }
+
+       // Return selector if it's the root target we are looking for.
+       if ( 'root' === $target ) {
+               return $root_selector;
+       }
+
+       // If target is not `root` we have a feature or subfeature as the target.
+       // If the target is a string convert to an array.
+       if ( is_string( $target ) ) {
+               $target = explode( '.', $target );
+       }
+
+       // Feature Selectors ( May fallback to root selector ).
+       if ( 1 === count( $target ) ) {
+               $fallback_selector = $fallback ? $root_selector : null;
+
+               // Prefer the selectors API if available.
+               if ( $has_selectors ) {
+                       // Look for selector under `feature.root`.
+                       $path             = array_merge( $target, array( 'root' ) );
+                       $feature_selector = _wp_array_get( $block_type->selectors, $path, null );
+
+                       if ( $feature_selector ) {
+                               return $feature_selector;
+                       }
+
+                       // Check if feature selector is set via shorthand.
+                       $feature_selector = _wp_array_get( $block_type->selectors, $target, null );
+
+                       return is_string( $feature_selector ) ? $feature_selector : $fallback_selector;
+               }
+
+               // Try getting old experimental supports selector value.
+               $path             = array_merge( $target, array( '__experimentalSelector' ) );
+               $feature_selector = _wp_array_get( $block_type->supports, $path, null );
+
+               // Nothing to work with, provide fallback or null.
+               if ( null === $feature_selector ) {
+                       return $fallback_selector;
+               }
+
+               // Scope the feature selector by the block's root selector.
+               return WP_Theme_JSON::scope_selector( $root_selector, $feature_selector );
+       }
+
+       // Subfeature selector
+       // This may fallback either to parent feature or root selector.
+       $subfeature_selector = null;
+
+       // Use selectors API if available.
+       if ( $has_selectors ) {
+               $subfeature_selector = _wp_array_get( $block_type->selectors, $target, null );
+       }
+
+       // Only return if we have a subfeature selector.
+       if ( $subfeature_selector ) {
+               return $subfeature_selector;
+       }
+
+       // To this point we don't have a subfeature selector. If a fallback
+       // has been requested, remove subfeature from target path and return
+       // results of a call for the parent feature's selector.
+       if ( $fallback ) {
+               return wp_get_block_css_selector( $block_type, $target[0], $fallback );
+       }
+
+       return null;
+}
</ins></span></pre></div>
<a id="trunktestsphpunitteststhemewpGetBlockCssSelectorphp"></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/theme/wpGetBlockCssSelector.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpGetBlockCssSelector.php                         (rev 0)
+++ trunk/tests/phpunit/tests/theme/wpGetBlockCssSelector.php   2023-06-27 08:46:45 UTC (rev 56058)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,356 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Tests wp_get_block_css_selector().
+ *
+ * @since 6.3.0
+ *
+ * @group themes
+ *
+ * @covers ::wp_get_block_css_selector
+ */
+
+class Tests_Theme_WpGetBlockCssSelector extends WP_Theme_UnitTestCase {
+       private $test_block_name;
+
+       public function set_up() {
+               parent::set_up();
+               $this->test_block_name = null;
+       }
+
+       public function tear_down() {
+               unregister_block_type( $this->test_block_name );
+               $this->test_block_name = null;
+               parent::tear_down();
+       }
+
+       private function register_test_block( $name, $selectors = null, $supports = null ) {
+               $this->test_block_name = $name;
+
+               return register_block_type(
+                       $this->test_block_name,
+                       array(
+                               'api_version' => 2,
+                               'attributes'  => array(),
+                               'selectors'   => $selectors,
+                               'supports'    => $supports,
+                       )
+               );
+       }
+
+       /**
+       * @ticket 58586
+       */
+       public function test_get_root_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/block-with-selectors',
+                       array( 'root' => '.wp-custom-block-class' )
+               );
+
+               $selector = wp_get_block_css_selector( $block_type );
+               $this->assertEquals( '.wp-custom-block-class', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_get_root_selector_via_experimental_property() {
+               $block_type = self::register_test_block(
+                       'test/block-without-selectors',
+                       null,
+                       array( '__experimentalSelector' => '.experimental-selector' )
+               );
+
+               $selector = wp_get_block_css_selector( $block_type );
+               $this->assertEquals( '.experimental-selector', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_default_root_selector_generation_for_core_block() {
+               $block_type = self::register_test_block(
+                       'core/without-selectors-or-supports',
+                       null,
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type );
+               $this->assertEquals( '.wp-block-without-selectors-or-supports', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_default_root_selector_generation() {
+               $block_type = self::register_test_block(
+                       'test/without-selectors-or-supports',
+                       null,
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type );
+               $this->assertEquals( '.wp-block-test-without-selectors-or-supports', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_get_feature_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/feature-selector',
+                       array( 'typography' => array( 'root' => '.typography' ) ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography' );
+               $this->assertEquals( '.typography', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_get_feature_selector_via_selectors_api_shorthand_property() {
+               $block_type = self::register_test_block(
+                       'test/shorthand-feature-selector',
+                       array( 'typography' => '.typography' ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography' );
+               $this->assertEquals( '.typography', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_no_feature_level_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/null-feature-selector',
+                       array( 'root' => '.fallback-root-selector' ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography' );
+               $this->assertEquals( null, $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_fallback_feature_level_selector_via_selectors_api_to_generated_class() {
+               $block_type = self::register_test_block(
+                       'test/fallback-feature-selector',
+                       array(),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography', true );
+               $this->assertEquals( '.wp-block-test-fallback-feature-selector', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_fallback_feature_level_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/fallback-feature-selector',
+                       array( 'root' => '.fallback-root-selector' ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography', true );
+               $this->assertEquals( '.fallback-root-selector', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_get_feature_selector_via_experimental_property() {
+               $block_type = self::register_test_block(
+                       'test/experimental-feature-selector',
+                       null,
+                       array(
+                               'typography' => array(
+                                       '__experimentalSelector' => '.experimental-typography',
+                               ),
+                       )
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography' );
+               $this->assertEquals( '.wp-block-test-experimental-feature-selector .experimental-typography', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_fallback_feature_selector_via_experimental_property() {
+               $block_type = self::register_test_block(
+                       'test/fallback-feature-selector',
+                       null,
+                       array()
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography', true );
+               $this->assertEquals( '.wp-block-test-fallback-feature-selector', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_no_feature_selector_via_experimental_property() {
+               $block_type = self::register_test_block(
+                       'test/null-experimental-feature-selector',
+                       null,
+                       array()
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography' );
+               $this->assertEquals( null, $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_get_subfeature_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/subfeature-selector',
+                       array(
+                               'typography' => array(
+                                       'textDecoration' => '.root .typography .text-decoration',
+                               ),
+                       ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector(
+                       $block_type,
+                       array( 'typography', 'textDecoration' )
+               );
+
+               $this->assertEquals( '.root .typography .text-decoration', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_fallback_subfeature_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/subfeature-selector',
+                       array(
+                               'typography' => array( 'root' => '.root .typography' ),
+                       ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector(
+                       $block_type,
+                       array( 'typography', 'textDecoration' ),
+                       true
+               );
+
+               $this->assertEquals( '.root .typography', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_no_subfeature_level_selector_via_selectors_api() {
+               $block_type = self::register_test_block(
+                       'test/null-subfeature-selector',
+                       array(),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, array( 'typography', 'fontSize' ) );
+               $this->assertEquals( null, $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_fallback_subfeature_selector_via_experimental_property() {
+               $block_type = self::register_test_block(
+                       'test/fallback-subfeature-selector',
+                       null,
+                       array()
+               );
+
+               $selector = wp_get_block_css_selector(
+                       $block_type,
+                       array( 'typography', 'fontSize' ),
+                       true
+               );
+               $this->assertEquals( '.wp-block-test-fallback-subfeature-selector', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_no_subfeature_selector_via_experimental_property() {
+               $block_type = self::register_test_block(
+                       'test/null-experimental-subfeature-selector',
+                       null,
+                       array()
+               );
+
+               $selector = wp_get_block_css_selector(
+                       $block_type,
+                       array( 'typography', 'fontSize' )
+               );
+               $this->assertEquals( null, $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_empty_target_returns_null() {
+               $block_type = self::register_test_block(
+                       'test/null-experimental-subfeature-selector',
+                       null,
+                       array()
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, array() );
+               $this->assertEquals( null, $selector );
+
+               $selector = wp_get_block_css_selector( $block_type, '' );
+               $this->assertEquals( null, $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_string_targets_for_features() {
+               $block_type = self::register_test_block(
+                       'test/target-types-for-features',
+                       array( 'typography' => '.found' ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography' );
+               $this->assertEquals( '.found', $selector );
+
+               $selector = wp_get_block_css_selector( $block_type, array( 'typography' ) );
+               $this->assertEquals( '.found', $selector );
+       }
+
+       /**
+        * @ticket 58586
+        */
+       public function test_string_targets_for_subfeatures() {
+               $block_type = self::register_test_block(
+                       'test/target-types-for-features',
+                       array(
+                               'typography' => array( 'fontSize' => '.found' ),
+                       ),
+                       null
+               );
+
+               $selector = wp_get_block_css_selector( $block_type, 'typography.fontSize' );
+               $this->assertEquals( '.found', $selector );
+
+               $selector = wp_get_block_css_selector( $block_type, array( 'typography', 'fontSize' ) );
+               $this->assertEquals( '.found', $selector );
+       }
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/theme/wpGetBlockCssSelector.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>