Skip to content

Commit a113c05

Browse files
committed
Add a test that verifies that only terms with search term in title return results.
1 parent e886af1 commit a113c05

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@ public function test_search_returns_results_for_pages() {
4242
$this->assertCount( 3, $results );
4343
}
4444

45+
/**
46+
* Test that search only returns results for posts with term in title.
47+
*
48+
* @ticket 48655
49+
*/
50+
public function test_search_only_returns_results_for_posts_with_term_in_title() {
51+
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
52+
53+
// This will make sure that WP_Query sets is_admin to true.
54+
set_current_screen( 'nav-menu.php' );
55+
56+
self::factory()->post->create(
57+
array(
58+
'post_type' => 'post',
59+
'post_status' => 'publish',
60+
'post_title' => 'Publish FOO',
61+
'post_content' => 'FOO',
62+
)
63+
);
64+
self::factory()->post->create(
65+
array(
66+
'post_type' => 'post',
67+
'post_status' => 'publish',
68+
'post_title' => 'Publish without search term',
69+
'post_content' => 'FOO',
70+
)
71+
);
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+
}
83+
4584
/**
4685
* Test that search only returns results for published posts.
4786
*

0 commit comments

Comments
 (0)