Make WordPress Core

Changeset 56828


Ignore:
Timestamp:
10/11/2023 03:14:01 PM (15 months ago)
Author:
flixos90
Message:

Editor: Add further test coverage for wp_render_elements_support().

Props dmsnell, aaronrobertshaw.
Fixes #59578.

Location:
trunk
Files:
2 edited

Legend:

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

    r56807 r56828  
    3737
    3838    $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
     39    if ( ! $block_type ) {
     40        return $block_content;
     41    }
    3942
    4043    $element_color_properties = array(
  • trunk/tests/phpunit/tests/block-supports/wpRenderElementsSupport.php

    r56806 r56828  
    1717        $this->test_block_name = null;
    1818        parent::tear_down();
     19    }
     20
     21    /**
     22     * Tests that block supports leaves block content alone if the block type
     23     * isn't registered.
     24     *
     25     * @ticket 59578
     26     *
     27     * @covers ::wp_render_elements_support
     28     *
     29     * @return void
     30     */
     31    public function test_leaves_block_content_alone_when_block_type_not_registered() {
     32        $block = array(
     33            'blockName' => 'test/element-block-supports',
     34            'attrs'     => array(
     35                'style' => array(
     36                    'elements' => array(
     37                        'button' => array(
     38                            'color' => array(
     39                                'text'       => 'var:preset|color|vivid-red',
     40                                'background' => '#fff',
     41                            ),
     42                        ),
     43                    ),
     44                ),
     45            ),
     46        );
     47
     48        $block_markup = '<p>Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>';
     49        $actual       = wp_render_elements_support( $block_markup, $block );
     50
     51        $this->assertSame( $block_markup, $actual, 'Expected to leave block content unmodified, but found changes.' );
    1952    }
    2053
     
    6598            $expected_markup,
    6699            $actual,
    67             'Position block wrapper markup should be correct'
     100            'Block wrapper markup should be correct'
    68101        );
    69102    }
     
    81114
    82115        return array(
     116            // @ticket 59578
     117            'empty block markup remains untouched'         => array(
     118                'color_settings'  => array(
     119                    'button' => true,
     120                ),
     121                'elements_styles' => array(
     122                    'button' => array( 'color' => $color_styles ),
     123                ),
     124                'block_markup'    => '',
     125                'expected_markup' => '/^$/',
     126            ),
     127            'empty block markup remains untouched when no block attributes' => array(
     128                'color_settings'  => array(
     129                    'button' => true,
     130                ),
     131                'elements_styles' => null,
     132                'block_markup'    => '',
     133                'expected_markup' => '/^$/',
     134            ),
     135            'block markup remains untouched when block has no attributes' => array(
     136                'color_settings'  => array(
     137                    'button' => true,
     138                ),
     139                'elements_styles' => null,
     140                'block_markup'    => '<p>Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>',
     141                'expected_markup' => '/^<p>Hello <a href="http:\/\/www.wordpress.org\/">WordPress<\/a>!<\/p>$/',
     142            ),
     143            // @ticket 5418
    83144            'button element styles with serialization skipped' => array(
    84145                'color_settings'  => array(
Note: See TracChangeset for help on using the changeset viewer.