Make WordPress Core

Changeset 48439


Ignore:
Timestamp:
07/11/2020 09:46:29 PM (6 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r48416 r48439  
    493493                }
    494494
    495                 if ( wp_unslash( $args['menu-item-title'] ) == wp_specialchars_decode( $original_title ) ) {
     495                if ( wp_unslash( $args['menu-item-title'] ) === wp_specialchars_decode( $original_title ) ) {
    496496                        $args['menu-item-title'] = '';
    497497                }
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r48416 r48439  
    417417                );
    418418
    419                 $post_inser2 = wp_update_nav_menu_item(
     419                $post_insert2 = wp_update_nav_menu_item(
    420420                        $this->menu_id,
    421421                        0,
     
    960960         * Tests `wp_update_nav_menu_item()` with special characters in a category name.
    961961         *
    962          * When inserting a category as a nav item, the `$args['menu-item-title']` should
    963          * always be empty as it should get the title from the category object itself.
     962         * When inserting a category as a nav item, the `post_title` property should
     963         * be empty, as the item should get the title from the category object itself.
    964964         *
    965965         * @ticket 48011
    966966         */
    967         function test_wp_update_nav_menu_item_with_special_character_in_categories() {
    968 
     967        function test_wp_update_nav_menu_item_with_special_characters_in_category_name() {
    969968                $category_name = 'Test Cat - \"Pre-Slashed\" Cat Name & >';
    970969
    971                 $cat = self::factory()->category->create_and_get(
     970                $category = self::factory()->category->create_and_get(
    972971                        array(
    973972                                'name' => $category_name,
     
    975974                );
    976975
    977                 add_action( 'wp_update_nav_menu_item', array( $this, 'callback_wp_update_nav_menu_item_48011' ), 10, 3 );
    978 
    979                 wp_update_nav_menu_item(
     976                $category_item_id = wp_update_nav_menu_item(
    980977                        $this->menu_id,
    981978                        0,
     
    983980                                'menu-item-type'      => 'taxonomy',
    984981                                'menu-item-object'    => 'category',
    985                                 'menu-item-object-id' => $cat->term_id,
    986                                 'menu-item-status'    => 'publish',
    987                                 /**
     982                                'menu-item-object-id' => $category->term_id,
     983                                'menu-item-status'    => 'publish',
     984                                /*
    988985                                 * Interestingly enough, if we use `$cat->name` for the menu item title,
    989986                                 * we won't be able to replicate the bug because it's in htmlentities form.
     
    992989                        )
    993990                );
    994         }
    995 
    996         /**
    997          * Callback for the `wp_update_nav_menu_item` action.
    998          *
    999          * @since 5.5.0
    1000          */
    1001         function callback_wp_update_nav_menu_item_48011( $menu_id, $menu_item_db_id, $args ) {
    1002                 $this->assertEmpty( $args['menu-item-title'] );
     991
     992                $category_item = get_post( $category_item_id );
     993                $this->assertEmpty( $category_item->post_title );
    1003994        }
    1004995}
Note: See TracChangeset for help on using the changeset viewer.