Make WordPress Core

Ticket #35272: 35272.4.diff

File 35272.4.diff, 2.3 KB (added by welcher, 9 years ago)

Adds unit tests and small fix

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

     
    334334        $possible_object_parents = array_filter( $possible_object_parents );
    335335
    336336        $front_page_url = home_url();
     337        $front_page_id  = (int) get_option( 'page_on_front' );
    337338
    338339        foreach ( (array) $menu_items as $key => $menu_item ) {
    339340
     
    344345                $classes[] = 'menu-item-type-' . $menu_item->type;
    345346                $classes[] = 'menu-item-object-' . $menu_item->object;
    346347
     348                // This menu item is set as the 'Front Page'.
     349                if ( $front_page_id === (int) $menu_item->object_id ) {
     350                        $classes[] = 'menu-item-home';
     351                }
     352
    347353                // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
    348354                if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
    349355                        $active_parent_object_ids[] = (int) $menu_item->object_id;
     
    377383                                $classes[] = 'current_page_item';
    378384                        }
    379385
    380                         if ( 'page_on_front' ) {
    381                                 $classes[] = 'menu-item-home';
    382                         }
    383 
    384386                        $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
    385387                        $active_parent_object_ids[] = (int) $menu_item->post_parent;
    386388                        $active_object = $menu_item->object;
  • tests/phpunit/tests/post/nav-menu.php

     
    444444                $this->assertTrue( is_object( $args ) );
    445445                return $ignored_1;
    446446        }
     447
     448
     449        /**
     450         * @ticket 35272
     451         */
     452        function test_class_applied_to_front_page_item() {
     453
     454                $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Home Page' ) );
     455                update_option( 'page_on_front', $page_id );
     456
     457                wp_update_nav_menu_item( $this->menu_id, 0, array(
     458                        'menu-item-type' => 'post_type',
     459                        'menu-item-object' => 'page',
     460                        'menu-item-object-id' => $page_id,
     461                        'menu-item-status' => 'publish',
     462                ));
     463
     464                $menu_items = wp_get_nav_menu_items( $this->menu_id );
     465                _wp_menu_item_classes_by_context( $menu_items );
     466
     467                $classes = $menu_items[0]->classes;
     468
     469                $this->assertContains( 'menu-item-home', $classes );
     470        }
    447471}