wordpress-develop/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
Dominik Schilling (ocean90) f147b02783 Nav Menus: Use WP_Query for quick searches.
`the_post()` sets the `$in_the_loop` property to true which is unexpected in the admin if you're using filters which should only affect real loops.

Props ruud@joyo.
Fixes #27042.

git-svn-id: https://develop.svn.wordpress.org/trunk@37881 602fd350-edb4-49c9-b593-d223f7449a82
2016-06-27 11:50:31 +00:00

30 lines
777 B
PHP

<?php
/**
* @group menu
*/
class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase {
/**
* @ticket 27042
*/
public function test_search_returns_results_for_pages() {
include_once ABSPATH . 'wp-admin/includes/nav-menu.php';
self::factory()->post->create_many( 3, array( 'post_type' => 'page', 'post_content' => 'foo' ) );
self::factory()->post->create( array( 'post_type' => 'page', 'post_content' => 'bar' ) );
$request = array(
'type' => 'quick-search-posttype-page',
'q' => 'foo',
'response-format' => 'json',
);
$output = get_echo( '_wp_ajax_menu_quick_search', array( $request ) );
$this->assertNotEmpty( $output );
$results = explode( "\n", trim( $output ) );
$this->assertCount( 3, $results );
}
}