Make WordPress Core


Ignore:
Timestamp:
01/25/2024 10:41:38 AM (8 months ago)
Author:
youknowriad
Message:

Editor: Fix Theme.json application of custom root selector for styles.

Theme.json stylesheets attempting to use a custom root selector are generated with in correct styles.

Props aaronrobertshaw, get_dave, mukesh27.
Fixes #60343.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r57333 r57352  
    32113211     * @param array $styles An array with style definitions.
    32123212     * @param array $path   Path to the desired properties.
    3213      *
    32143213     */
    32153214    public function test_get_property_value_should_return_string_for_invalid_paths_or_null_values( $styles, $path ) {
     
    49404939        $this->assertEquals( $secondary_color, $styles['blocks']['core/quote']['variations']['plain']['color']['background'], 'Block variations: color' );
    49414940    }
     4941
     4942    /**
     4943     * Tests that a custom root selector is correctly applied when generating a stylesheet.
     4944     *
     4945     * @ticket 60343
     4946     */
     4947    public function test_get_stylesheet_custom_root_selector() {
     4948        $theme_json = new WP_Theme_JSON(
     4949            array(
     4950                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     4951                'styles'  => array(
     4952                    'color' => array(
     4953                        'text' => 'teal',
     4954                    ),
     4955                ),
     4956            ),
     4957            'default'
     4958        );
     4959
     4960        $options = array( 'root_selector' => '.custom' );
     4961        $actual  = $theme_json->get_stylesheet( array( 'styles' ), null, $options );
     4962
     4963        // Results also include root site blocks styles which hard code
     4964        // `body { margin: 0;}`.
     4965        $this->assertEquals(
     4966            'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.custom{color: teal;}',
     4967            $actual
     4968        );
     4969    }
    49424970}
Note: See TracChangeset for help on using the changeset viewer.