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
This commit is contained in:
Sergey Biryukov 2020-07-11 21:46:29 +00:00
parent d5cfd5c63c
commit a9368a89e5
2 changed files with 11 additions and 20 deletions

View File

@ -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'] = '';
}

View File

@ -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 );
}
}