Make WordPress Core


Ignore:
Timestamp:
09/01/2023 02:51:55 AM (2 years ago)
Author:
isabel_brison
Message:

Editor: Preserve block style variations when securing theme.

Adds the ability to process block style variations to the remove_insecure_properties function of theme json class.

Props dsas, ramonopoly.
Fixes #59108.

File:
1 edited

Legend:

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

    r56101 r56502  
    38703870    }
    38713871
     3872    public function test_block_style_variations() {
     3873        wp_set_current_user( static::$administrator_id );
     3874
     3875        $expected = array(
     3876            'version' => WP_Theme_JSON::LATEST_SCHEMA,
     3877            'styles'  => array(
     3878                'blocks' => array(
     3879                    'core/button' => array(
     3880                        'color'      => array(
     3881                            'background' => 'blue',
     3882                        ),
     3883                        'variations' => array(
     3884                            'outline' => array(
     3885                                'color' => array(
     3886                                    'background' => 'purple',
     3887                                ),
     3888                            ),
     3889                        ),
     3890                    ),
     3891                ),
     3892            ),
     3893        );
     3894
     3895        $actual = WP_Theme_JSON::remove_insecure_properties( $expected );
     3896
     3897        $this->assertSameSetsWithIndex( $expected, $actual );
     3898    }
     3899
     3900    public function test_block_style_variations_with_invalid_properties() {
     3901        wp_set_current_user( static::$administrator_id );
     3902
     3903        $partially_invalid_variation = array(
     3904            'version' => WP_Theme_JSON::LATEST_SCHEMA,
     3905            'styles'  => array(
     3906                'blocks' => array(
     3907                    'core/button' => array(
     3908                        'color'      => array(
     3909                            'background' => 'blue',
     3910                        ),
     3911                        'variations' => array(
     3912                            'outline' => array(
     3913                                'color'   => array(
     3914                                    'background' => 'purple',
     3915                                ),
     3916                                'invalid' => array(
     3917                                    'value' => 'should be stripped',
     3918                                ),
     3919                            ),
     3920                        ),
     3921                    ),
     3922                ),
     3923            ),
     3924        );
     3925
     3926        $expected = array(
     3927            'version' => WP_Theme_JSON::LATEST_SCHEMA,
     3928            'styles'  => array(
     3929                'blocks' => array(
     3930                    'core/button' => array(
     3931                        'color'      => array(
     3932                            'background' => 'blue',
     3933                        ),
     3934                        'variations' => array(
     3935                            'outline' => array(
     3936                                'color' => array(
     3937                                    'background' => 'purple',
     3938                                ),
     3939                            ),
     3940                        ),
     3941                    ),
     3942                ),
     3943            ),
     3944        );
     3945
     3946        $actual = WP_Theme_JSON::remove_insecure_properties( $partially_invalid_variation );
     3947
     3948        $this->assertSameSetsWithIndex( $expected, $actual );
     3949    }
     3950
    38723951    /**
    38733952     * @ticket 56611
Note: See TracChangeset for help on using the changeset viewer.