WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/02/2016 06:23:12 AM (5 years ago)
Author:
rmccue
Message:

REST API: Add locale to user resource.

Props ocean90, joehoyle.
Fixes #38528.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r39085 r39090  
    778778            'first_name' => 'Old Name',
    779779            'user_url' => 'http://apple.com',
     780            'locale' => 'en_US',
    780781        ));
    781782        $this->allow_user_to_manage_multisite();
     
    789790        $_POST['first_name'] = 'New Name';
    790791        $_POST['url'] = 'http://google.com';
     792        $_POST['locale'] = 'de_DE';
    791793
    792794        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
     
    805807        $this->assertEquals( 'http://google.com', $new_data['url'] );
    806808        $this->assertEquals( 'http://google.com', $user->user_url );
     809        $this->assertEquals( 'de_DE', $user->locale );
    807810
    808811        // Check that we haven't inadvertently changed the user's password,
     
    822825        $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    823826        $this->assertEquals( 'rest_user_invalid_email', $response->as_error()->get_error_code() );
     827    }
     828
     829    public function test_update_item_invalid_locale() {
     830        $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) );
     831        $this->allow_user_to_manage_multisite();
     832        wp_set_current_user( self::$user );
     833
     834        $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user1 );
     835        $request->set_param( 'locale', 'klingon' );
     836        $response = $this->server->dispatch( $request );
     837        $this->assertInstanceOf( 'WP_Error', $response->as_error() );
     838        $this->assertEquals( 'rest_invalid_param', $response->as_error()->get_error_code() );
    824839    }
    825840
     
    11401155        $properties = $data['schema']['properties'];
    11411156
    1142         $this->assertEquals( 18, count( $properties ) );
     1157        $this->assertEquals( 19, count( $properties ) );
    11431158        $this->assertArrayHasKey( 'avatar_urls', $properties );
    11441159        $this->assertArrayHasKey( 'capabilities', $properties );
     
    11501165        $this->assertArrayHasKey( 'last_name', $properties );
    11511166        $this->assertArrayHasKey( 'link', $properties );
     1167        $this->assertArrayHasKey( 'locale', $properties );
    11521168        $this->assertArrayHasKey( 'meta', $properties );
    11531169        $this->assertArrayHasKey( 'name', $properties );
     
    12981314            $this->assertEquals( $user->user_login, $data['username'] );
    12991315            $this->assertEquals( $user->roles, $data['roles'] );
     1316            $this->assertEquals( get_user_locale( $user ), $data['locale'] );
    13001317        }
    13011318
Note: See TracChangeset for help on using the changeset viewer.