diff --git a/phpunit/blocks/block-navigation-block-hooks-test.php b/phpunit/blocks/block-navigation-block-hooks-test.php index ba30c2e26d25c..3cb2e785a8e11 100644 --- a/phpunit/blocks/block-navigation-block-hooks-test.php +++ b/phpunit/blocks/block-navigation-block-hooks-test.php @@ -122,4 +122,39 @@ public function test_block_core_navigation_dont_modify_no_post_id() { 'Post content did not match the original markup.' ); } + + /** + * @covers ::gutenberg_block_core_navigation_update_ignore_hooked_blocks_meta + */ + public function test_block_core_navigation_retains_content_if_not_set() { + if ( ! function_exists( 'set_ignored_hooked_blocks_metadata' ) ) { + $this->markTestSkipped( 'Test skipped on WordPress versions that do not included required Block Hooks functionality.' ); + } + + register_block_type( + 'tests/my-block', + array( + 'block_hooks' => array( + 'core/navigation' => 'last_child', + ), + ) + ); + + $post = new stdClass(); + $post->ID = self::$navigation_post->ID; + $post->post_title = 'Navigation Menu with changes'; + + $post = gutenberg_block_core_navigation_update_ignore_hooked_blocks_meta( $post ); + + $this->assertSame( + 'Navigation Menu with changes', + $post->post_title, + 'Post title was changed.' + ); + + $this->assertFalse( + isset( $post->post_content ), + 'Post content should not be set.' + ); + } }