| 995 | |
| 996 | /** |
| 997 | * Test passed post_date/post_date_gmt. |
| 998 | * |
| 999 | * When inserting a nav menu item, it should be possible to set the post_date |
| 1000 | * of it to ensure that this data is maintained during an import. |
| 1001 | * |
| 1002 | * @ticket 52189 |
| 1003 | */ |
| 1004 | function test_wp_update_nav_menu_item_with_post_date() { |
| 1005 | $post_date = '2020-12-28 11:26:35'; |
| 1006 | $post_date_gmt = '2020-12-29 10:11:45'; |
| 1007 | $invalid_date = '2020-12-41 14:15:27'; |
| 1008 | |
| 1009 | $post_id = self::factory()->post->create( |
| 1010 | array( |
| 1011 | 'post_status' => 'publish', |
| 1012 | ) |
| 1013 | ); |
| 1014 | |
| 1015 | $menu_item_id = wp_update_nav_menu_item( |
| 1016 | $this->menu_id, |
| 1017 | 0, |
| 1018 | array( |
| 1019 | 'menu-item-type' => 'post_type', |
| 1020 | 'menu-item-object' => 'post', |
| 1021 | 'menu-item-object-id' => $post_id, |
| 1022 | 'menu-item-status' => 'publish', |
| 1023 | ) |
| 1024 | ); |
| 1025 | $post = get_post( $menu_item_id ); |
| 1026 | $this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| 1027 | |
| 1028 | $menu_item_id = wp_update_nav_menu_item( |
| 1029 | $this->menu_id, |
| 1030 | 0, |
| 1031 | array( |
| 1032 | 'menu-item-type' => 'post_type', |
| 1033 | 'menu-item-object' => 'post', |
| 1034 | 'menu-item-object-id' => $post_id, |
| 1035 | 'menu-item-status' => 'publish', |
| 1036 | 'menu-item-post-date-gmt' => $post_date_gmt, |
| 1037 | ) |
| 1038 | ); |
| 1039 | $post = get_post( $menu_item_id ); |
| 1040 | $this->assertEquals( get_date_from_gmt( $post_date_gmt ), $post->post_date ); |
| 1041 | |
| 1042 | $menu_item_id = wp_update_nav_menu_item( |
| 1043 | $this->menu_id, |
| 1044 | 0, |
| 1045 | array( |
| 1046 | 'menu-item-type' => 'post_type', |
| 1047 | 'menu-item-object' => 'post', |
| 1048 | 'menu-item-object-id' => $post_id, |
| 1049 | 'menu-item-status' => 'publish', |
| 1050 | 'menu-item-post-date-gmt' => $invalid_date, |
| 1051 | ) |
| 1052 | ); |
| 1053 | $post = get_post( $menu_item_id ); |
| 1054 | $this->assertEquals( '1970-01-01 00:00:00', $post->post_date ); |
| 1055 | |
| 1056 | $menu_item_id = wp_update_nav_menu_item( |
| 1057 | $this->menu_id, |
| 1058 | 0, |
| 1059 | array( |
| 1060 | 'menu-item-type' => 'post_type', |
| 1061 | 'menu-item-object' => 'post', |
| 1062 | 'menu-item-object-id' => $post_id, |
| 1063 | 'menu-item-status' => 'publish', |
| 1064 | 'menu-item-post-date' => $post_date, |
| 1065 | ) |
| 1066 | ); |
| 1067 | $post = get_post( $menu_item_id ); |
| 1068 | $this->assertEquals( $post_date, $post->post_date ); |
| 1069 | |
| 1070 | $menu_item_id = wp_update_nav_menu_item( |
| 1071 | $this->menu_id, |
| 1072 | 0, |
| 1073 | array( |
| 1074 | 'menu-item-type' => 'post_type', |
| 1075 | 'menu-item-object' => 'post', |
| 1076 | 'menu-item-object-id' => $post_id, |
| 1077 | 'menu-item-status' => 'publish', |
| 1078 | 'menu-item-post-date' => $post_date, |
| 1079 | 'menu-item-post-date-gmt' => $post_date_gmt, |
| 1080 | ) |
| 1081 | ); |
| 1082 | $post = get_post( $menu_item_id ); |
| 1083 | $this->assertEquals( $post_date, $post->post_date ); |
| 1084 | |
| 1085 | $menu_item_id = wp_update_nav_menu_item( |
| 1086 | $this->menu_id, |
| 1087 | 0, |
| 1088 | array( |
| 1089 | 'menu-item-type' => 'post_type', |
| 1090 | 'menu-item-object' => 'post', |
| 1091 | 'menu-item-object-id' => $post_id, |
| 1092 | 'menu-item-status' => 'publish', |
| 1093 | 'menu-item-post-date' => $post_date, |
| 1094 | 'menu-item-post-date-gmt' => $invalid_date, |
| 1095 | ) |
| 1096 | ); |
| 1097 | $post = get_post( $menu_item_id ); |
| 1098 | $this->assertEquals( $post_date, $post->post_date ); |
| 1099 | |
| 1100 | $menu_item_id = wp_update_nav_menu_item( |
| 1101 | $this->menu_id, |
| 1102 | 0, |
| 1103 | array( |
| 1104 | 'menu-item-type' => 'post_type', |
| 1105 | 'menu-item-object' => 'post', |
| 1106 | 'menu-item-object-id' => $post_id, |
| 1107 | 'menu-item-status' => 'publish', |
| 1108 | 'menu-item-post-date' => $invalid_date, |
| 1109 | ) |
| 1110 | ); |
| 1111 | $post = get_post( $menu_item_id ); |
| 1112 | $this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| 1113 | |
| 1114 | $menu_item_id = wp_update_nav_menu_item( |
| 1115 | $this->menu_id, |
| 1116 | 0, |
| 1117 | array( |
| 1118 | 'menu-item-type' => 'post_type', |
| 1119 | 'menu-item-object' => 'post', |
| 1120 | 'menu-item-object-id' => $post_id, |
| 1121 | 'menu-item-status' => 'publish', |
| 1122 | 'menu-item-post-date' => $invalid_date, |
| 1123 | 'menu-item-post-date-gmt' => $post_date_gmt, |
| 1124 | ) |
| 1125 | ); |
| 1126 | $post = get_post( $menu_item_id ); |
| 1127 | $this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| 1128 | |
| 1129 | $menu_item_id = wp_update_nav_menu_item( |
| 1130 | $this->menu_id, |
| 1131 | 0, |
| 1132 | array( |
| 1133 | 'menu-item-type' => 'post_type', |
| 1134 | 'menu-item-object' => 'post', |
| 1135 | 'menu-item-object-id' => $post_id, |
| 1136 | 'menu-item-status' => 'publish', |
| 1137 | 'menu-item-post-date' => $invalid_date, |
| 1138 | 'menu-item-post-date-gmt' => $invalid_date, |
| 1139 | ) |
| 1140 | ); |
| 1141 | $post = get_post( $menu_item_id ); |
| 1142 | $this->assertEqualsWithDelta( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| 1143 | } |