| 625 | /** |
| 626 | * Make sure an existing menu item is pre-populated with its existing values. |
| 627 | * |
| 628 | * @ticket 28138 |
| 629 | */ |
| 630 | function test_default_values() { |
| 631 | do_action( 'customize_register', $this->wp_customize ); |
| 632 | |
| 633 | $first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) ); |
| 634 | |
| 635 | $primary_menu_id = wp_create_nav_menu( 'Primary' ); |
| 636 | $item_title = 'Greetings'; |
| 637 | $item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array( |
| 638 | 'menu-item-type' => 'post_type', |
| 639 | 'menu-item-object' => 'post', |
| 640 | 'menu-item-object-id' => $first_post_id, |
| 641 | 'menu-item-title' => $item_title, |
| 642 | 'menu-item-status' => 'publish', |
| 643 | 'menu-item-parent-id' => 1, |
| 644 | 'menu-item-position' => 1, |
| 645 | 'menu-item-description' => 'This is a test', |
| 646 | 'menu-item-attr-title' => 'Attribute title', |
| 647 | 'menu-item-target' => '_blank', |
| 648 | 'menu-item-classes' => 'first second', |
| 649 | 'menu-item-xfn' => 'xfn', |
| 650 | ) ); |
| 651 | |
| 652 | // Hook a mock action into the update action so we can capture arguments |
| 653 | $a = new MockAction(); |
| 654 | add_action( 'wp_update_nav_menu_item', array( $a, 'action' ), 10, 3 ); |
| 655 | |
| 656 | // Now update the menu, passing no information, and verify that everything stayed the same |
| 657 | $updated_id = wp_update_nav_menu_item( $primary_menu_id, $item_id, array() ); |
| 658 | |
| 659 | // Verify |
| 660 | $this->assertEquals( 1, $a->get_call_count() ); |
| 661 | |
| 662 | $args = $a->get_args(); |
| 663 | $args = $args[0]; // There is only one item in the collection |
| 664 | $this->assertEquals( $primary_menu_id, $args[0] ); |
| 665 | $this->assertEquals( $item_id, $args[1] ); |
| 666 | |
| 667 | $this->assertEquals( 'post_type', $args[2]['menu-item-type'] ); |
| 668 | $this->assertEquals( 'post', $args[2]['menu-item-object'] ); |
| 669 | $this->assertEquals( $first_post_id, $args[2]['menu-item-object-id'] ); |
| 670 | $this->assertEquals( $item_title, $args[2]['menu-item-title'] ); |
| 671 | $this->assertEquals( 'publish', $args[2]['menu-item-status'] ); |
| 672 | $this->assertEquals( 1, $args[2]['menu-item-parent-id'] ); |
| 673 | $this->assertEquals( 1, $args[2]['menu-item-position'] ); |
| 674 | $this->assertEquals( 'This is a test', $args[2]['menu-item-description'] ); |
| 675 | $this->assertEquals( 'Attribute title', $args[2]['menu-item-attr-title'] ); |
| 676 | $this->assertEquals( '_blank', $args[2]['menu-item-target'] ); |
| 677 | $this->assertEquals( 'xfn', $args[2]['menu-item-xfn'] ); |
| 678 | |
| 679 | $this->assertContains( 'first', $args[2]['menu-item-classes'] ); |
| 680 | $this->assertContains( 'second', $args[2]['menu-item-classes'] ); |
| 681 | } |