mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 19:54:28 +00:00
REST API: Respect _fields query arg in preloaded requests
Ensures that preloaded request can include a `_fields` query param that asks that only selected response fields are returned. Props jsnajdr, timothyblynjacobs. Fixes #55213. See #55567. git-svn-id: https://develop.svn.wordpress.org/trunk@53217 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2490,4 +2490,32 @@ class Tests_REST_API extends WP_UnitTestCase {
|
||||
array( '', array(), array() ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 55213
|
||||
*/
|
||||
public function test_rest_preload_api_request_fields() {
|
||||
$preload_paths = array(
|
||||
'/',
|
||||
'/?_fields=description',
|
||||
);
|
||||
|
||||
$preload_data = array_reduce(
|
||||
$preload_paths,
|
||||
'rest_preload_api_request',
|
||||
array()
|
||||
);
|
||||
|
||||
$this->assertSame( array_keys( $preload_data ), array( '/', '/?_fields=description' ) );
|
||||
|
||||
// Unfiltered request has all fields
|
||||
$this->assertArrayHasKey( 'description', $preload_data['/']['body'] );
|
||||
$this->assertArrayHasKey( 'routes', $preload_data['/']['body'] );
|
||||
|
||||
// Filtered request only has the desired fields + links
|
||||
$this->assertSame(
|
||||
array_keys( $preload_data['/?_fields=description']['body'] ),
|
||||
array( 'description', '_links' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user