| | 526 | |
| | 527 | /** |
| | 528 | * @ticket 38836 |
| | 529 | */ |
| | 530 | function test_class_applied_to_public_custom_post_type_archive_on_single_cpt_post() { |
| | 531 | $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) ); |
| | 532 | |
| | 533 | register_post_type( 'cpt', array( 'public' => true, 'has_archive' => true ) ); |
| | 534 | $cpt_id = self::factory()->post->create( array( 'post_type' => 'cpt', 'post_name' => 'cpt-name' ) ); |
| | 535 | |
| | 536 | wp_update_nav_menu_item( $this->menu_id, 0, array( |
| | 537 | 'menu-item-type' => 'post_type_archive', |
| | 538 | 'menu-item-object' => 'cpt', |
| | 539 | 'menu-item-status' => 'publish', |
| | 540 | ) ); |
| | 541 | |
| | 542 | wp_update_nav_menu_item( $this->menu_id, 0, array( |
| | 543 | 'menu-item-type' => 'post_type', |
| | 544 | 'menu-item-object' => 'page', |
| | 545 | 'menu-item-object-id' => $page_id, |
| | 546 | 'menu-item-status' => 'publish', |
| | 547 | ) ); |
| | 548 | |
| | 549 | $permalink = get_permalink( $cpt_id ); |
| | 550 | $this->go_to( $permalink ); |
| | 551 | |
| | 552 | $menu_items = wp_get_nav_menu_items( $this->menu_id ); |
| | 553 | _wp_menu_item_classes_by_context( $menu_items ); |
| | 554 | |
| | 555 | $cptarchive_classes = $menu_items[0]->classes; |
| | 556 | $testpage_classes = $menu_items[1]->classes; |
| | 557 | |
| | 558 | $this->assertContains( 'current_page_parent', $cptarchive_classes ); |
| | 559 | $this->assertNotContains( 'current_page_parent', $testpage_classes ); |
| | 560 | } |
| | 561 | |
| | 562 | /** |
| | 563 | * @ticket 38836 |
| | 564 | */ |
| | 565 | function test_class_not_applied_to_custom_post_type_archive_on_single_cpt_post() { |
| | 566 | register_post_type( 'cpt', array( 'has_archive' => true ) ); |
| | 567 | $cpt_id = self::factory()->post->create( array( 'post_type' => 'cpt', 'post_name' => 'cpt-name' ) ); |
| | 568 | |
| | 569 | wp_update_nav_menu_item( $this->menu_id, 0, array( |
| | 570 | 'menu-item-type' => 'post_type_archive', |
| | 571 | 'menu-item-object' => 'cpt', |
| | 572 | 'menu-item-status' => 'publish', |
| | 573 | ) ); |
| | 574 | |
| | 575 | $permalink = get_permalink( $cpt_id ); |
| | 576 | $this->go_to( $permalink ); |
| | 577 | |
| | 578 | $menu_items = wp_get_nav_menu_items( $this->menu_id ); |
| | 579 | _wp_menu_item_classes_by_context( $menu_items ); |
| | 580 | |
| | 581 | $cptarchive_classes = $menu_items[0]->classes; |
| | 582 | |
| | 583 | $this->assertNotContains( 'current_page_parent', $cptarchive_classes ); |
| | 584 | } |