Make WordPress Core

Changeset 39056


Ignore:
Timestamp:
10/31/2016 11:10:37 AM (9 years ago)
Author:
pento
Message:

REST API: Allow a CSV list of user roles to be passed to /users.

After [39048], this changes explicitly parses the list of user roles as slugs, and adds tests.

Props jnylen0.
Fixes #38557.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r39046 r39056  
    10111011                    ),
    10121012                    'context'     => array( 'edit' ),
     1013                    'arg_options' => array(
     1014                        'sanitize_callback' => 'wp_parse_slug_list',
     1015                    ),
    10131016                ),
    10141017                'password'        => array(
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r39043 r39056  
    905905
    906906        $user = get_userdata( $user_id );
     907        $this->assertArrayHasKey( 'editor', $user->caps );
     908        $this->assertArrayNotHasKey( 'administrator', $user->caps );
     909    }
     910
     911    public function test_update_user_multiple_roles() {
     912        $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     913
     914        wp_set_current_user( self::$user );
     915        $this->allow_user_to_manage_multisite();
     916
     917        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
     918        $request->set_param( 'roles', 'author,editor' );
     919        $response = $this->server->dispatch( $request );
     920
     921        $new_data = $response->get_data();
     922
     923        $this->assertEquals( array( 'author', 'editor' ), $new_data['roles'] );
     924
     925        $user = get_userdata( $user_id );
     926        $this->assertArrayHasKey( 'author', $user->caps );
    907927        $this->assertArrayHasKey( 'editor', $user->caps );
    908928        $this->assertArrayNotHasKey( 'administrator', $user->caps );
Note: See TracChangeset for help on using the changeset viewer.