- Timestamp:
- 11/02/2016 06:52:30 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r39090 r39092 957 957 $this->assertArrayHasKey( 'editor', $user->caps ); 958 958 $this->assertArrayNotHasKey( 'administrator', $user->caps ); 959 960 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 961 $request->set_param( 'roles', array( 'administrator' ) ); 962 $response = $this->server->dispatch( $request ); 963 964 $this->assertErrorResponse( 'rest_cannot_edit_roles', $response, 403 ); 965 $user = get_userdata( self::$editor ); 966 $this->assertArrayHasKey( 'editor', $user->caps ); 967 $this->assertArrayNotHasKey( 'administrator', $user->caps ); 959 968 } 960 969 … … 977 986 $this->assertArrayHasKey( 'administrator', $user->caps ); 978 987 $this->assertArrayNotHasKey( 'editor', $user->caps ); 988 989 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 990 $request->set_param( 'roles', array( 'editor' ) ); 991 $response = $this->server->dispatch( $request ); 992 993 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 403 ); 994 995 $user = get_userdata( $user_id ); 996 $this->assertArrayHasKey( 'administrator', $user->caps ); 997 $this->assertArrayNotHasKey( 'editor', $user->caps ); 979 998 } 980 999 … … 997 1016 $this->assertEquals( 'editor', $new_data['roles'][0] ); 998 1017 $this->assertNotEquals( 'administrator', $new_data['roles'][0] ); 1018 1019 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 1020 1021 wp_set_current_user( $user_id ); 1022 $user = wp_get_current_user(); 1023 update_site_option( 'site_admins', array( $user->user_login ) ); 1024 1025 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1026 $request->set_param( 'roles', array( 'editor' ) ); 1027 $response = $this->server->dispatch( $request ); 1028 1029 $new_data = $response->get_data(); 1030 $this->assertEquals( 'editor', $new_data['roles'][0] ); 1031 $this->assertNotEquals( 'administrator', $new_data['roles'][0] ); 999 1032 } 1000 1033 … … 1005 1038 1006 1039 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) ); 1040 $request->set_param( 'roles', array( 'BeSharp' ) ); 1041 $response = $this->server->dispatch( $request ); 1042 1043 $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 ); 1044 1045 $user = get_userdata( self::$editor ); 1046 $this->assertArrayHasKey( 'editor', $user->caps ); 1047 $this->assertArrayNotHasKey( 'BeSharp', $user->caps ); 1048 1049 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1007 1050 $request->set_param( 'roles', array( 'BeSharp' ) ); 1008 1051 $response = $this->server->dispatch( $request ); … … 1030 1073 1031 1074 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); 1075 1076 $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me' ); 1077 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 1078 $request->set_body_params( $params ); 1079 $response = $this->server->dispatch( $request ); 1080 1081 $this->assertErrorResponse( 'rest_user_invalid_argument', $response, 400 ); 1032 1082 } 1033 1083 … … 1067 1117 } 1068 1118 1119 public function test_delete_current_item() { 1120 $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) ); 1121 1122 wp_set_current_user( $user_id ); 1123 $user = wp_get_current_user(); 1124 update_site_option( 'site_admins', array( $user->user_login ) ); 1125 1126 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1127 $request['force'] = true; 1128 $response = $this->server->dispatch( $request ); 1129 1130 $this->assertEquals( 200, $response->get_status() ); 1131 $data = $response->get_data(); 1132 $this->assertEquals( 'Deleted User', $data['name'] ); 1133 } 1134 1069 1135 public function test_delete_item_no_trash() { 1070 1136 $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); … … 1083 1149 } 1084 1150 1151 public function test_delete_current_item_no_trash() { 1152 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 1153 1154 wp_set_current_user( $user_id ); 1155 $user = wp_get_current_user(); 1156 update_site_option( 'site_admins', array( $user->user_login ) ); 1157 1158 $userdata = get_userdata( $user_id ); // cache for later 1159 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1160 $response = $this->server->dispatch( $request ); 1161 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 1162 1163 // Ensure the user still exists 1164 $user = get_user_by( 'id', $user_id ); 1165 $this->assertNotEmpty( $user ); 1166 } 1167 1085 1168 public function test_delete_user_without_permission() { 1086 1169 $user_id = $this->factory->user->create(); … … 1090 1173 1091 1174 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1175 $request['force'] = true; 1176 $response = $this->server->dispatch( $request ); 1177 1178 $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 ); 1179 1180 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1092 1181 $request['force'] = true; 1093 1182 $response = $this->server->dispatch( $request );
Note: See TracChangeset
for help on using the changeset viewer.