From 2363f7fe1acc6035c1460e42303928f453875f17 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 26 Mar 2024 09:12:52 +0100 Subject: [PATCH] Navigation Block: Verify that content is not removed when renaming the nav menu --- .../block-navigation-block-hooks-test.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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.' + ); + } }