mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
REST API: Correct the schema for the wp/v2/block-directory/search endpoint.
Props zieladam, TimothyBlynJacobs, spacedmonkey, johnbillion Fixes #53621 git-svn-id: https://develop.svn.wordpress.org/trunk@53315 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f4416e018d
commit
5612331504
@ -239,7 +239,7 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller {
|
||||
),
|
||||
'rating' => array(
|
||||
'description' => __( 'The star rating of the block.' ),
|
||||
'type' => 'integer',
|
||||
'type' => 'number',
|
||||
'context' => array( 'view' ),
|
||||
),
|
||||
'rating_count' => array(
|
||||
@ -249,12 +249,12 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller {
|
||||
),
|
||||
'active_installs' => array(
|
||||
'description' => __( 'The number sites that have activated this block.' ),
|
||||
'type' => 'string',
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view' ),
|
||||
),
|
||||
'author_block_rating' => array(
|
||||
'description' => __( 'The average rating of blocks published by the same author.' ),
|
||||
'type' => 'integer',
|
||||
'type' => 'number',
|
||||
'context' => array( 'view' ),
|
||||
),
|
||||
'author_block_count' => array(
|
||||
|
||||
@ -212,6 +212,46 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te
|
||||
$this->assertArrayHasKey( 'humanized_updated', $properties );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 53621
|
||||
*/
|
||||
public function test_get_items_response_conforms_to_schema() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
$plugin = $this->get_mock_plugin();
|
||||
|
||||
// Fetch the block directory schema.
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/block-directory/search' );
|
||||
$schema = rest_get_server()->dispatch( $request )->get_data()['schema'];
|
||||
|
||||
add_filter(
|
||||
'plugins_api',
|
||||
static function () use ( $plugin ) {
|
||||
return (object) array(
|
||||
'info' =>
|
||||
array(
|
||||
'page' => 1,
|
||||
'pages' => 1,
|
||||
'results' => 1,
|
||||
),
|
||||
'plugins' => array(
|
||||
$plugin,
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// Fetch a block plugin.
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' );
|
||||
$request->set_query_params( array( 'term' => 'cache' ) );
|
||||
|
||||
$result = rest_get_server()->dispatch( $request );
|
||||
$data = $result->get_data();
|
||||
|
||||
$valid = rest_validate_value_from_schema( $data[0], $schema );
|
||||
|
||||
$this->assertNotWPError( $valid );
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a network failure on outbound http requests to a given hostname.
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user