- Timestamp:
- 11/30/2016 11:35:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php
r39365 r39393 812 812 $setting->preview(); 813 813 814 $item_value = $setting->value(); 815 $this->assertArrayHasKey( 'type_label', $item_value ); 814 816 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); 815 817 $this->assertEquals( 'Custom Link', $nav_menu_item->type_label ); 818 $this->assertEquals( $item_value['type_label'], $nav_menu_item->type_label ); 816 819 add_filter( 'wp_setup_nav_menu_item', array( $this, 'filter_type_label' ) ); 817 820 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); … … 896 899 897 900 /** 901 * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() for obtaining original title. 902 * 903 * @ticket 38945 904 * @covers WP_Customize_Nav_Menu_Item_Setting::get_original_title() 905 */ 906 function test_get_original_title() { 907 $menu_id = wp_create_nav_menu( 'Menu' ); 908 register_post_type( 'press_release', array( 909 'has_archive' => true, 910 'labels' => array( 911 'name' => 'PRs', 912 'singular_name' => 'PR', 913 'archives' => 'All PRs', 914 ), 915 ) ); 916 $original_post_title = 'The PR Post'; 917 $post_id = self::factory()->post->create( array( 'post_type' => 'press_release', 'post_title' => $original_post_title ) ); 918 $original_term_title = 'The Category Term'; 919 $term_id = self::factory()->term->create( array( 'taxonomy' => 'category', 'name' => $original_term_title ) ); 920 921 // Post: existing nav menu item. 922 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 923 'menu-item-object-id' => $post_id, 924 'menu-item-type' => 'post_type', 925 'menu-item-object' => 'press_release', 926 'menu-item-title' => '', 927 'menu-item-status' => 'publish', 928 ) ); 929 $setting = new WP_Customize_Nav_Menu_Item_Setting( 930 $this->wp_customize, 931 'nav_menu_item[' . $nav_menu_item_id . ']' 932 ); 933 $item_value = $setting->value(); 934 $this->assertEquals( $original_post_title, $item_value['original_title'] ); 935 $this->assertEquals( '', $item_value['title'] ); 936 $item = $setting->value_as_wp_post_nav_menu_item(); 937 $this->assertObjectHasAttribute( 'type_label', $item ); 938 $this->assertEquals( $original_post_title, $item->original_title ); 939 $this->assertEquals( $original_post_title, $item->title ); 940 $this->assertArrayHasKey( 'type_label', $item_value ); 941 $this->assertEquals( get_post_type_object( 'press_release' )->labels->singular_name, $item_value['type_label'] ); 942 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 943 944 // Post: staged nav menu item. 945 $setting = new WP_Customize_Nav_Menu_Item_Setting( 946 $this->wp_customize, 947 'nav_menu_item[-1]' 948 ); 949 $this->wp_customize->set_post_value( $setting->id, array( 950 'object_id' => $post_id, 951 'type' => 'post_type', 952 'object' => 'press_release', 953 'title' => '', 954 'status' => 'publish', 955 ) ); 956 $setting->preview(); 957 $item_value = $setting->value(); 958 $this->assertEquals( $original_post_title, $item_value['original_title'] ); 959 $this->assertEquals( '', $item_value['title'] ); 960 $item = $setting->value_as_wp_post_nav_menu_item(); 961 $this->assertObjectHasAttribute( 'type_label', $item ); 962 $this->assertEquals( $original_post_title, $item->original_title ); 963 $this->assertEquals( $original_post_title, $item->title ); 964 $this->assertArrayHasKey( 'type_label', $item_value ); 965 $this->assertEquals( get_post_type_object( 'press_release' )->labels->singular_name, $item_value['type_label'] ); 966 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 967 968 // Term: existing nav menu item. 969 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 970 'menu-item-object-id' => $term_id, 971 'menu-item-type' => 'taxonomy', 972 'menu-item-object' => 'category', 973 'menu-item-title' => '', 974 'menu-item-status' => 'publish', 975 ) ); 976 $setting = new WP_Customize_Nav_Menu_Item_Setting( 977 $this->wp_customize, 978 'nav_menu_item[' . $nav_menu_item_id . ']' 979 ); 980 $item_value = $setting->value(); 981 $this->assertEquals( $original_term_title, $item_value['original_title'] ); 982 $this->assertEquals( '', $item_value['title'] ); 983 $item = $setting->value_as_wp_post_nav_menu_item(); 984 $this->assertObjectHasAttribute( 'type_label', $item ); 985 $this->assertEquals( $original_term_title, $item->original_title ); 986 $this->assertEquals( $original_term_title, $item->title ); 987 $this->assertArrayHasKey( 'type_label', $item_value ); 988 $this->assertEquals( get_taxonomy( 'category' )->labels->singular_name, $item_value['type_label'] ); 989 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 990 991 // Term: staged nav menu item. 992 $setting = new WP_Customize_Nav_Menu_Item_Setting( 993 $this->wp_customize, 994 'nav_menu_item[-2]' 995 ); 996 $this->wp_customize->set_post_value( $setting->id, array( 997 'object_id' => $term_id, 998 'type' => 'taxonomy', 999 'object' => 'category', 1000 'title' => '', 1001 'status' => 'publish', 1002 ) ); 1003 $setting->preview(); 1004 $item_value = $setting->value(); 1005 $this->assertEquals( $original_term_title, $item_value['original_title'] ); 1006 $this->assertEquals( '', $item_value['title'] ); 1007 $item = $setting->value_as_wp_post_nav_menu_item(); 1008 $this->assertObjectHasAttribute( 'type_label', $item ); 1009 $this->assertEquals( $original_term_title, $item->original_title ); 1010 $this->assertEquals( $original_term_title, $item->title ); 1011 $this->assertArrayHasKey( 'type_label', $item_value ); 1012 $this->assertEquals( get_taxonomy( 'category' )->labels->singular_name, $item_value['type_label'] ); 1013 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 1014 1015 // Post Type Archive: existing nav menu item. 1016 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 1017 'menu-item-type' => 'post_type_archive', 1018 'menu-item-object' => 'press_release', 1019 'menu-item-title' => '', 1020 'menu-item-status' => 'publish', 1021 ) ); 1022 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1023 $this->wp_customize, 1024 'nav_menu_item[' . $nav_menu_item_id . ']' 1025 ); 1026 $item_value = $setting->value(); 1027 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] ); 1028 $this->assertEquals( '', $item_value['title'] ); 1029 $item = $setting->value_as_wp_post_nav_menu_item(); 1030 $this->assertObjectHasAttribute( 'type_label', $item ); 1031 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->original_title ); 1032 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->title ); 1033 $this->assertArrayHasKey( 'type_label', $item_value ); 1034 $this->assertEquals( __( 'Post Type Archive' ), $item_value['type_label'] ); 1035 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 1036 1037 // Post Type Archive: staged nav menu item. 1038 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1039 $this->wp_customize, 1040 'nav_menu_item[-3]' 1041 ); 1042 $this->wp_customize->set_post_value( $setting->id, array( 1043 'type' => 'post_type_archive', 1044 'object' => 'press_release', 1045 'title' => '', 1046 'status' => 'publish', 1047 ) ); 1048 $setting->preview(); 1049 $item_value = $setting->value(); 1050 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] ); 1051 $this->assertEquals( '', $item_value['title'] ); 1052 $item = $setting->value_as_wp_post_nav_menu_item(); 1053 $this->assertObjectHasAttribute( 'type_label', $item ); 1054 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->original_title ); 1055 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->title ); 1056 $this->assertArrayHasKey( 'type_label', $item_value ); 1057 $this->assertEquals( __( 'Post Type Archive' ), $item_value['type_label'] ); 1058 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 1059 } 1060 1061 /** 898 1062 * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() where title is empty. 899 1063 *
Note: See TracChangeset
for help on using the changeset viewer.