Make WordPress Core

Ticket #38577: 38577.diff

File 38577.diff, 2.0 KB (added by jnylen0, 8 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
    index 48d649a..a5f1f38 100644
    a b class WP_REST_Users_Controller extends WP_REST_Controller { 
    10071007                                        'description' => __( 'Roles assigned to the resource.' ),
    10081008                                        'type'        => 'array',
    10091009                                        'context'     => array( 'edit' ),
     1010                                        'arg_options' => array(
     1011                                                'sanitize_callback' => 'wp_parse_slug_list',
     1012                                        ),
    10101013                                ),
    10111014                                'password'        => array(
    10121015                                        'description' => __( 'Password for the resource (never included).' ),
  • tests/phpunit/tests/rest-api/rest-users-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php
    index f2131d4..efc0d53 100644
    a b class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 
    907907                $this->assertArrayNotHasKey( 'administrator', $user->caps );
    908908        }
    909909
     910        public function test_update_user_multiple_roles() {
     911                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     912
     913                wp_set_current_user( self::$user );
     914                $this->allow_user_to_manage_multisite();
     915
     916                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
     917                $request->set_param( 'roles', 'author,editor' );
     918                $response = $this->server->dispatch( $request );
     919
     920                $new_data = $response->get_data();
     921
     922                $this->assertEquals( array( 'author', 'editor' ), $new_data['roles'] );
     923
     924                $user = get_userdata( $user_id );
     925                $this->assertArrayHasKey( 'author', $user->caps );
     926                $this->assertArrayHasKey( 'editor', $user->caps );
     927                $this->assertArrayNotHasKey( 'administrator', $user->caps );
     928        }
     929
    910930        public function test_update_user_role_invalid_privilege_escalation() {
    911931                wp_set_current_user( self::$editor );
    912932