Make WordPress Core


Ignore:
Timestamp:
03/15/2014 06:06:41 AM (11 years ago)
Author:
nacin
Message:

Explicitly assign menu term relationship rather than piggybacking on wp_insert_post() with the tax_input argument.

That argument currently depends on user context (see #19373).

Adds unit test for properly updating orphaned menu items.

props danielbachhuber.
fixes #27113.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r27150 r27556  
    8989        $this->assertEqualSets( array(), $page_items );
    9090    }
     91
     92    /**
     93     * @ticket 27113
     94     */
     95    function test_orphan_nav_menu_item() {
     96
     97        // Create an orphan nav menu item
     98        $custom_item_id = wp_update_nav_menu_item( 0, 0, array(
     99            'menu-item-type'      => 'custom',
     100            'menu-item-title'     => 'Wordpress.org',
     101            'menu-item-link'      => 'http://wordpress.org',
     102            'menu-item-status'    => 'publish'
     103        ) );
     104
     105        // Confirm it saved properly
     106        $custom_item = wp_setup_nav_menu_item( get_post( $custom_item_id ) );
     107        $this->assertEquals( 'Wordpress.org', $custom_item->title );
     108
     109        // Update the orphan with an associated nav menu
     110        wp_update_nav_menu_item( $this->menu_id, $custom_item_id, array(
     111            'menu-item-title'     => 'WordPress.org',
     112            ) );
     113        $menu_items = wp_get_nav_menu_items( $this->menu_id );
     114        $custom_item = wp_filter_object_list( $menu_items, array( 'db_id' => $custom_item_id ) );
     115        $custom_item = array_pop( $custom_item );
     116        $this->assertEquals( 'WordPress.org', $custom_item->title );
     117
     118    }
    91119}
Note: See TracChangeset for help on using the changeset viewer.