@@ -1392,4 +1392,103 @@ public function test_wp_update_nav_menu_item_with_post_date() {
13921392 $ post = get_post ( $ menu_item_id );
13931393 $ this ->assertEqualsWithDelta ( strtotime ( gmdate ( 'Y-m-d H:i:s ' ) ), strtotime ( $ post ->post_date ), 2 , 'The dates should be equal ' );
13941394 }
1395+
1396+ /**
1397+ * Post type archive menu items should receive current_page_parent on public CPT single views.
1398+ *
1399+ * @ticket 38836
1400+ */
1401+ public function test_post_type_archive_menu_item_gets_current_page_parent_on_public_cpt_single () {
1402+ $ page_id = self ::factory ()->post ->create (
1403+ array (
1404+ 'post_type ' => 'page ' ,
1405+ 'post_title ' => 'Test Page ' ,
1406+ )
1407+ );
1408+
1409+ register_post_type (
1410+ 'cpt38836 ' ,
1411+ array (
1412+ 'public ' => true ,
1413+ 'has_archive ' => true ,
1414+ )
1415+ );
1416+
1417+ $ cpt_id = self ::factory ()->post ->create (
1418+ array (
1419+ 'post_type ' => 'cpt38836 ' ,
1420+ 'post_name ' => 'cpt-name ' ,
1421+ 'post_status ' => 'publish ' ,
1422+ )
1423+ );
1424+
1425+ wp_update_nav_menu_item (
1426+ $ this ->menu_id ,
1427+ 0 ,
1428+ array (
1429+ 'menu-item-type ' => 'post_type_archive ' ,
1430+ 'menu-item-object ' => 'cpt38836 ' ,
1431+ 'menu-item-status ' => 'publish ' ,
1432+ )
1433+ );
1434+
1435+ wp_update_nav_menu_item (
1436+ $ this ->menu_id ,
1437+ 0 ,
1438+ array (
1439+ 'menu-item-type ' => 'post_type ' ,
1440+ 'menu-item-object ' => 'page ' ,
1441+ 'menu-item-object-id ' => $ page_id ,
1442+ 'menu-item-status ' => 'publish ' ,
1443+ )
1444+ );
1445+
1446+ $ this ->go_to ( get_permalink ( $ cpt_id ) );
1447+
1448+ $ menu_items = wp_get_nav_menu_items ( $ this ->menu_id );
1449+ _wp_menu_item_classes_by_context ( $ menu_items );
1450+
1451+ $ this ->assertContains ( 'current_page_parent ' , $ menu_items [0 ]->classes , 'Archive item should be marked parent on CPT single. ' );
1452+ $ this ->assertNotContains ( 'current_page_parent ' , $ menu_items [1 ]->classes , 'Unrelated page item should not get the class. ' );
1453+ }
1454+
1455+ /**
1456+ * Non-public CPT singles should not add current_page_parent to the archive menu item.
1457+ *
1458+ * @ticket 38836
1459+ */
1460+ public function test_post_type_archive_menu_item_is_not_current_page_parent_for_non_public_cpt_single () {
1461+ register_post_type (
1462+ 'cpt38836b ' ,
1463+ array (
1464+ 'has_archive ' => true ,
1465+ )
1466+ );
1467+
1468+ $ cpt_id = self ::factory ()->post ->create (
1469+ array (
1470+ 'post_type ' => 'cpt38836b ' ,
1471+ 'post_name ' => 'cpt-name ' ,
1472+ 'post_status ' => 'publish ' ,
1473+ )
1474+ );
1475+
1476+ wp_update_nav_menu_item (
1477+ $ this ->menu_id ,
1478+ 0 ,
1479+ array (
1480+ 'menu-item-type ' => 'post_type_archive ' ,
1481+ 'menu-item-object ' => 'cpt38836b ' ,
1482+ 'menu-item-status ' => 'publish ' ,
1483+ )
1484+ );
1485+
1486+ $ this ->go_to ( get_permalink ( $ cpt_id ) );
1487+
1488+ $ menu_items = wp_get_nav_menu_items ( $ this ->menu_id );
1489+ _wp_menu_item_classes_by_context ( $ menu_items );
1490+
1491+ $ cpt_archive_classes = $ menu_items [0 ]->classes ;
1492+ $ this ->assertNotContains ( 'current_page_parent ' , $ cpt_archive_classes );
1493+ }
13951494}
0 commit comments