Skip to content

Instantly share code, notes, and snippets.

@joehoyle
Last active March 19, 2016 16:21
Show Gist options
  • Save joehoyle/4db7ba5d871338d1fb97 to your computer and use it in GitHub Desktop.
Save joehoyle/4db7ba5d871338d1fb97 to your computer and use it in GitHub Desktop.
<?php
/**
* @rest-api-base-namespace: /wp/v2
* @rest-api-base-path: /posts
*/
class REST_API_Endpoint_Test extends WP_REST_Unit_Test_Case {
function test_create_item() {
$response = $this->create_item( array(
'title' => 'Test',
));
$this->assertResponseEquals( array(
'code' => 200,
'data' => array(
'id' => 1,
'author' => 1,
),
'links' => array(
'author' => '/wp/v2/users/1',
),
), $response );
// test for a subset of any data, e.g. a specific key is in the body
$this->assertResponseContains( array(
'data' => array(
'author' => 1,
),
'links' => array(
'author' => '/wp/v2/users/1',
),
), $response );
$this->assertResponseCollectionEquals( array(
...
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment