New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#53621 Correct the schema for the wp/v2/block-directory/search
endpoint
#1487
Conversation
Here's a unit test that could be added to /**
* @ticket 53621
*/
public function test_get_items_response_conforms_to_schema() {
wp_set_current_user( self::$admin_id );
$plugin = $this->get_mock_plugin();
$cb = function () use ( $plugin ) {
return (object) array(
'info' =>
array(
'page' => 1,
'pages' => 1,
'results' => 1,
),
'plugins' => array(
$plugin,
),
);
};
add_filter( 'plugins_api', $cb );
$request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' );
$request->set_query_params( array( 'term' => 'cache' ) );
$expected = array(
array(
'name' => 'sortabrilliant/guidepost',
'title' => 'Guidepost',
'description' => 'A guidepost gives you directions. It lets you know where you’re going. It gives you a preview of what’s to come.',
'id' => 'guidepost',
'rating' => 4.3,
'rating_count' => 90,
'active_installs' => 100,
'author_block_rating' => 0,
'author_block_count' => 1,
'author' => 'sorta brilliant',
'icon' => 'https://ps.w.org/guidepost/assets/icon-128x128.jpg?rev=2235512',
'last_updated' => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ),
'humanized_updated' => sprintf( '%s ago', human_time_diff( strtotime( $plugin['last_updated'] ) ) ),
'_links' => array(
'wp:install-plugin' => array(
array(
'href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fplugins&slug=guidepost',
),
),
'curies' => array(
array(
'name' => 'wp',
'href' => 'https://api.w.org/{rel}',
'templated' => true,
),
),
),
),
);
$result = rest_do_request( $request );
remove_filter( 'plugins_api', $cb );
$this->assertNotWPError( $result->as_error() );
$this->assertSame( 200, $result->status );
$this->assertSame( $expected, $result->get_data() );
} |
tests/phpunit/tests/rest-api/rest-block-directory-controller.php
Outdated
Show resolved
Hide resolved
tests/phpunit/tests/rest-api/rest-block-directory-controller.php
Outdated
Show resolved
Hide resolved
This test is somewhat of a duplicate of our existing We can do this by applying |
I adjusted then test as per Timothy's recommendation. It now validates the result against the schema. It successfully fails with the old schema and passes with the corrected one. |
Looks good to me. |
Trac ticket: https://core.trac.wordpress.org/ticket/53621