diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContent.php b/tests/phpunit/tests/blocks/applyBlockHooksToContent.php index 22e3c6e8dffb5..963211ae4920a 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContent.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContent.php @@ -28,6 +28,15 @@ public static function wpSetUpBeforeClass() { ) ); + register_block_type( + 'tests/hooked-block-as-last-child', + array( + 'block_hooks' => array( + 'tests/anchor-block-for-child-insertion' => 'last_child', + ), + ) + ); + register_block_type( 'tests/hooked-block-with-multiple-false', array( @@ -59,6 +68,7 @@ public static function wpTearDownAfterClass() { $registry = WP_Block_Type_Registry::get_instance(); $registry->unregister( 'tests/hooked-block' ); + $registry->unregister( 'tests/hooked-block-as-last-child' ); $registry->unregister( 'tests/hooked-block-with-multiple-false' ); $registry->unregister( 'tests/dynamically-hooked-block-with-multiple-false' ); } @@ -91,6 +101,36 @@ public function test_apply_block_hooks_to_content_inserts_hooked_block() { ); } + public function test_apply_block_hooks_to_content_inserts_hooked_block_as_last_child_if_sibling_is_present() { + $block_opener = ''; + $block_closer = ''; + $sibling_block = ''; + + $context = new WP_Block_Template(); + $context->content = $block_opener . $sibling_block . $block_closer; + + $actual = apply_block_hooks_to_content( $context->content, $context, 'insert_hooked_blocks' ); + $this->assertSame( + $block_opener . $sibling_block . '' . $block_closer, + $actual + ); + } + + public function test_apply_block_hooks_to_content_inserts_hooked_block_as_last_child_if_sibling_is_classic_block() { + $block_opener = ''; + $block_closer = ''; + $sibling_block = '

Hello World!

'; + + $context = new WP_Block_Template(); + $context->content = $block_opener . $sibling_block . $block_closer; + + $actual = apply_block_hooks_to_content( $context->content, $context, 'insert_hooked_blocks' ); + $this->assertSame( + $block_opener . $sibling_block . '' . $block_closer, + $actual + ); + } + /** * @ticket 61074 */