Changeset 38584
- Timestamp:
- 09/09/2016 04:59:01 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/nav-menu.php
r38470 r38584 71 71 } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) { 72 72 if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) { 73 $search_results_query = new WP_Query( array( 73 $post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); 74 $args = array( 74 75 'no_found_rows' => true, 75 76 'update_post_meta_cache' => false, … … 78 79 'post_type' => $matches[2], 79 80 's' => $query, 80 ) ); 81 ); 82 if ( isset( $post_type_obj->_default_query ) ) { 83 $args = array_merge( $args, (array) $post_type_obj->_default_query ); 84 } 85 $search_results_query = new WP_Query( $args ); 81 86 if ( ! $search_results_query->have_posts() ) { 82 87 return; -
trunk/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
r37881 r38584 7 7 8 8 /** 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 * 9 36 * @ticket 27042 10 37 */ … … 27 54 $this->assertCount( 3, $results ); 28 55 } 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 } 29 83 }
Note: See TracChangeset
for help on using the changeset viewer.