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:
Ryan McCue
2016-02-16 02:18:34 +00:00
parent 6dd1dd61a1
commit d7e7c0b81b
3 changed files with 106 additions and 0 deletions

View File

@@ -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
*/