Make WordPress Core

Ticket #39800: 39800.diff

File 39800.diff, 3.7 KB (added by welcher, 6 years ago)

File cleanup and remove @group reference

  • src/wp-includes/nav-menu-template.php

    diff --git src/wp-includes/nav-menu-template.php src/wp-includes/nav-menu-template.php
    index 737d6e6..ea7c22d 100644
    function _wp_menu_item_classes_by_context( &$menu_items ) { 
    394394                ) {
    395395                        $classes[] = 'current-menu-item';
    396396                        $menu_items[$key]->current = true;
     397
     398                        $_anc_id = (int) $menu_item->db_id;
     399
     400                        while(
     401                                ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
     402                                ! in_array( $_anc_id, $active_ancestor_item_ids, true )
     403                        ) {
     404                                $active_ancestor_item_ids[] = $_anc_id;
     405                        }
     406
     407                        $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
     408
    397409                // if the menu item corresponds to the currently-requested URL
    398410                } elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
    399411                        $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
  • tests/phpunit/tests/post/nav-menu.php

    diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
    index c6a028c..d0496a1 100644
    class Test_Nav_Menus extends WP_UnitTestCase { 
    553553                $this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) );
    554554                $this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) );
    555555        }
     556       
     557       
     558        /**
     559         * @ticket 39800
     560         */
     561        function test_parent_ancestor_for_post_archive() {
     562
     563                register_post_type( 'books', array( 'label' => 'Books', 'public' => true, 'has_archive' => true ) );
     564
     565                $first_page_id  = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Top Level Page') );
     566                $second_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Second Level Page') );
     567
     568
     569                $first_menu_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
     570                        'menu-item-type'      => 'post_type',
     571                        'menu-item-object'    => 'page',
     572                        'menu-item-object-id' => $first_page_id,
     573                        'menu-item-status'    => 'publish',
     574                ));
     575
     576                $second_menu_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
     577                        'menu-item-type'      => 'post_type',
     578                        'menu-item-object'    => 'page',
     579                        'menu-item-object-id' => $second_page_id,
     580                        'menu-item-status'    => 'publish',
     581                        'menu-item-parent-id' => $first_menu_id
     582                ));
     583
     584                wp_update_nav_menu_item( $this->menu_id, 0, array(
     585                        'menu-item-type'      => 'post_type_archive',
     586                        'menu-item-object'    => 'books',
     587                        'menu-item-status'    => 'publish',
     588                        'menu-item-parent-id' => $second_menu_id
     589                ));
     590
     591                $this->go_to( get_post_type_archive_link( 'books') );
     592
     593                $menu_items = wp_get_nav_menu_items( $this->menu_id );
     594                _wp_menu_item_classes_by_context( $menu_items );
     595
     596                $top_page_menu_item       = $menu_items[0];
     597                $secondary_page_menu_item = $menu_items[1];
     598                $post_archive_menu_item   = $menu_items[2];
     599
     600                $this->assertFalse( $top_page_menu_item->current_item_parent );
     601                $this->assertTrue( $top_page_menu_item->current_item_ancestor );
     602                $this->assertContains( 'current-menu-ancestor', $top_page_menu_item->classes );
     603
     604                $this->assertTrue( $secondary_page_menu_item->current_item_parent );
     605                $this->assertTrue( $secondary_page_menu_item->current_item_ancestor  );
     606                $this->assertContains( 'current-menu-parent', $secondary_page_menu_item->classes );
     607                $this->assertContains( 'current-menu-ancestor', $secondary_page_menu_item->classes );
     608
     609                $this->assertFalse( $post_archive_menu_item->current_item_parent );
     610                $this->assertFalse( $post_archive_menu_item->current_item_ancestor  );
     611
     612                $this->assertNotContains( 'current-menu-parent', $post_archive_menu_item->classes );
     613                $this->assertNotContains( 'current-menu-ancestor', $post_archive_menu_item->classes );
     614        }
    556615}