Changeset 39090
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r39085 r39090 697 697 } 698 698 699 if ( ! empty( $schema['properties']['locale'] ) ) { 700 $data['locale'] = get_user_locale( $user ); 701 } 702 699 703 if ( ! empty( $schema['properties']['nickname'] ) ) { 700 704 $data['nickname'] = $user->nickname; … … 832 836 if ( isset( $request['url'] ) && ! empty( $schema['properties']['url'] ) ) { 833 837 $prepared_user->user_url = $request['url']; 838 } 839 840 if ( isset( $request['locale'] ) && ! empty( $schema['properties']['locale'] ) ) { 841 $prepared_user->locale = $request['locale']; 834 842 } 835 843 … … 978 986 'context' => array( 'embed', 'view', 'edit' ), 979 987 'readonly' => true, 988 ), 989 'locale' => array( 990 'description' => __( 'Locale for the resource.' ), 991 'type' => 'string', 992 'enum' => get_available_languages(), 993 'context' => array( 'edit' ), 980 994 ), 981 995 'nickname' => array( -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r39085 r39090 778 778 'first_name' => 'Old Name', 779 779 'user_url' => 'http://apple.com', 780 'locale' => 'en_US', 780 781 )); 781 782 $this->allow_user_to_manage_multisite(); … … 789 790 $_POST['first_name'] = 'New Name'; 790 791 $_POST['url'] = 'http://google.com'; 792 $_POST['locale'] = 'de_DE'; 791 793 792 794 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); … … 805 807 $this->assertEquals( 'http://google.com', $new_data['url'] ); 806 808 $this->assertEquals( 'http://google.com', $user->user_url ); 809 $this->assertEquals( 'de_DE', $user->locale ); 807 810 808 811 // Check that we haven't inadvertently changed the user's password, … … 822 825 $this->assertInstanceOf( 'WP_Error', $response->as_error() ); 823 826 $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() ); 824 839 } 825 840 … … 1140 1155 $properties = $data['schema']['properties']; 1141 1156 1142 $this->assertEquals( 1 8, count( $properties ) );1157 $this->assertEquals( 19, count( $properties ) ); 1143 1158 $this->assertArrayHasKey( 'avatar_urls', $properties ); 1144 1159 $this->assertArrayHasKey( 'capabilities', $properties ); … … 1150 1165 $this->assertArrayHasKey( 'last_name', $properties ); 1151 1166 $this->assertArrayHasKey( 'link', $properties ); 1167 $this->assertArrayHasKey( 'locale', $properties ); 1152 1168 $this->assertArrayHasKey( 'meta', $properties ); 1153 1169 $this->assertArrayHasKey( 'name', $properties ); … … 1298 1314 $this->assertEquals( $user->user_login, $data['username'] ); 1299 1315 $this->assertEquals( $user->roles, $data['roles'] ); 1316 $this->assertEquals( get_user_locale( $user ), $data['locale'] ); 1300 1317 } 1301 1318
Note: See TracChangeset
for help on using the changeset viewer.