Make WordPress Core


Ignore:
Timestamp:
02/24/2018 01:43:07 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Menus: When checking if a Custom Link matches the current URL to add the current-menu-item class, check for decoded URL as well.

Props soulseekah, campusboy1987.
Fixes #43401.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r42636 r42732  
    763763    }
    764764
     765    /**
     766     * Provides IRI matching data for _wp_menu_item_classes_by_context() test.
     767     */
     768    function get_iri_current_menu_items() {
     769        return array(
     770            array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ) ),
     771            array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ) ),
     772            array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ),
     773            array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ),
     774            array( '/привет/' ),
     775            array( '/привет' ),
     776        );
     777    }
     778
     779    /**
     780     * @ticket 43401
     781     * @dataProvider get_iri_current_menu_items
     782     */
     783    function test_iri_current_menu_item( $custom_link, $current = true ) {
     784        wp_update_nav_menu_item(
     785            $this->menu_id, 0, array(
     786                'menu-item-status' => 'publish',
     787                'menu-item-type'   => 'custom',
     788                'menu-item-url'    => $custom_link,
     789            )
     790        );
     791
     792        $this->go_to( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ) );
     793
     794        $menu_items = wp_get_nav_menu_items( $this->menu_id );
     795        _wp_menu_item_classes_by_context( $menu_items );
     796
     797        $classes = $menu_items[0]->classes;
     798
     799        if ( $current ) {
     800            $this->assertContains( 'current-menu-item', $classes );
     801        } else {
     802            $this->assertNotContains( 'current-menu-item', $classes );
     803        }
     804    }
     805
    765806}
Note: See TracChangeset for help on using the changeset viewer.