From e78230b39a87c2ebc35d61e667839b4fe46e3b1f Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Wed, 2 Nov 2016 21:20:12 +0000 Subject: [PATCH] REST API: Add en_US to the locales enum. Props ocean90. Fixes #38528. git-svn-id: https://develop.svn.wordpress.org/trunk@39096 602fd350-edb4-49c9-b593-d223f7449a82 --- .../endpoints/class-wp-rest-users-controller.php | 2 +- .../tests/rest-api/rest-users-controller.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 9a8cc21245..bb3737df0c 100644 --- 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 @@ -1069,7 +1069,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'locale' => array( 'description' => __( 'Locale for the resource.' ), 'type' => 'string', - 'enum' => get_available_languages(), + 'enum' => array_merge( array( 'en_US' ), get_available_languages() ), 'context' => array( 'edit' ), ), 'nickname' => array( diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 574e5711f8..4f89ac2180 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -838,6 +838,20 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 'rest_invalid_param', $response->as_error()->get_error_code() ); } + public function test_update_item_en_US_locale() { + $user_id = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); + $this->allow_user_to_manage_multisite(); + wp_set_current_user( self::$user ); + + $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id ); + $request->set_param( 'locale', 'en_US' ); + $response = $this->server->dispatch( $request ); + $this->check_add_edit_user_response( $response, true ); + + $user = get_userdata( $user_id ); + $this->assertEquals( 'en_US', $user->locale ); + } + public function test_update_item_username_attempt() { $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); $user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) );