Skip to content

Commit b195441

Browse files
committed
Adding Tests
1 parent 1e04fc0 commit b195441

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

tests/phpunit/tests/rest-api/rest-post-types-controller.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ public function test_get_items() {
4444
$this->assertArrayNotHasKey( 'revision', $data );
4545
}
4646

47+
/**
48+
* @ticket 50012
49+
* @ticket 61477
50+
*/
51+
public function test_get_items_with_filtered_fields() {
52+
$request = new WP_REST_Request( 'GET', '/wp/v2/types' );
53+
$request->set_param( '_fields', 'rest_base,description' );
54+
$response = rest_get_server()->dispatch( $request );
55+
$data = $response->get_data();
56+
57+
$this->assertArrayHasKey( 'rest_base', $data['post'] );
58+
$this->assertArrayHasKey( 'description', $data['post'] );
59+
$this->assertFalse( array_key_exists( 'taxonomies', $data['post'] ) );
60+
}
61+
4762
/**
4863
* @dataProvider data_readable_http_methods
4964
* @ticket 56481

tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public function test_get_items_with_head_request_should_not_prepare_taxonomy_dat
7676
$this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
7777
}
7878

79+
/**
80+
* @ticket 50012
81+
*/
82+
public function test_get_items_with_filtered_fields() {
83+
$request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
84+
$request->set_param( '_fields', 'name,hierarchical' );
85+
$response = rest_get_server()->dispatch( $request );
86+
$data = $response->get_data();
87+
88+
$this->assertArrayHasKey( 'name', $data['category'] );
89+
$this->assertArrayHasKey( 'hierarchical', $data['category'] );
90+
$this->assertFalse( array_key_exists( 'slug', $data['category'] ) );
91+
}
92+
7993
public function test_get_items_context_edit() {
8094
wp_set_current_user( self::$contributor_id );
8195
$request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );

0 commit comments

Comments
 (0)