Make WordPress Core


Ignore:
Timestamp:
04/05/2022 12:06:48 PM (3 years ago)
Author:
gziolo
Message:

Editor: Backport block support changes from the Gutenberg plugin

Migrate spacing, border, color, dimensions, elements and typography and associated tests for block supports in the block editor.

Related changes in Gutenberg:

Props ramonopoly, aaronrobertshaw.
See #55505.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-supports/colors.php

    r52264 r53076  
    4545        unregister_block_type( 'test/color-slug-with-numbers' );
    4646    }
     47
     48    /**
     49     * @ticket 55505
     50     */
     51    function test_color_with_skipped_serialization_block_supports() {
     52        $block_name = 'test/color-with-skipped-serialization-block-supports';
     53        register_block_type(
     54            $block_name,
     55            array(
     56                'api_version' => 2,
     57                'attributes'  => array(
     58                    'style' => array(
     59                        'type' => 'object',
     60                    ),
     61                ),
     62                'supports'    => array(
     63                    'color' => array(
     64                        'text'                            => true,
     65                        'gradients'                       => true,
     66                        '__experimentalSkipSerialization' => true,
     67                    ),
     68                ),
     69            )
     70        );
     71
     72        $registry   = WP_Block_Type_Registry::get_instance();
     73        $block_type = $registry->get_registered( $block_name );
     74        $block_atts = array(
     75            'style' => array(
     76                'color' => array(
     77                    'text'     => '#d92828',
     78                    'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,13,13) 46%,rgb(155,81,224) 100%)',
     79                ),
     80            ),
     81        );
     82
     83        $actual   = wp_apply_colors_support( $block_type, $block_atts );
     84        $expected = array();
     85
     86        $this->assertSame( $expected, $actual );
     87        unregister_block_type( $block_name );
     88    }
     89
     90    /**
     91     * @ticket 55505
     92     */
     93    function test_gradient_with_individual_skipped_serialization_block_supports() {
     94        $block_name = 'test/gradient-with-individual-skipped-serialization-block-support';
     95        register_block_type(
     96            $block_name,
     97            array(
     98                'api_version' => 2,
     99                'attributes'  => array(
     100                    'style' => array(
     101                        'type' => 'object',
     102                    ),
     103                ),
     104                'supports'    => array(
     105                    'color' => array(
     106                        'text'                            => true,
     107                        'gradients'                       => true,
     108                        '__experimentalSkipSerialization' => array( 'gradients' ),
     109                    ),
     110                ),
     111            )
     112        );
     113
     114        $registry   = WP_Block_Type_Registry::get_instance();
     115        $block_type = $registry->get_registered( $block_name );
     116        $block_atts = array(
     117            'style' => array(
     118                'color' => array(
     119                    'text' => '#d92828',
     120                ),
     121            ),
     122        );
     123
     124        $actual   = wp_apply_colors_support( $block_type, $block_atts );
     125        $expected = array(
     126            'class' => 'has-text-color',
     127            'style' => 'color: #d92828;',
     128        );
     129
     130        $this->assertSame( $expected, $actual );
     131        unregister_block_type( $block_name );
     132    }
    47133}
Note: See TracChangeset for help on using the changeset viewer.