Make WordPress Core


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

Editor: Add further test coverage for wp_render_elements_support().

Props dmsnell, aaronrobertshaw.
Fixes #59578.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.