| 959 | /** |
| 960 | * @ticket 38836 |
| 961 | */ |
| 962 | function test_class_applied_to_public_custom_post_type_archive_on_single_cpt_post() { |
| 963 | $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) ); |
| 964 | |
| 965 | register_post_type( 'cpt', array( 'public' => true, 'has_archive' => true ) ); |
| 966 | $cpt_id = self::factory()->post->create( array( 'post_type' => 'cpt', 'post_name' => 'cpt-name' ) ); |
| 967 | |
| 968 | wp_update_nav_menu_item( $this->menu_id, 0, array( |
| 969 | 'menu-item-type' => 'post_type_archive', |
| 970 | 'menu-item-object' => 'cpt', |
| 971 | 'menu-item-status' => 'publish', |
| 972 | ) ); |
| 973 | |
| 974 | wp_update_nav_menu_item( $this->menu_id, 0, array( |
| 975 | 'menu-item-type' => 'post_type', |
| 976 | 'menu-item-object' => 'page', |
| 977 | 'menu-item-object-id' => $page_id, |
| 978 | 'menu-item-status' => 'publish', |
| 979 | ) ); |
| 980 | |
| 981 | $permalink = get_permalink( $cpt_id ); |
| 982 | $this->go_to( $permalink ); |
| 983 | |
| 984 | $menu_items = wp_get_nav_menu_items( $this->menu_id ); |
| 985 | _wp_menu_item_classes_by_context( $menu_items ); |
| 986 | |
| 987 | $cptarchive_classes = $menu_items[0]->classes; |
| 988 | $testpage_classes = $menu_items[1]->classes; |
| 989 | |
| 990 | $this->assertContains( 'current_page_parent', $cptarchive_classes ); |
| 991 | $this->assertNotContains( 'current_page_parent', $testpage_classes ); |
| 992 | } |
| 993 | |
| 994 | /** |
| 995 | * @ticket 38836 |
| 996 | */ |
| 997 | function test_class_not_applied_to_custom_post_type_archive_on_single_cpt_post() { |
| 998 | register_post_type( 'cpt', array( 'has_archive' => true ) ); |
| 999 | |
| 1000 | $cpt_id = self::factory()->post->create( |
| 1001 | array( |
| 1002 | 'post_type' => 'cpt', |
| 1003 | 'post_name' => 'cpt-name' |
| 1004 | ) |
| 1005 | ); |
| 1006 | |
| 1007 | wp_update_nav_menu_item( $this->menu_id, 0, array( |
| 1008 | 'menu-item-type' => 'post_type_archive', |
| 1009 | 'menu-item-object' => 'cpt', |
| 1010 | 'menu-item-status' => 'publish', |
| 1011 | ) ); |
| 1012 | |
| 1013 | $permalink = get_permalink( $cpt_id ); |
| 1014 | $this->go_to( $permalink ); |
| 1015 | |
| 1016 | $menu_items = wp_get_nav_menu_items( $this->menu_id ); |
| 1017 | _wp_menu_item_classes_by_context( $menu_items ); |
| 1018 | |
| 1019 | $cptarchive_classes = $menu_items[0]->classes; |
| 1020 | $this->assertNotContains( 'current_page_parent', $cptarchive_classes ); |
| 1021 | } |
| 1022 | |