From 6467467bd27fe7203a3246524ed302495466e3a0 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Wed, 16 Nov 2022 14:38:11 +1100 Subject: [PATCH 1/2] Test for #57122. --- tests/phpunit/tests/menu/wp-nav-menu.php | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/phpunit/tests/menu/wp-nav-menu.php b/tests/phpunit/tests/menu/wp-nav-menu.php index 08f105be9a76..a4460f577839 100644 --- a/tests/phpunit/tests/menu/wp-nav-menu.php +++ b/tests/phpunit/tests/menu/wp-nav-menu.php @@ -197,4 +197,52 @@ public function test_wp_nav_menu_should_not_have_has_children_class_with_custom_ 'Level 3 should not be present in the HTML output.' ); } + + /** + * Test that the order in which menu items are created does not matter. + * + * @ticket 57122 + */ + public function test_parent_with_higher_id_should_not_error() { + // Create a new level zero menu item. + $new_lvl0_menu_item = wp_update_nav_menu_item( + self::$menu_id, + 0, + array( + 'menu-item-title' => 'Root menu item with high ID', + 'menu-item-url' => '#', + 'menu-item-status' => 'publish', + ) + ); + + // Reparent level 1 menu item to the new level zero menu item. + self::$lvl1_menu_item = wp_update_nav_menu_item( + self::$menu_id, + self::$lvl1_menu_item, + array( + 'menu-item-parent-id' => $new_lvl0_menu_item, + ) + ); + + // Delete the old level zero menu item. + wp_delete_post( self::$lvl0_menu_item, true ); + + // Render the menu. + $menu_html = wp_nav_menu( + array( + 'menu' => self::$menu_id, + 'echo' => false, + ) + ); + + $this->assertStringContainsString( + sprintf( + '