WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/09/16 04:59:01 (9 months ago)
Author:
westonruter
Message:

Menus: Prevent non-published posts/pages from being returned in search results for adding as nav menu items.

Re-use the same query vars in searching as when listing posts. Aligns with behavior of nav menus in customizer.

Fixes #33742.
Props welcher, westonruter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php

    r37881 r38584  
    77 
    88    /** 
     9     * Current screen. 
     10     * 
     11     * @var mixed 
     12     */ 
     13    protected $current_screen; 
     14 
     15    /** 
     16     * Set up. Workaround set_current_screen( null ) not working due to $hook_suffix not being set. 
     17     */ 
     18    function setUp() { 
     19        global $current_screen; 
     20        $this->current_screen = $current_screen; 
     21        parent::setUp(); 
     22    } 
     23 
     24    /** 
     25     * Tear down. Workaround set_current_screen( null ) not working due to $hook_suffix not being set. 
     26     */ 
     27    function tearDown() { 
     28        global $current_screen; 
     29        parent::tearDown(); 
     30        $current_screen = $this->current_screen; 
     31    } 
     32 
     33    /** 
     34     * Test search returns results for pages. 
     35     * 
    936     * @ticket 27042 
    1037     */ 
     
    2754        $this->assertCount( 3, $results ); 
    2855    } 
     56 
     57    /** 
     58     * Test that search only returns results for publihed posts. 
     59     * 
     60     * @ticket 33742 
     61     */ 
     62    public function test_search_returns_results_for_published_posts() { 
     63        require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; 
     64 
     65        // This will make sure that WP_Query sets is_admin to true. 
     66        set_current_screen( 'nav-menu.php' ); 
     67 
     68        self::factory()->post->create( array( 'post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'Publish', 'post_content' => 'FOO' ) ); 
     69        self::factory()->post->create( array( 'post_type' => 'post', 'post_status' => 'draft', 'post_title' => 'Draft', 'post_content' => 'FOO' ) ); 
     70        self::factory()->post->create( array( 'post_type' => 'post', 'post_status' => 'pending', 'post_title' => 'Pending', 'post_content' => 'FOO' ) ); 
     71        self::factory()->post->create( array( 'post_type' => 'post', 'post_status' => 'future', 'post_title' => 'Future', 'post_content' => 'FOO', 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 month' ) ) ) ); 
     72 
     73        $request = array( 
     74            'type' => 'quick-search-posttype-post', 
     75            'q' => 'FOO', 
     76        ); 
     77        $output = get_echo( '_wp_ajax_menu_quick_search', array( $request ) ); 
     78 
     79        $this->assertNotEmpty( $output ); 
     80        $results = explode( "\n", trim( $output ) ); 
     81        $this->assertCount( 1, $results ); 
     82    } 
    2983} 
Note: See TracChangeset for help on using the changeset viewer.