Make WordPress Core

Changeset 55448


Ignore:
Timestamp:
03/01/2023 04:15:27 PM (15 months ago)
Author:
audrasjb
Message:

Editor: Ensure Global styles values are reset in the site editor.

This changeset fixes a bug by which the reset function of the global styles sidebar would not work as expected in the site editor. It reverts [54517] and adds related unit tests.

Props oandregal, ntsekouras, youknowriad, hellofromTonya.
Fixes #57824
See #56467

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r55273 r55448  
    560560        }
    561561
    562         $result = static::get_core_data();
     562        $result = new WP_Theme_JSON();
     563        $result->merge( static::get_core_data() );
    563564        if ( 'default' === $origin ) {
    564565            $result->set_spacing_sizes();
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r55273 r55448  
    847847        $this->assertSame( $user_palette, isset( $settings['color']['palette']['custom'] ), $user_palette_text );
    848848
     849    }
     850
     851    /**
     852     * Tests that get_merged_data returns the data merged up to the proper origin
     853     * and that the core values have the proper data.
     854     *
     855     * @ticket 57824
     856     *
     857     * @covers WP_Theme_JSON_Resolver::get_merged_data
     858     *
     859     */
     860    public function test_get_merged_data_returns_origin_proper() {
     861        // Make sure the theme has a theme.json
     862        // though it doesn't have any data for styles.spacing.padding.
     863        switch_theme( 'block-theme' );
     864
     865        // Make sure the user defined some data for styles.spacing.padding.
     866        wp_set_current_user( self::$administrator_id );
     867        $user_cpt                               = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme(), true );
     868        $config                                 = json_decode( $user_cpt['post_content'], true );
     869        $config['styles']['spacing']['padding'] = array(
     870            'top'    => '23px',
     871            'left'   => '23px',
     872            'bottom' => '23px',
     873            'right'  => '23px',
     874        );
     875        $user_cpt['post_content']               = wp_json_encode( $config );
     876        wp_update_post( $user_cpt, true, false );
     877
     878        // Query data from the user origin and then for the theme origin.
     879        $theme_json_user  = WP_Theme_JSON_Resolver::get_merged_data( 'custom' );
     880        $padding_user     = $theme_json_user->get_raw_data()['styles']['spacing']['padding'];
     881        $theme_json_theme = WP_Theme_JSON_Resolver::get_merged_data( 'theme' );
     882        $padding_theme    = $theme_json_theme->get_raw_data()['styles']['spacing']['padding'];
     883
     884        $this->assertSame( '23px', $padding_user['top'] );
     885        $this->assertSame( '23px', $padding_user['right'] );
     886        $this->assertSame( '23px', $padding_user['bottom'] );
     887        $this->assertSame( '23px', $padding_user['left'] );
     888        $this->assertSame( '0px', $padding_theme['top'] );
     889        $this->assertSame( '0px', $padding_theme['right'] );
     890        $this->assertSame( '0px', $padding_theme['bottom'] );
     891        $this->assertSame( '0px', $padding_theme['left'] );
    849892    }
    850893
Note: See TracChangeset for help on using the changeset viewer.