REST API: Improve post cache priming in WP_REST_Post_Search_Handler class.

In the `WP_REST_Post_Search_Handler` class, ensure that post, post meta and term caches are correctly primed when performing a search.

Props furi3r, spacedmonkey, TimothyBlynJacobs, audrasjb, peterwilsoncc. 
Fixes #55674.



git-svn-id: https://develop.svn.wordpress.org/trunk@53485 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2022-06-10 15:45:45 +00:00
parent 8903b4a981
commit b855e63693
2 changed files with 38 additions and 7 deletions

View File

@@ -332,6 +332,36 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
);
}
/**
* @ticket 55674
*/
public function test_get_items_search_prime_ids() {
$action = new MockAction();
add_filter( 'query', array( $action, 'filter' ), 10, 2 );
$query_args = array(
'per_page' => 100,
'search' => 'foocontent',
);
$response = $this->do_request_with_params( $query_args );
$this->assertSame( 200, $response->get_status(), 'Request Status Response is not 200.' );
$ids = wp_list_pluck( $response->get_data(), 'id' );
$this->assertSameSets( self::$my_content_post_ids, $ids, 'Query result posts ids do not match with expected ones.' );
$args = $action->get_args();
$primed_query_found = false;
foreach ( $args as $arg ) {
// Primed query will use WHERE ID IN clause.
if ( str_contains( $arg[0], 'WHERE ID IN (' . implode( ',', $ids ) ) ) {
$primed_query_found = true;
break;
}
}
$this->assertTrue( $primed_query_found, 'Prime query was not executed.' );
}
/**
* Test retrieving a single item isn't possible.
*/