Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/endpoints/class-wp-rest-users-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function register_routes() {
public function get_items( $request ) {

$prepared_args = array();
$prepared_args['exclude'] = $request['exclude'];
$prepared_args['include'] = $request['include'];
$prepared_args['order'] = $request['order'];
$prepared_args['number'] = $request['per_page'];
Expand Down
33 changes: 33 additions & 0 deletions tests/test-rest-users-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ public function test_context_param() {
$this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
}

public function test_registered_query_params() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$keys = array_keys( $data['endpoints'][0]['args'] );
sort( $keys );
$this->assertEquals( array(
'context',
'include',
'order',
'orderby',
'page',
'per_page',
'search',
), $keys );
}

public function test_get_items() {
wp_set_current_user( $this->user );

Expand Down Expand Up @@ -226,6 +243,22 @@ public function test_get_items_include_query() {
$this->assertEquals( $id3, $data[0]['id'] );
}

public function test_get_items_exclude_query() {
wp_set_current_user( $this->user );
$id1 = $this->factory->user->create();
$id2 = $this->factory->user->create();
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
$request->set_param( 'exclude', array( $id2 ) );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
}

public function test_get_items_search() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
Expand Down