mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-14 09:34:41 +00:00
REST API: Add support for CURIEs.
CURIEs are Compact URIs, which provide a more usable way to use custom relations in the API. The `wp` CURIE is registered by default for `https://api.w.org/` URI relations. Fixes #34729. Props joehoyle. git-svn-id: https://develop.svn.wordpress.org/trunk@36533 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -400,6 +400,45 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$this->assertEquals( 'embed', $alternate[1]['parameters']['context'] );
|
||||
}
|
||||
|
||||
public function test_link_curies() {
|
||||
$response = new WP_REST_Response();
|
||||
$response->add_link( 'https://api.w.org/term', 'http://example.com/' );
|
||||
|
||||
$data = $this->server->response_to_data( $response, false );
|
||||
$links = $data['_links'];
|
||||
|
||||
$this->assertArrayHasKey( 'wp:term', $links );
|
||||
$this->assertArrayHasKey( 'curies', $links );
|
||||
}
|
||||
|
||||
public function test_custom_curie_link() {
|
||||
$response = new WP_REST_Response();
|
||||
$response->add_link( 'http://mysite.com/contact.html', 'http://example.com/' );
|
||||
|
||||
add_filter( 'rest_response_link_curies', array( $this, 'add_custom_curie' ) );
|
||||
|
||||
$data = $this->server->response_to_data( $response, false );
|
||||
$links = $data['_links'];
|
||||
|
||||
$this->assertArrayHasKey( 'my_site:contact', $links );
|
||||
$this->assertArrayHasKey( 'curies', $links );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper callback to add a new custom curie via a filter.
|
||||
*
|
||||
* @param array $curies
|
||||
* @return array
|
||||
*/
|
||||
public function add_custom_curie( $curies ) {
|
||||
$curies[] = array(
|
||||
'name' => 'my_site',
|
||||
'href' => 'http://mysite.com/{rel}.html',
|
||||
'templated' => true,
|
||||
);
|
||||
return $curies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_link_embedding
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user