mirror of
git://develop.git.wordpress.org/
synced 2025-04-13 08:32:10 +02:00
Editor: Add further test coverage for wp_render_elements_support()
.
Props dmsnell, aaronrobertshaw. Fixes #59578. git-svn-id: https://develop.svn.wordpress.org/trunk@56828 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ce8aed4698
commit
bb4ab816b5
@ -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(
|
||||
|
@ -18,6 +18,39 @@ class Tests_Block_Supports_WpRenderElementsSupport extends WP_UnitTestCase {
|
||||
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.
|
||||
*
|
||||
@ -64,7 +97,7 @@ class Tests_Block_Supports_WpRenderElementsSupport extends WP_UnitTestCase {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected_markup,
|
||||
$actual,
|
||||
'Position block wrapper markup should be correct'
|
||||
'Block wrapper markup should be correct'
|
||||
);
|
||||
}
|
||||
|
||||
@ -80,6 +113,34 @@ class Tests_Block_Supports_WpRenderElementsSupport extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user