From c98ca19a20f3c59b8220681deebb5960a423758b Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 14 Feb 2023 03:30:58 +0000 Subject: [PATCH] Menus: Test creating parent after a child doesn't throw an error. As menus are re-arranged, it's possible a menu item was created prior to its parent. This introduces a test to ensure the order in which menu items are created relevant to their parents does not trigger errors. Props costdev, peterwilsoncc. Fixes #57122. git-svn-id: https://develop.svn.wordpress.org/trunk@55328 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 08f105be9a..298b222e01 100644 --- a/tests/phpunit/tests/menu/wp-nav-menu.php +++ b/tests/phpunit/tests/menu/wp-nav-menu.php @@ -197,4 +197,52 @@ class Tests_Menu_wpNavMenu extends WP_UnitTestCase { 'Level 3 should not be present in the HTML output.' ); } + + /** + * The order in which parent/child menu items are created should 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( + '