Make WordPress Core

Ticket #56577: 56577.unittests.patch

File 56577.unittests.patch, 1.3 KB (added by andizer, 6 months ago)

Added unit tests

  • tests/phpunit/tests/post/nav-menu.php

    diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php
    index 52d7a93c34..dc63625c44 100644
    a b class Tests_Post_Nav_Menu extends WP_UnitTestCase { 
    11411141                $post         = get_post( $menu_item_id );
    11421142                $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
    11431143        }
     1144
     1145        /**
     1146         * @ticket 56577
     1147         */
     1148        public function test_orphan_nav_menu_item_short_circuit_filter()
     1149        {
     1150                // Create an orphan nav menu item.
     1151                $custom_item_id = wp_update_nav_menu_item(
     1152                        0,
     1153                        0,
     1154                        array(
     1155                                'menu-item-type' => 'custom',
     1156                                'menu-item-title' => 'Wordpress.org',
     1157                                'menu-item-url' => 'http://wordpress.org',
     1158                                'menu-item-status' => 'publish',
     1159                        )
     1160                );
     1161
     1162                add_filter( 'pre_wp_setup_nav_menu_item', [ $this, 'short_circuit_nav_menu_item' ] );
     1163
     1164                // Confirm it saved properly.
     1165                $custom_item = wp_setup_nav_menu_item(get_post($custom_item_id));
     1166                $this->assertSame('--empty nav menu item--', $custom_item);
     1167
     1168                remove_filter( 'pre_wp_setup_nav_menu_item', [ $this, 'short_circuit_nav_menu_item' ] );
     1169        }
     1170
     1171        public function short_circuit_nav_menu_item() {
     1172                return '--empty nav menu item--';
     1173        }
     1174
    11441175}