Skip to content

Commit

Permalink
Editor: Add further test coverage for wp_render_elements_support().
Browse files Browse the repository at this point in the history
Props dmsnell, aaronrobertshaw.
Fixes #59578.


git-svn-id: https://develop.svn.wordpress.org/trunk@56828 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
felixarntz committed Oct 11, 2023
1 parent ce8aed4 commit bb4ab81
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/wp-includes/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function wp_render_elements_support( $block_content, $block ) {
}

$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
if ( ! $block_type ) {
return $block_content;
}

$element_color_properties = array(
'button' => array(
Expand Down
63 changes: 62 additions & 1 deletion tests/phpunit/tests/block-supports/wpRenderElementsSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@ public function tear_down() {
parent::tear_down();
}

/**
* Tests that block supports leaves block content alone if the block type
* isn't registered.
*
* @ticket 59578
*
* @covers ::wp_render_elements_support
*
* @return void
*/
public function test_leaves_block_content_alone_when_block_type_not_registered() {
$block = array(
'blockName' => 'test/element-block-supports',
'attrs' => array(
'style' => array(
'elements' => array(
'button' => array(
'color' => array(
'text' => 'var:preset|color|vivid-red',
'background' => '#fff',
),
),
),
),
),
);

$block_markup = '<p>Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>';
$actual = wp_render_elements_support( $block_markup, $block );

$this->assertSame( $block_markup, $actual, 'Expected to leave block content unmodified, but found changes.' );
}

/**
* Tests that elements block support applies the correct classname.
*
Expand Down Expand Up @@ -64,7 +97,7 @@ public function test_elements_block_support_class( $color_settings, $elements_st
$this->assertMatchesRegularExpression(
$expected_markup,
$actual,
'Position block wrapper markup should be correct'
'Block wrapper markup should be correct'
);
}

Expand All @@ -80,6 +113,34 @@ public function data_elements_block_support_class() {
);

return array(
// @ticket 59578
'empty block markup remains untouched' => array(
'color_settings' => array(
'button' => true,
),
'elements_styles' => array(
'button' => array( 'color' => $color_styles ),
),
'block_markup' => '',
'expected_markup' => '/^$/',
),
'empty block markup remains untouched when no block attributes' => array(
'color_settings' => array(
'button' => true,
),
'elements_styles' => null,
'block_markup' => '',
'expected_markup' => '/^$/',
),
'block markup remains untouched when block has no attributes' => array(
'color_settings' => array(
'button' => true,
),
'elements_styles' => null,
'block_markup' => '<p>Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>',
'expected_markup' => '/^<p>Hello <a href="http:\/\/www.wordpress.org\/">WordPress<\/a>!<\/p>$/',
),
// @ticket 5418
'button element styles with serialization skipped' => array(
'color_settings' => array(
'button' => true,
Expand Down

0 comments on commit bb4ab81

Please sign in to comment.