Make WordPress Core

Changeset 58312


Ignore:
Timestamp:
06/03/2024 11:34:24 PM (2 years ago)
Author:
isabel_brison
Message:

Editor: Add __experimentalSkipSerialization support to shadow.

Checks if __experimentalSkipSerialization is set and returns early from wp_apply_shadow_support if so.

Props colind, madhudollu, aaronrobertshaw, vcanales, isabel_brison, swissspidy, youknowriad.
Fixes #60784.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/shadow.php

    r57510 r58312  
    4444 *
    4545 * @since 6.3.0
     46 * @since 6.6.0 Return early if __experimentalSkipSerialization is true.
    4647 * @access private
    4748 *
     
    5354        $has_shadow_support = block_has_support( $block_type, 'shadow', false );
    5455
    55         if ( ! $has_shadow_support ) {
     56        if (
     57                ! $has_shadow_support ||
     58                wp_should_skip_block_supports_serialization( $block_type, 'shadow' )
     59        ) {
    5660                return array();
    5761        }
  • trunk/tests/phpunit/tests/block-supports/shadow.php

    r58181 r58312  
    2323
    2424        /**
    25          * @ticket 58590
     25         * Registers a new block for testing shadow support.
     26         *
     27         * @param string $block_name Name for the test block.
     28         * @param array  $supports   Array defining block support configuration.
     29         *
     30         * @return WP_Block_Type The block type for the newly registered test block.
    2631         */
    27         public function test_shadow_style_is_applied() {
    28                 $this->test_block_name = 'test/shadow-style-is-applied';
     32        private function register_shadow_block_with_support( $block_name, $supports = array() ) {
     33                $this->test_block_name = $block_name;
    2934                register_block_type(
    3035                        $this->test_block_name,
     
    3641                                        ),
    3742                                ),
    38                                 'supports'    => array(
    39                                         'shadow' => true,
    40                                 ),
     43                                'supports'    => $supports,
    4144                        )
    4245                );
    43                 $registry   = WP_Block_Type_Registry::get_instance();
    44                 $block_type = $registry->get_registered( $this->test_block_name );
    45                 $block_atts = array(
    46                         'style' => array(
    47                                 'shadow' => '60px -16px teal',
    48                         ),
     46                $registry = WP_Block_Type_Registry::get_instance();
     47
     48                return $registry->get_registered( $this->test_block_name );
     49        }
     50
     51        /**
     52         * Tests the generation of shadow block support styles.
     53         *
     54         * @dataProvider data_generate_shadow_fixtures
     55         *
     56         * @param boolean|array $support Shadow block support configuration.
     57         * @param string        $value   Shadow style value for style attribute object.
     58         * @param array         $expected       Expected shadow block support styles.
     59         */
     60        public function test_wp_apply_shadow_support( $support, $value, $expected ) {
     61                $block_type  = self::register_shadow_block_with_support(
     62                        'test/shadow-block',
     63                        array( 'shadow' => $support )
    4964                );
    50 
    51                 $actual   = wp_apply_shadow_support( $block_type, $block_atts );
    52                 $expected = array(
    53                         'style' => 'box-shadow:60px -16px teal;',
    54                 );
     65                $block_attrs = array( 'style' => array( 'shadow' => $value ) );
     66                $actual      = wp_apply_shadow_support( $block_type, $block_attrs );
    5567
    5668                $this->assertSame( $expected, $actual );
     
    5870
    5971        /**
    60          * @ticket 58590
     72         * Data provider.
     73         *
     74         * @return array
    6175         */
    62         public function test_shadow_without_block_supports() {
    63                 $this->test_block_name = 'test/shadow-with-skipped-serialization-block-supports';
    64                 register_block_type(
    65                         $this->test_block_name,
    66                         array(
    67                                 'api_version' => 2,
    68                                 'attributes'  => array(
    69                                         'style' => array(
    70                                                 'type' => 'object',
    71                                         ),
    72                                 ),
    73                                 'supports'    => array(),
    74                         )
    75                 );
    76                 $registry   = WP_Block_Type_Registry::get_instance();
    77                 $block_type = $registry->get_registered( $this->test_block_name );
    78                 $block_atts = array(
    79                         'style' => array(
    80                                 'shadow' => '60px -16px teal',
     76        public function data_generate_shadow_fixtures() {
     77                return array(
     78                        'with no styles'               => array(
     79                                'support'  => true,
     80                                'value'    => '',
     81                                'expected' => array(),
     82                        ),
     83                        'without support'              => array(
     84                                'support'  => false,
     85                                'value'    => '1px 1px 1px #000',
     86                                'expected' => array(),
     87                        ),
     88                        'with single shadow'           => array(
     89                                'support'  => true,
     90                                'value'    => '1px 1px 1px #000',
     91                                'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000;' ),
     92                        ),
     93                        'with comma separated shadows' => array(
     94                                'support'  => true,
     95                                'value'    => '1px 1px 1px #000, 2px 2px 2px #fff',
     96                                'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000, 2px 2px 2px #fff;' ),
     97                        ),
     98                        'with preset shadow'           => array(
     99                                'support'  => true,
     100                                'value'    => 'var:preset|shadow|natural',
     101                                'expected' => array( 'style' => 'box-shadow:var(--wp--preset--shadow--natural);' ),
     102                        ),
     103                        'with serialization skipped'   => array(
     104                                'support'  => array( '__experimentalSkipSerialization' => true ),
     105                                'value'    => '1px 1px 1px #000',
     106                                'expected' => array(),
    81107                        ),
    82108                );
    83 
    84                 $actual   = wp_apply_spacing_support( $block_type, $block_atts );
    85                 $expected = array();
    86 
    87                 $this->assertSame( $expected, $actual );
    88109        }
    89110}
Note: See TracChangeset for help on using the changeset viewer.