| | 183 | |
| | 184 | /** |
| | 185 | * @ticket 34803 |
| | 186 | */ |
| | 187 | function test_delete_child_menu_with_grandchildren_present() { |
| | 188 | |
| | 189 | // Create a new menu |
| | 190 | $menuId = wp_create_nav_menu( rand_str() ); |
| | 191 | $menu = wp_get_nav_menu_object($menuId); |
| | 192 | $this->assertSame($menuId, $menu->term_id); |
| | 193 | |
| | 194 | // Add grandparent nav menu item |
| | 195 | // and confirm it saved properly |
| | 196 | $grandparent = wp_update_nav_menu_item( $menuId, 0, array( |
| | 197 | 'menu-item-type' => 'custom', |
| | 198 | 'menu-item-title' => 'Grandparent', |
| | 199 | 'menu-item-link' => 'http://wordpress.org', |
| | 200 | 'menu-item-status' => 'publish' |
| | 201 | ) ); |
| | 202 | $custom_item = wp_setup_nav_menu_item( get_post( $grandparent ) ); |
| | 203 | $this->assertEquals( 'Grandparent', $custom_item->title ); |
| | 204 | |
| | 205 | // Add parent nav menu item |
| | 206 | // and confirm it saved properly |
| | 207 | $parent = wp_update_nav_menu_item( $menuId, 0, array( |
| | 208 | 'menu-item-type' => 'custom', |
| | 209 | 'menu-item-title' => 'Parent', |
| | 210 | 'menu-item-link' => 'http://wordpress.org', |
| | 211 | 'menu-item-status' => 'publish', |
| | 212 | 'menu-item-parent-id' => $grandparent |
| | 213 | ) ); |
| | 214 | $custom_item = wp_setup_nav_menu_item( get_post( $parent ) ); |
| | 215 | $this->assertEquals( 'Parent', $custom_item->title ); |
| | 216 | |
| | 217 | // Add child nav menu item |
| | 218 | // and confirm it saved properly |
| | 219 | $child = wp_update_nav_menu_item( $menuId, 0, array( |
| | 220 | 'menu-item-type' => 'custom', |
| | 221 | 'menu-item-title' => 'Child', |
| | 222 | 'menu-item-link' => 'http://wordpress.org', |
| | 223 | 'menu-item-status' => 'publish', |
| | 224 | 'menu-item-parent-id' => $parent |
| | 225 | ) ); |
| | 226 | $custom_item = wp_setup_nav_menu_item( get_post( $child ) ); |
| | 227 | $this->assertEquals( 'Child', $custom_item->title ); |
| | 228 | |
| | 229 | // Delete the Parent menu item |
| | 230 | wp_delete_post( $parent, true ); |
| | 231 | $deletedPost = get_post( $parent ); |
| | 232 | $this->assertNull( $deletedPost ); |
| | 233 | |
| | 234 | // Verify that the child is now associated directly with the grandparent |
| | 235 | $newParentMenuItemId = get_post_meta( $child, '_menu_item_menu_item_parent', true ); |
| | 236 | $this->assertEquals( $grandparent, (int)$newParentMenuItemId ); |
| | 237 | |
| | 238 | } |
| | 239 | |