Skip to content

Commit c292e28

Browse files
committed
Tests: Cover block directory REST response links.
Check that block directory response preparation includes an install-plugin link by default and omits links when `_fields` excludes them. Developed in: #14762 Props devmuhib. See #40538. git-svn-id: https://develop.svn.wordpress.org/trunk@64831 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f000afc commit c292e28

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎tests/phpunit/tests/rest-api/rest-block-directory-controller.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,31 @@ public function test_prepare_item() {
219219
);
220220

221221
$this->assertSame( $expected, $response->get_data() );
222+
223+
$links = test_rest_expand_compact_links( $response->get_links() );
224+
$this->assertArrayHasKey( 'https://api.w.org/install-plugin', $links );
225+
}
226+
227+
/**
228+
* @ticket 40538
229+
*/
230+
public function test_prepare_item_limit_fields() {
231+
wp_set_current_user( self::$admin_id );
232+
233+
$controller = new WP_REST_Block_Directory_Controller();
234+
235+
$plugin = $this->get_mock_plugin();
236+
$request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' );
237+
$request->set_query_params(
238+
array(
239+
'term' => 'block',
240+
'_fields' => 'id,name',
241+
)
242+
);
243+
244+
$response = $controller->prepare_item_for_response( $plugin, $request );
245+
246+
$this->assertEmpty( $response->get_links(), 'Links should be omitted when not requested in _fields.' );
222247
}
223248

224249
/**

0 commit comments

Comments
 (0)