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