Make WordPress Core

Ticket #19038: 19038.3.diff

File 19038.3.diff, 1.4 KB (added by swissspidy, 9 years ago)

adds unit test

  • src/wp-includes/nav-menu.php

    diff --git src/wp-includes/nav-menu.php src/wp-includes/nav-menu.php
    index 58a5d11..16653ca 100644
    function wp_setup_nav_menu_item( $menu_item ) { 
    747747                                        $menu_item->_invalid = true;
    748748                                }
    749749
     750                                if ( 'trash' === get_post_status( $menu_item->object_id ) ) {
     751                                        $menu_item->_invalid = true;
     752                                }
     753
    750754                                $menu_item->url = get_permalink( $menu_item->object_id );
    751755
    752756                                $original_object = get_post( $menu_item->object_id );
  • tests/phpunit/tests/post/nav-menu.php

    diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
    index bbcbbab..83edce5 100644
    class Test_Nav_Menus extends WP_UnitTestCase { 
    277277        }
    278278
    279279        /**
     280         * @ticket 19038
     281         */
     282        function test_wp_setup_nav_menu_item_for_trashed_post() {
     283                $post_id = self::factory()->post->create( array(
     284                        'post_status' => 'trash',
     285                ) );
     286
     287                $menu_item_id = wp_update_nav_menu_item( $this->menu_id, 0, array(
     288                        'menu-item-type'      => 'post_type',
     289                        'menu-item-object'    => 'post',
     290                        'menu-item-object-id' => $post_id,
     291                        'menu-item-status'    => 'publish',
     292                ) );
     293
     294                $menu_item = wp_setup_nav_menu_item( get_post( $menu_item_id ) );
     295
     296                $this->assertTrue( ! _is_valid_nav_menu_item( $menu_item ) );
     297        }
     298
     299        /**
    280300         * @ticket 35206
    281301         */
    282302        function test_wp_nav_menu_whitespace_options() {