From d79722b09fb31f89fe473f4bfa0c5c08795182ed Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Thu, 18 Feb 2021 01:11:18 +0000 Subject: [PATCH] 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 --- .../phpunit/tests/blocks/render-reusable.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/phpunit/tests/blocks/render-reusable.php b/tests/phpunit/tests/blocks/render-reusable.php index 66b01b0428..eeea33b343 100644 --- a/tests/phpunit/tests/blocks/render-reusable.php +++ b/tests/phpunit/tests/blocks/render-reusable.php @@ -88,6 +88,38 @@ class WP_Test_Render_Reusable_Blocks extends WP_UnitTestCase { $this->assertSame( '

Hello world!

', $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( '

Hello world!

Hello world!

', $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_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() );