Editor: Additional tests for reusable blocks.

Ensure that subsequent renders of a reusable block will render correctly and that recursively inserting a reusable block into itself does not cause an internal server (500) error.

Props bernhard-reiter, SergeyBiryukov.
Fixes #52364.



git-svn-id: https://develop.svn.wordpress.org/trunk@50382 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2021-02-18 01:11:18 +00:00
parent e686cb1b0e
commit d79722b09f

View File

@ -88,6 +88,38 @@ class WP_Test_Render_Reusable_Blocks extends WP_UnitTestCase {
$this->assertSame( '<p>Hello world!</p>', $output );
}
/**
* Make sure that a reusable block can be rendered twice in a row.
*
* @ticket 52364
*/
public function test_render_subsequent() {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/block' );
$output = $block_type->render( array( 'ref' => self::$block_id ) );
$output .= $block_type->render( array( 'ref' => self::$block_id ) );
$this->assertSame( '<p>Hello world!</p><p>Hello world!</p>', $output );
}
/**
* Throw a warning if blocks are recursively nested.
*
* @ticket 52364
*/
public function test_recursive_render_warning() {
$recursive_reusable_block = array(
'ID' => self::$block_id,
'post_content' => '<!-- wp:block {"ref":' . self::$block_id . '} /-->',
);
wp_update_post( $recursive_reusable_block );
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/block' );
// The block_render method for `core/block` triggers a user warning if it
// encounters a recursively nested block.
$this->expectException( 'PHPUnit_Framework_Error_Warning' );
$block_type->render( array( 'ref' => self::$block_id ) );
}
public function test_ref_empty() {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/block' );
$output = $block_type->render( array() );