From a9368a89e527e9857245381e1047fc97148708c9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 11 Jul 2020 21:46:29 +0000 Subject: [PATCH] Menus: Simplify the test for `wp_update_nav_menu_item()` with special characters in category name. The `menu-item-title` value is saved as a `post_title` property, so the resulting property can be checked directly, without a callback. Follow-up to [48416]. See #48011. git-svn-id: https://develop.svn.wordpress.org/trunk@48439 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/nav-menu.php | 2 +- tests/phpunit/tests/post/nav-menu.php | 29 +++++++++------------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 6f4d8c807b..36697f1ee9 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -492,7 +492,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item } } - if ( wp_unslash( $args['menu-item-title'] ) == wp_specialchars_decode( $original_title ) ) { + if ( wp_unslash( $args['menu-item-title'] ) === wp_specialchars_decode( $original_title ) ) { $args['menu-item-title'] = ''; } diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index c944b14f03..7ae35e34d9 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -416,7 +416,7 @@ class Test_Nav_Menus extends WP_UnitTestCase { ) ); - $post_inser2 = wp_update_nav_menu_item( + $post_insert2 = wp_update_nav_menu_item( $this->menu_id, 0, array( @@ -959,46 +959,37 @@ class Test_Nav_Menus extends WP_UnitTestCase { /** * Tests `wp_update_nav_menu_item()` with special characters in a category name. * - * When inserting a category as a nav item, the `$args['menu-item-title']` should - * always be empty as it should get the title from the category object itself. + * When inserting a category as a nav item, the `post_title` property should + * be empty, as the item should get the title from the category object itself. * * @ticket 48011 */ - function test_wp_update_nav_menu_item_with_special_character_in_categories() { - + function test_wp_update_nav_menu_item_with_special_characters_in_category_name() { $category_name = 'Test Cat - \"Pre-Slashed\" Cat Name & >'; - $cat = self::factory()->category->create_and_get( + $category = self::factory()->category->create_and_get( array( 'name' => $category_name, ) ); - add_action( 'wp_update_nav_menu_item', array( $this, 'callback_wp_update_nav_menu_item_48011' ), 10, 3 ); - - wp_update_nav_menu_item( + $category_item_id = wp_update_nav_menu_item( $this->menu_id, 0, array( 'menu-item-type' => 'taxonomy', 'menu-item-object' => 'category', - 'menu-item-object-id' => $cat->term_id, + 'menu-item-object-id' => $category->term_id, 'menu-item-status' => 'publish', - /** + /* * Interestingly enough, if we use `$cat->name` for the menu item title, * we won't be able to replicate the bug because it's in htmlentities form. */ 'menu-item-title' => $category_name, ) ); - } - /** - * Callback for the `wp_update_nav_menu_item` action. - * - * @since 5.5.0 - */ - function callback_wp_update_nav_menu_item_48011( $menu_id, $menu_item_db_id, $args ) { - $this->assertEmpty( $args['menu-item-title'] ); + $category_item = get_post( $category_item_id ); + $this->assertEmpty( $category_item->post_title ); } }