- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r41760 r42343 16 16 protected static $draft_editor; 17 17 protected static $authors = array(); 18 protected static $posts = array();18 protected static $posts = array(); 19 19 protected static $site; 20 20 21 21 public static function wpSetUpBeforeClass( $factory ) { 22 self::$superadmin = $factory->user->create( array( 23 'role' => 'administrator', 24 'user_login' => 'superadmin', 25 ) ); 26 self::$user = $factory->user->create( array( 27 'role' => 'administrator', 28 ) ); 29 self::$editor = $factory->user->create( array( 30 'role' => 'editor', 31 'user_email' => 'editor@example.com', 32 ) ); 33 self::$draft_editor = $factory->user->create( array( 34 'role' => 'editor', 35 'user_email' => 'draft-editor@example.com', 36 ) ); 22 self::$superadmin = $factory->user->create( 23 array( 24 'role' => 'administrator', 25 'user_login' => 'superadmin', 26 ) 27 ); 28 self::$user = $factory->user->create( 29 array( 30 'role' => 'administrator', 31 ) 32 ); 33 self::$editor = $factory->user->create( 34 array( 35 'role' => 'editor', 36 'user_email' => 'editor@example.com', 37 ) 38 ); 39 self::$draft_editor = $factory->user->create( 40 array( 41 'role' => 'editor', 42 'user_email' => 'draft-editor@example.com', 43 ) 44 ); 37 45 38 46 foreach ( array( true, false ) as $show_in_rest ) { 39 47 foreach ( array( true, false ) as $public ) { 40 48 $post_type_name = 'r_' . json_encode( $show_in_rest ) . '_p_' . json_encode( $public ); 41 register_post_type( $post_type_name, array( 42 'public' => $public, 43 'show_in_rest' => $show_in_rest, 44 'tests_no_auto_unregister' => true, 45 ) ); 46 self::$authors[ $post_type_name ] = $factory->user->create( array( 47 'role' => 'editor', 48 'user_email' => 'author_' . $post_type_name . '@example.com', 49 ) ); 50 self::$posts[ $post_type_name ] = $factory->post->create( array( 51 'post_type' => $post_type_name, 52 'post_author' => self::$authors[ $post_type_name ], 53 ) ); 49 register_post_type( 50 $post_type_name, array( 51 'public' => $public, 52 'show_in_rest' => $show_in_rest, 53 'tests_no_auto_unregister' => true, 54 ) 55 ); 56 self::$authors[ $post_type_name ] = $factory->user->create( 57 array( 58 'role' => 'editor', 59 'user_email' => 'author_' . $post_type_name . '@example.com', 60 ) 61 ); 62 self::$posts[ $post_type_name ] = $factory->post->create( 63 array( 64 'post_type' => $post_type_name, 65 'post_author' => self::$authors[ $post_type_name ], 66 ) 67 ); 54 68 } 55 69 } 56 70 57 self::$posts['post'] = $factory->post->create( array( 58 'post_type' => 'post', 59 'post_author' => self::$editor, 60 ) ); 61 self::$posts['r_true_p_true_DRAFT'] = $factory->post->create( array( 62 'post_type' => 'r_true_p_true', 63 'post_author' => self::$draft_editor, 64 'post_status' => 'draft', 65 ) ); 71 self::$posts['post'] = $factory->post->create( 72 array( 73 'post_type' => 'post', 74 'post_author' => self::$editor, 75 ) 76 ); 77 self::$posts['r_true_p_true_DRAFT'] = $factory->post->create( 78 array( 79 'post_type' => 'r_true_p_true', 80 'post_author' => self::$draft_editor, 81 'post_status' => 'draft', 82 ) 83 ); 66 84 67 85 if ( is_multisite() ) { 68 self::$site = $factory->blog->create( array( 'domain' => 'rest.wordpress.org', 'path' => '/' ) ); 86 self::$site = $factory->blog->create( 87 array( 88 'domain' => 'rest.wordpress.org', 89 'path' => '/', 90 ) 91 ); 69 92 update_site_option( 'site_admins', array( 'superadmin' ) ); 70 93 } … … 112 135 public function test_context_param() { 113 136 // Collection 114 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );115 $response = $this->server->dispatch( $request ); 116 $data = $response->get_data();137 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 138 $response = $this->server->dispatch( $request ); 139 $data = $response->get_data(); 117 140 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 118 141 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 119 142 // Single 120 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user );121 $response = $this->server->dispatch( $request ); 122 $data = $response->get_data();143 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user ); 144 $response = $this->server->dispatch( $request ); 145 $data = $response->get_data(); 123 146 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 124 147 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 126 149 127 150 public function test_registered_query_params() { 128 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );129 $response = $this->server->dispatch( $request ); 130 $data = $response->get_data();131 $keys = array_keys( $data['endpoints'][0]['args'] );151 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 152 $response = $this->server->dispatch( $request ); 153 $data = $response->get_data(); 154 $keys = array_keys( $data['endpoints'][0]['args'] ); 132 155 sort( $keys ); 133 $this->assertEquals( array( 134 'context', 135 'exclude', 136 'include', 137 'offset', 138 'order', 139 'orderby', 140 'page', 141 'per_page', 142 'roles', 143 'search', 144 'slug', 145 ), $keys ); 156 $this->assertEquals( 157 array( 158 'context', 159 'exclude', 160 'include', 161 'offset', 162 'order', 163 'orderby', 164 'page', 165 'per_page', 166 'roles', 167 'search', 168 'slug', 169 ), $keys 170 ); 146 171 } 147 172 … … 156 181 157 182 $all_data = $response->get_data(); 158 $data = $all_data[0];183 $data = $all_data[0]; 159 184 $userdata = get_userdata( $data['id'] ); 160 185 $this->check_user_data( $userdata, $data, 'view', $data['_links'] ); … … 171 196 172 197 $all_data = $response->get_data(); 173 $data = $all_data[0];198 $data = $all_data[0]; 174 199 $userdata = get_userdata( $data['id'] ); 175 200 $this->check_user_data( $userdata, $data, 'edit', $data['_links'] ); … … 194 219 195 220 public function test_get_items_unauthenticated_includes_authors_of_post_types_shown_in_rest() { 196 $request = new WP_REST_Request( 'GET', '/wp/v2/users' );197 $response = $this->server->dispatch( $request ); 198 $users = $response->get_data();221 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 222 $response = $this->server->dispatch( $request ); 223 $users = $response->get_data(); 199 224 200 225 $rest_post_types = array_values( get_post_types( array( 'show_in_rest' => true ), 'names' ) ); … … 218 243 $user_ids = wp_list_pluck( $users, 'id' ); 219 244 220 $this->assertTrue( in_array( self::$editor 221 $this->assertTrue( in_array( self::$authors['r_true_p_true'] 245 $this->assertTrue( in_array( self::$editor, $user_ids, true ) ); 246 $this->assertTrue( in_array( self::$authors['r_true_p_true'], $user_ids, true ) ); 222 247 $this->assertTrue( in_array( self::$authors['r_true_p_false'], $user_ids, true ) ); 223 248 $this->assertCount( 3, $user_ids ); … … 225 250 226 251 public function test_get_items_unauthenticated_does_not_include_authors_of_post_types_not_shown_in_rest() { 227 $request = new WP_REST_Request( 'GET', '/wp/v2/users' );228 $response = $this->server->dispatch( $request ); 229 $users = $response->get_data();252 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 253 $response = $this->server->dispatch( $request ); 254 $users = $response->get_data(); 230 255 $user_ids = wp_list_pluck( $users, 'id' ); 231 256 232 $this->assertFalse( in_array( self::$authors['r_false_p_true'] 257 $this->assertFalse( in_array( self::$authors['r_false_p_true'], $user_ids, true ) ); 233 258 $this->assertFalse( in_array( self::$authors['r_false_p_false'], $user_ids, true ) ); 234 259 } 235 260 236 261 public function test_get_items_unauthenticated_does_not_include_users_without_published_posts() { 237 $request = new WP_REST_Request( 'GET', '/wp/v2/users' );238 $response = $this->server->dispatch( $request ); 239 $users = $response->get_data();262 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 263 $response = $this->server->dispatch( $request ); 264 $users = $response->get_data(); 240 265 $user_ids = wp_list_pluck( $users, 'id' ); 241 266 242 267 $this->assertFalse( in_array( self::$draft_editor, $user_ids, true ) ); 243 $this->assertFalse( in_array( self::$user 268 $this->assertFalse( in_array( self::$user, $user_ids, true ) ); 244 269 } 245 270 … … 247 272 wp_set_current_user( self::$user ); 248 273 for ( $i = 0; $i < 44; $i++ ) { 249 $this->factory->user->create( array( 250 'name' => "User {$i}", 251 ) ); 252 } 253 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 254 $response = $this->server->dispatch( $request ); 255 $headers = $response->get_headers(); 274 $this->factory->user->create( 275 array( 276 'name' => "User {$i}", 277 ) 278 ); 279 } 280 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 281 $response = $this->server->dispatch( $request ); 282 $headers = $response->get_headers(); 256 283 $this->assertEquals( 53, $headers['X-WP-Total'] ); 257 284 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 258 $next_link = add_query_arg( array( 259 'page' => 2, 260 ), rest_url( 'wp/v2/users' ) ); 285 $next_link = add_query_arg( 286 array( 287 'page' => 2, 288 ), rest_url( 'wp/v2/users' ) 289 ); 261 290 $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) ); 262 291 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 263 292 // 3rd page 264 $this->factory->user->create( array( 265 'name' => 'User 51', 266 ) ); 293 $this->factory->user->create( 294 array( 295 'name' => 'User 51', 296 ) 297 ); 267 298 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 268 299 $request->set_param( 'page', 3 ); 269 300 $response = $this->server->dispatch( $request ); 270 $headers = $response->get_headers();301 $headers = $response->get_headers(); 271 302 $this->assertEquals( 54, $headers['X-WP-Total'] ); 272 303 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 273 $prev_link = add_query_arg( array( 274 'page' => 2, 275 ), rest_url( 'wp/v2/users' ) ); 304 $prev_link = add_query_arg( 305 array( 306 'page' => 2, 307 ), rest_url( 'wp/v2/users' ) 308 ); 276 309 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 277 $next_link = add_query_arg( array( 278 'page' => 4, 279 ), rest_url( 'wp/v2/users' ) ); 310 $next_link = add_query_arg( 311 array( 312 'page' => 4, 313 ), rest_url( 'wp/v2/users' ) 314 ); 280 315 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 281 316 // Last page … … 283 318 $request->set_param( 'page', 6 ); 284 319 $response = $this->server->dispatch( $request ); 285 $headers = $response->get_headers();320 $headers = $response->get_headers(); 286 321 $this->assertEquals( 54, $headers['X-WP-Total'] ); 287 322 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 288 $prev_link = add_query_arg( array( 289 'page' => 5, 290 ), rest_url( 'wp/v2/users' ) ); 323 $prev_link = add_query_arg( 324 array( 325 'page' => 5, 326 ), rest_url( 'wp/v2/users' ) 327 ); 291 328 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 292 329 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); … … 295 332 $request->set_param( 'page', 8 ); 296 333 $response = $this->server->dispatch( $request ); 297 $headers = $response->get_headers();334 $headers = $response->get_headers(); 298 335 $this->assertEquals( 54, $headers['X-WP-Total'] ); 299 336 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 300 $prev_link = add_query_arg( array( 301 'page' => 6, 302 ), rest_url( 'wp/v2/users' ) ); 337 $prev_link = add_query_arg( 338 array( 339 'page' => 6, 340 ), rest_url( 'wp/v2/users' ) 341 ); 303 342 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 304 343 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); … … 310 349 $this->factory->user->create( array( 'display_name' => "User {$i}" ) ); 311 350 } 312 $request = new WP_REST_Request( 'GET', '/wp/v2/users' );351 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 313 352 $response = $this->server->dispatch( $request ); 314 353 $this->assertEquals( 10, count( $response->get_data() ) ); … … 329 368 $response = $this->server->dispatch( $request ); 330 369 $this->assertEquals( 5, count( $response->get_data() ) ); 331 $prev_link = add_query_arg( array( 332 'per_page' => 5, 333 'page' => 1, 334 ), rest_url( 'wp/v2/users' ) ); 335 $headers = $response->get_headers(); 370 $prev_link = add_query_arg( 371 array( 372 'per_page' => 5, 373 'page' => 1, 374 ), rest_url( 'wp/v2/users' ) 375 ); 376 $headers = $response->get_headers(); 336 377 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 337 378 } … … 339 380 public function test_get_items_orderby_name() { 340 381 wp_set_current_user( self::$user ); 341 $low_id = $this->factory->user->create( array( 'display_name' => 'AAAAA' ) );342 $mid_id = $this->factory->user->create( array( 'display_name' => 'NNNNN' ) );382 $low_id = $this->factory->user->create( array( 'display_name' => 'AAAAA' ) ); 383 $mid_id = $this->factory->user->create( array( 'display_name' => 'NNNNN' ) ); 343 384 $high_id = $this->factory->user->create( array( 'display_name' => 'ZZZZ' ) ); 344 385 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); … … 347 388 $request->set_param( 'per_page', 1 ); 348 389 $response = $this->server->dispatch( $request ); 349 $data = $response->get_data();390 $data = $response->get_data(); 350 391 $this->assertEquals( $high_id, $data[0]['id'] ); 351 392 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); … … 354 395 $request->set_param( 'per_page', 1 ); 355 396 $response = $this->server->dispatch( $request ); 356 $data = $response->get_data();397 $data = $response->get_data(); 357 398 $this->assertEquals( $low_id, $data[0]['id'] ); 358 399 } … … 361 402 wp_set_current_user( self::$user ); 362 403 363 $low_id = $this->factory->user->create( array( 'user_url' => 'http://a.com' ) );404 $low_id = $this->factory->user->create( array( 'user_url' => 'http://a.com' ) ); 364 405 $high_id = $this->factory->user->create( array( 'user_url' => 'http://b.com' ) ); 365 406 … … 370 411 $request->set_param( 'include', array( $low_id, $high_id ) ); 371 412 $response = $this->server->dispatch( $request ); 372 $data = $response->get_data();413 $data = $response->get_data(); 373 414 374 415 $this->assertEquals( $high_id, $data[0]['id'] ); … … 380 421 $request->set_param( 'include', array( $low_id, $high_id ) ); 381 422 $response = $this->server->dispatch( $request ); 382 $data = $response->get_data();423 $data = $response->get_data(); 383 424 $this->assertEquals( $low_id, $data[0]['id'] ); 384 425 } … … 388 429 389 430 $high_id = $this->factory->user->create( array( 'user_nicename' => 'blogin' ) ); 390 $low_id = $this->factory->user->create( array( 'user_nicename' => 'alogin' ) );431 $low_id = $this->factory->user->create( array( 'user_nicename' => 'alogin' ) ); 391 432 392 433 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); … … 396 437 $request->set_param( 'include', array( $low_id, $high_id ) ); 397 438 $response = $this->server->dispatch( $request ); 398 $data = $response->get_data();439 $data = $response->get_data(); 399 440 400 441 $this->assertEquals( $high_id, $data[0]['id'] ); … … 406 447 $request->set_param( 'include', array( $low_id, $high_id ) ); 407 448 $response = $this->server->dispatch( $request ); 408 $data = $response->get_data();449 $data = $response->get_data(); 409 450 $this->assertEquals( $low_id, $data[0]['id'] ); 410 451 } … … 421 462 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 422 463 $response = $this->server->dispatch( $request ); 423 $data = $response->get_data();464 $data = $response->get_data(); 424 465 425 466 $this->assertEquals( 'taco', $data[0]['slug'] ); … … 432 473 433 474 $high_id = $this->factory->user->create( array( 'user_email' => 'bemail@gmail.com' ) ); 434 $low_id = $this->factory->user->create( array( 'user_email' => 'aemail@gmail.com' ) );475 $low_id = $this->factory->user->create( array( 'user_email' => 'aemail@gmail.com' ) ); 435 476 436 477 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); … … 440 481 $request->set_param( 'include', array( $low_id, $high_id ) ); 441 482 $response = $this->server->dispatch( $request ); 442 $data = $response->get_data();483 $data = $response->get_data(); 443 484 $this->assertEquals( $high_id, $data[0]['id'] ); 444 485 … … 449 490 $request->set_param( 'include', array( $low_id, $high_id ) ); 450 491 $response = $this->server->dispatch( $request ); 451 $data = $response->get_data();492 $data = $response->get_data(); 452 493 $this->assertEquals( $low_id, $data[0]['id'] ); 453 494 } … … 507 548 public function test_get_items_include_query() { 508 549 wp_set_current_user( self::$user ); 509 $id1 = $this->factory->user->create();510 $id2 = $this->factory->user->create();511 $id3 = $this->factory->user->create();550 $id1 = $this->factory->user->create(); 551 $id2 = $this->factory->user->create(); 552 $id3 = $this->factory->user->create(); 512 553 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 513 554 // Orderby=>asc 514 555 $request->set_param( 'include', array( $id3, $id1 ) ); 515 556 $response = $this->server->dispatch( $request ); 516 $data = $response->get_data();557 $data = $response->get_data(); 517 558 $this->assertEquals( 2, count( $data ) ); 518 559 $this->assertEquals( $id1, $data[0]['id'] ); … … 520 561 $request->set_param( 'orderby', 'include' ); 521 562 $response = $this->server->dispatch( $request ); 522 $data = $response->get_data();563 $data = $response->get_data(); 523 564 $this->assertEquals( 2, count( $data ) ); 524 565 $this->assertEquals( $id3, $data[0]['id'] ); … … 531 572 wp_set_current_user( 0 ); 532 573 $response = $this->server->dispatch( $request ); 533 $data = $response->get_data();574 $data = $response->get_data(); 534 575 $this->assertEquals( 0, count( $data ) ); 535 576 … … 538 579 public function test_get_items_exclude_query() { 539 580 wp_set_current_user( self::$user ); 540 $id1 = $this->factory->user->create();541 $id2 = $this->factory->user->create();581 $id1 = $this->factory->user->create(); 582 $id2 = $this->factory->user->create(); 542 583 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 543 584 $request->set_param( 'per_page', 20 ); // there are >10 users at this point 544 585 $response = $this->server->dispatch( $request ); 545 $data = $response->get_data();586 $data = $response->get_data(); 546 587 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 547 588 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 548 589 $request->set_param( 'exclude', array( $id2 ) ); 549 590 $response = $this->server->dispatch( $request ); 550 $data = $response->get_data();591 $data = $response->get_data(); 551 592 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 552 593 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); … … 569 610 $this->assertEquals( 1, count( $response->get_data() ) ); 570 611 // default to wildcard search 571 $adam_id = $this->factory->user->create( array( 572 'role' => 'author', 573 'user_nicename' => 'adam', 574 ) ); 612 $adam_id = $this->factory->user->create( 613 array( 614 'role' => 'author', 615 'user_nicename' => 'adam', 616 ) 617 ); 575 618 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 576 619 $request->set_param( 'search', 'ada' ); 577 620 $response = $this->server->dispatch( $request ); 578 $data = $response->get_data();621 $data = $response->get_data(); 579 622 $this->assertEquals( 1, count( $data ) ); 580 623 $this->assertEquals( $adam_id, $data[0]['id'] ); … … 583 626 public function test_get_items_slug_query() { 584 627 wp_set_current_user( self::$user ); 585 $this->factory->user->create( array( 'display_name' => 'foo', 'user_login' => 'bar' ) ); 586 $id2 = $this->factory->user->create( array( 'display_name' => 'Moo', 'user_login' => 'foo' ) ); 628 $this->factory->user->create( 629 array( 630 'display_name' => 'foo', 631 'user_login' => 'bar', 632 ) 633 ); 634 $id2 = $this->factory->user->create( 635 array( 636 'display_name' => 'Moo', 637 'user_login' => 'foo', 638 ) 639 ); 587 640 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 588 641 $request->set_param( 'slug', 'foo' ); 589 642 $response = $this->server->dispatch( $request ); 590 $data = $response->get_data();643 $data = $response->get_data(); 591 644 $this->assertEquals( 1, count( $data ) ); 592 645 $this->assertEquals( $id2, $data[0]['id'] ); … … 595 648 public function test_get_items_slug_array_query() { 596 649 wp_set_current_user( self::$user ); 597 $id1 = $this->factory->user->create( array( 598 'display_name' => 'Taco', 599 'user_login' => 'taco' 600 ) ); 601 $id2 = $this->factory->user->create( array( 602 'display_name' => 'Enchilada', 603 'user_login' => 'enchilada' 604 ) ); 605 $id3 = $this->factory->user->create( array( 606 'display_name' => 'Burrito', 607 'user_login' => 'burrito' 608 ) ); 609 $this->factory->user->create( array( 610 'display_name' => 'Hon Pizza', 611 'user_login' => 'pizza' 612 ) ); 613 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 614 $request->set_param( 'slug', array( 615 'taco', 616 'burrito', 617 'enchilada', 618 ) ); 650 $id1 = $this->factory->user->create( 651 array( 652 'display_name' => 'Taco', 653 'user_login' => 'taco', 654 ) 655 ); 656 $id2 = $this->factory->user->create( 657 array( 658 'display_name' => 'Enchilada', 659 'user_login' => 'enchilada', 660 ) 661 ); 662 $id3 = $this->factory->user->create( 663 array( 664 'display_name' => 'Burrito', 665 'user_login' => 'burrito', 666 ) 667 ); 668 $this->factory->user->create( 669 array( 670 'display_name' => 'Hon Pizza', 671 'user_login' => 'pizza', 672 ) 673 ); 674 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 675 $request->set_param( 676 'slug', array( 677 'taco', 678 'burrito', 679 'enchilada', 680 ) 681 ); 619 682 $request->set_param( 'orderby', 'slug' ); 620 683 $request->set_param( 'order', 'asc' ); 621 684 $response = $this->server->dispatch( $request ); 622 685 $this->assertEquals( 200, $response->get_status() ); 623 $data = $response->get_data();686 $data = $response->get_data(); 624 687 $slugs = wp_list_pluck( $data, 'slug' ); 625 688 $this->assertEquals( array( 'burrito', 'enchilada', 'taco' ), $slugs ); … … 628 691 public function test_get_items_slug_csv_query() { 629 692 wp_set_current_user( self::$user ); 630 $id1 = $this->factory->user->create( array( 631 'display_name' => 'Taco', 632 'user_login' => 'taco' 633 ) ); 634 $id2 = $this->factory->user->create( array( 635 'display_name' => 'Enchilada', 636 'user_login' => 'enchilada' 637 ) ); 638 $id3 = $this->factory->user->create( array( 639 'display_name' => 'Burrito', 640 'user_login' => 'burrito' 641 ) ); 642 $this->factory->user->create( array( 643 'display_name' => 'Hon Pizza', 644 'user_login' => 'pizza' 645 ) ); 646 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 647 $request->set_param( 'slug', 'taco,burrito , enchilada'); 693 $id1 = $this->factory->user->create( 694 array( 695 'display_name' => 'Taco', 696 'user_login' => 'taco', 697 ) 698 ); 699 $id2 = $this->factory->user->create( 700 array( 701 'display_name' => 'Enchilada', 702 'user_login' => 'enchilada', 703 ) 704 ); 705 $id3 = $this->factory->user->create( 706 array( 707 'display_name' => 'Burrito', 708 'user_login' => 'burrito', 709 ) 710 ); 711 $this->factory->user->create( 712 array( 713 'display_name' => 'Hon Pizza', 714 'user_login' => 'pizza', 715 ) 716 ); 717 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 718 $request->set_param( 'slug', 'taco,burrito , enchilada' ); 648 719 $request->set_param( 'orderby', 'slug' ); 649 720 $request->set_param( 'order', 'desc' ); 650 721 $response = $this->server->dispatch( $request ); 651 722 $this->assertEquals( 200, $response->get_status() ); 652 $data = $response->get_data();723 $data = $response->get_data(); 653 724 $slugs = wp_list_pluck( $data, 'slug' ); 654 725 $this->assertEquals( array( 'taco', 'enchilada', 'burrito' ), $slugs ); … … 658 729 public function test_get_items_roles() { 659 730 wp_set_current_user( self::$user ); 660 $tango = $this->factory->user->create( array( 'display_name' => 'tango', 'role' => 'subscriber' ) ); 661 $yolo = $this->factory->user->create( array( 'display_name' => 'yolo', 'role' => 'author' ) ); 731 $tango = $this->factory->user->create( 732 array( 733 'display_name' => 'tango', 734 'role' => 'subscriber', 735 ) 736 ); 737 $yolo = $this->factory->user->create( 738 array( 739 'display_name' => 'yolo', 740 'role' => 'author', 741 ) 742 ); 662 743 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 663 744 $request->set_param( 'roles', 'author,subscriber' ); 664 745 $response = $this->server->dispatch( $request ); 665 $data = $response->get_data();746 $data = $response->get_data(); 666 747 $this->assertEquals( 2, count( $data ) ); 667 748 $this->assertEquals( $tango, $data[0]['id'] ); … … 669 750 $request->set_param( 'roles', 'author' ); 670 751 $response = $this->server->dispatch( $request ); 671 $data = $response->get_data();752 $data = $response->get_data(); 672 753 $this->assertEquals( 1, count( $data ) ); 673 754 $this->assertEquals( $yolo, $data[0]['id'] ); … … 684 765 public function test_get_items_invalid_roles() { 685 766 wp_set_current_user( self::$user ); 686 $lolz = $this->factory->user->create( array( 'display_name' => 'lolz', 'role' => 'author' ) ); 767 $lolz = $this->factory->user->create( 768 array( 769 'display_name' => 'lolz', 770 'role' => 'author', 771 ) 772 ); 687 773 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 688 774 $request->set_param( 'roles', 'ilovesteak,author' ); 689 775 $response = $this->server->dispatch( $request ); 690 $data = $response->get_data();776 $data = $response->get_data(); 691 777 $this->assertEquals( 1, count( $data ) ); 692 778 $this->assertEquals( $lolz, $data[0]['id'] ); … … 694 780 $request->set_param( 'roles', 'steakisgood' ); 695 781 $response = $this->server->dispatch( $request ); 696 $data = $response->get_data();782 $data = $response->get_data(); 697 783 $this->assertEquals( 0, count( $data ) ); 698 784 $this->assertEquals( array(), $data ); … … 726 812 727 813 $data = $response->get_data(); 728 $this->assertArrayHasKey( 24, 729 $this->assertArrayHasKey( 48, 730 $this->assertArrayHasKey( 96, 814 $this->assertArrayHasKey( 24, $data['avatar_urls'] ); 815 $this->assertArrayHasKey( 48, $data['avatar_urls'] ); 816 $this->assertArrayHasKey( 96, $data['avatar_urls'] ); 731 817 732 818 $user = get_user_by( 'id', self::$editor ); … … 740 826 public function test_get_user_invalid_id() { 741 827 wp_set_current_user( self::$user ); 742 $request = new WP_REST_Request( 'GET', '/wp/v2/users/100' );828 $request = new WP_REST_Request( 'GET', '/wp/v2/users/100' ); 743 829 $response = $this->server->dispatch( $request ); 744 830 … … 750 836 $this->allow_user_to_manage_multisite(); 751 837 752 $lolz = $this->factory->user->create( array( 'display_name' => 'lolz', 'roles' => '' ) ); 838 $lolz = $this->factory->user->create( 839 array( 840 'display_name' => 'lolz', 841 'roles' => '', 842 ) 843 ); 753 844 delete_user_option( $lolz, 'capabilities' ); 754 845 delete_user_option( $lolz, 'user_level' ); … … 769 860 public function test_cannot_get_item_without_permission() { 770 861 wp_set_current_user( self::$editor ); 771 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$user ) );862 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$user ) ); 772 863 $response = $this->server->dispatch( $request ); 773 864 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 ); … … 775 866 776 867 public function test_can_get_item_author_of_rest_true_public_true_unauthenticated() { 777 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) );868 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) ); 778 869 $response = $this->server->dispatch( $request ); 779 870 $this->assertEquals( 200, $response->get_status() ); … … 782 873 public function test_can_get_item_author_of_rest_true_public_true_authenticated() { 783 874 wp_set_current_user( self::$editor ); 784 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) );875 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) ); 785 876 $response = $this->server->dispatch( $request ); 786 877 $this->assertEquals( 200, $response->get_status() ); … … 788 879 789 880 public function test_can_get_item_author_of_rest_true_public_false() { 790 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_false'] ) );881 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_false'] ) ); 791 882 $response = $this->server->dispatch( $request ); 792 883 $this->assertEquals( 200, $response->get_status() ); … … 794 885 795 886 public function test_cannot_get_item_author_of_rest_false_public_true_unauthenticated() { 796 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) );887 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) ); 797 888 $response = $this->server->dispatch( $request ); 798 889 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); … … 801 892 public function test_cannot_get_item_author_of_rest_false_public_true_without_permission() { 802 893 wp_set_current_user( self::$editor ); 803 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) );894 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_true'] ) ); 804 895 $response = $this->server->dispatch( $request ); 805 896 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 403 ); … … 807 898 808 899 public function test_cannot_get_item_author_of_rest_false_public_false() { 809 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_false'] ) );900 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_false_p_false'] ) ); 810 901 $response = $this->server->dispatch( $request ); 811 902 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); … … 813 904 814 905 public function test_can_get_item_author_of_post() { 815 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) );906 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) ); 816 907 $response = $this->server->dispatch( $request ); 817 908 $this->assertEquals( 200, $response->get_status() ); … … 819 910 820 911 public function test_cannot_get_item_author_of_draft() { 821 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$draft_editor ) );912 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$draft_editor ) ); 822 913 $response = $this->server->dispatch( $request ); 823 914 $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 ); … … 825 916 826 917 public function test_get_item_published_author_post() { 827 $this->author_id = $this->factory->user->create( array( 828 'role' => 'author', 829 ) ); 830 $this->post_id = $this->factory->post->create( array( 831 'post_author' => $this->author_id, 832 )); 918 $this->author_id = $this->factory->user->create( 919 array( 920 'role' => 'author', 921 ) 922 ); 923 $this->post_id = $this->factory->post->create( 924 array( 925 'post_author' => $this->author_id, 926 ) 927 ); 833 928 wp_set_current_user( 0 ); 834 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );929 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); 835 930 $response = $this->server->dispatch( $request ); 836 931 $this->check_get_user_response( $response, 'embed' ); … … 838 933 839 934 public function test_get_item_published_author_pages() { 840 $this->author_id = $this->factory->user->create( array( 841 'role' => 'author', 842 ) ); 935 $this->author_id = $this->factory->user->create( 936 array( 937 'role' => 'author', 938 ) 939 ); 843 940 wp_set_current_user( 0 ); 844 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );941 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); 845 942 $response = $this->server->dispatch( $request ); 846 943 $this->assertEquals( 401, $response->get_status() ); 847 $this->post_id = $this->factory->post->create( array( 848 'post_author' => $this->author_id, 849 'post_type' => 'page', 850 )); 851 $response = $this->server->dispatch( $request ); 944 $this->post_id = $this->factory->post->create( 945 array( 946 'post_author' => $this->author_id, 947 'post_type' => 'page', 948 ) 949 ); 950 $response = $this->server->dispatch( $request ); 852 951 $this->check_get_user_response( $response, 'embed' ); 853 952 } … … 865 964 866 965 public function test_get_item_published_author_wrong_context() { 867 $this->author_id = $this->factory->user->create( array( 868 'role' => 'author', 869 ) ); 870 $this->post_id = $this->factory->post->create( array( 871 'post_author' => $this->author_id, 872 )); 966 $this->author_id = $this->factory->user->create( 967 array( 968 'role' => 'author', 969 ) 970 ); 971 $this->post_id = $this->factory->post->create( 972 array( 973 'post_author' => $this->author_id, 974 ) 975 ); 873 976 wp_set_current_user( 0 ); 874 977 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); … … 896 999 public function test_get_current_user_without_permission() { 897 1000 wp_set_current_user( 0 ); 898 $request = new WP_REST_Request( 'GET', '/wp/v2/users/me' );1001 $request = new WP_REST_Request( 'GET', '/wp/v2/users/me' ); 899 1002 $response = $this->server->dispatch( $request ); 900 1003 … … 923 1026 924 1027 $response = $this->server->dispatch( $request ); 925 $data = $response->get_data();1028 $data = $response->get_data(); 926 1029 $this->assertEquals( 'http://example.com', $data['url'] ); 927 1030 $this->assertEquals( array( 'editor' ), $data['roles'] ); … … 1029 1132 $request->set_body_params( $params ); 1030 1133 $response = $this->server->dispatch( $request ); 1031 $data = $response->get_data();1032 $user_id = $data['id'];1134 $data = $response->get_data(); 1135 $user_id = $data['id']; 1033 1136 1034 1137 $user_is_member = is_user_member_of_blog( $user_id, self::$site ); … … 1083 1186 $request->set_body_params( $params ); 1084 1187 $response = $this->server->dispatch( $request ); 1085 $data = $response->get_data();1086 $user_id = $data['id'];1188 $data = $response->get_data(); 1189 $user_id = $data['id']; 1087 1190 1088 1191 restore_current_blog(); … … 1113 1216 $request->set_body_params( $params ); 1114 1217 $response = $this->server->dispatch( $request ); 1115 $data = $response->get_data();1116 $user_id = $data['id'];1218 $data = $response->get_data(); 1219 $user_id = $data['id']; 1117 1220 1118 1221 switch_to_blog( self::$site ); … … 1235 1338 1236 1339 public function test_update_item() { 1237 $user_id = $this->factory->user->create( array( 1238 'user_email' => 'test@example.com', 1239 'user_pass' => 'sjflsfls', 1240 'user_login' => 'test_update', 1241 'first_name' => 'Old Name', 1242 'user_url' => 'http://apple.com', 1243 'locale' => 'en_US', 1244 )); 1245 $this->allow_user_to_manage_multisite(); 1246 wp_set_current_user( self::$user ); 1247 1248 $userdata = get_userdata( $user_id ); 1340 $user_id = $this->factory->user->create( 1341 array( 1342 'user_email' => 'test@example.com', 1343 'user_pass' => 'sjflsfls', 1344 'user_login' => 'test_update', 1345 'first_name' => 'Old Name', 1346 'user_url' => 'http://apple.com', 1347 'locale' => 'en_US', 1348 ) 1349 ); 1350 $this->allow_user_to_manage_multisite(); 1351 wp_set_current_user( self::$user ); 1352 1353 $userdata = get_userdata( $user_id ); 1249 1354 $pw_before = $userdata->user_pass; 1250 1355 1251 $_POST['email'] = $userdata->user_email;1252 $_POST['username'] = $userdata->user_login;1356 $_POST['email'] = $userdata->user_email; 1357 $_POST['username'] = $userdata->user_login; 1253 1358 $_POST['first_name'] = 'New Name'; 1254 $_POST['url'] = 'http://google.com';1255 $_POST['locale'] = 'de_DE';1359 $_POST['url'] = 'http://google.com'; 1360 $_POST['locale'] = 'de_DE'; 1256 1361 1257 1362 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); … … 1295 1400 1296 1401 public function test_update_item_existing_email() { 1297 $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); 1298 $user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) ); 1402 $user1 = $this->factory->user->create( 1403 array( 1404 'user_login' => 'test_json_user', 1405 'user_email' => 'testjson@example.com', 1406 ) 1407 ); 1408 $user2 = $this->factory->user->create( 1409 array( 1410 'user_login' => 'test_json_user2', 1411 'user_email' => 'testjson2@example.com', 1412 ) 1413 ); 1299 1414 $this->allow_user_to_manage_multisite(); 1300 1415 wp_set_current_user( self::$user ); … … 1308 1423 1309 1424 public function test_update_item_invalid_locale() { 1310 $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); 1425 $user1 = $this->factory->user->create( 1426 array( 1427 'user_login' => 'test_json_user', 1428 'user_email' => 'testjson@example.com', 1429 ) 1430 ); 1311 1431 $this->allow_user_to_manage_multisite(); 1312 1432 wp_set_current_user( self::$user ); … … 1320 1440 1321 1441 public function test_update_item_en_US_locale() { 1322 $user_id = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); 1442 $user_id = $this->factory->user->create( 1443 array( 1444 'user_login' => 'test_json_user', 1445 'user_email' => 'testjson@example.com', 1446 ) 1447 ); 1323 1448 $this->allow_user_to_manage_multisite(); 1324 1449 wp_set_current_user( self::$user ); … … 1337 1462 */ 1338 1463 public function test_update_item_empty_locale() { 1339 $user_id = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com', 'locale' => 'de_DE' ) ); 1464 $user_id = $this->factory->user->create( 1465 array( 1466 'user_login' => 'test_json_user', 1467 'user_email' => 'testjson@example.com', 1468 'locale' => 'de_DE', 1469 ) 1470 ); 1340 1471 $this->allow_user_to_manage_multisite(); 1341 1472 wp_set_current_user( self::$user ); … … 1353 1484 1354 1485 public function test_update_item_username_attempt() { 1355 $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); 1356 $user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) ); 1486 $user1 = $this->factory->user->create( 1487 array( 1488 'user_login' => 'test_json_user', 1489 'user_email' => 'testjson@example.com', 1490 ) 1491 ); 1492 $user2 = $this->factory->user->create( 1493 array( 1494 'user_login' => 'test_json_user2', 1495 'user_email' => 'testjson2@example.com', 1496 ) 1497 ); 1357 1498 $this->allow_user_to_manage_multisite(); 1358 1499 wp_set_current_user( self::$user ); … … 1366 1507 1367 1508 public function test_update_item_existing_nicename() { 1368 $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); 1369 $user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) ); 1509 $user1 = $this->factory->user->create( 1510 array( 1511 'user_login' => 'test_json_user', 1512 'user_email' => 'testjson@example.com', 1513 ) 1514 ); 1515 $user2 = $this->factory->user->create( 1516 array( 1517 'user_login' => 'test_json_user2', 1518 'user_email' => 'testjson2@example.com', 1519 ) 1520 ); 1370 1521 $this->allow_user_to_manage_multisite(); 1371 1522 wp_set_current_user( self::$user ); … … 1379 1530 1380 1531 public function test_json_update_user() { 1381 $user_id = $this->factory->user->create( array( 1382 'user_email' => 'testjson2@example.com', 1383 'user_pass' => 'sjflsfl3sdjls', 1384 'user_login' => 'test_json_update', 1385 'first_name' => 'Old Name', 1386 'last_name' => 'Original Last', 1387 )); 1532 $user_id = $this->factory->user->create( 1533 array( 1534 'user_email' => 'testjson2@example.com', 1535 'user_pass' => 'sjflsfl3sdjls', 1536 'user_login' => 'test_json_update', 1537 'first_name' => 'Old Name', 1538 'last_name' => 'Original Last', 1539 ) 1540 ); 1388 1541 $this->allow_user_to_manage_multisite(); 1389 1542 wp_set_current_user( self::$user ); … … 1396 1549 ); 1397 1550 1398 $userdata = get_userdata( $user_id );1551 $userdata = get_userdata( $user_id ); 1399 1552 $pw_before = $userdata->user_pass; 1400 1553 … … 1616 1769 */ 1617 1770 public function test_update_item_only_roles_as_editor() { 1618 $user_id = $this->factory->user->create( array( 1619 'role' => 'author', 1620 ) ); 1771 $user_id = $this->factory->user->create( 1772 array( 1773 'role' => 'author', 1774 ) 1775 ); 1621 1776 1622 1777 wp_set_current_user( self::$editor ); … … 1631 1786 */ 1632 1787 public function test_update_item_only_roles_as_site_administrator() { 1633 $user_id = $this->factory->user->create( array( 1634 'role' => 'author', 1635 ) ); 1788 $user_id = $this->factory->user->create( 1789 array( 1790 'role' => 'author', 1791 ) 1792 ); 1636 1793 1637 1794 wp_set_current_user( self::$user ); … … 1649 1806 */ 1650 1807 public function test_update_item_including_roles_and_other_params() { 1651 $user_id = $this->factory->user->create( array( 1652 'role' => 'author', 1653 ) ); 1808 $user_id = $this->factory->user->create( 1809 array( 1810 'role' => 'author', 1811 ) 1812 ); 1654 1813 1655 1814 wp_set_current_user( self::$user ); … … 1705 1864 1706 1865 // Compare expected API output to actual API output 1707 $this->assertEquals( $expected_output['username'] 1708 $this->assertEquals( $expected_output['name'] 1709 $this->assertEquals( $expected_output['first_name'] 1710 $this->assertEquals( $expected_output['last_name'] 1711 $this->assertEquals( $expected_output['url'] 1866 $this->assertEquals( $expected_output['username'], $actual_output['username'] ); 1867 $this->assertEquals( $expected_output['name'], $actual_output['name'] ); 1868 $this->assertEquals( $expected_output['first_name'], $actual_output['first_name'] ); 1869 $this->assertEquals( $expected_output['last_name'], $actual_output['last_name'] ); 1870 $this->assertEquals( $expected_output['url'], $actual_output['url'] ); 1712 1871 $this->assertEquals( $expected_output['description'], $actual_output['description'] ); 1713 $this->assertEquals( $expected_output['nickname'] 1872 $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] ); 1714 1873 1715 1874 // Compare expected API output to WP internal values 1716 1875 $user = get_userdata( $actual_output['id'] ); 1717 $this->assertEquals( $expected_output['username'] 1718 $this->assertEquals( $expected_output['name'] 1719 $this->assertEquals( $expected_output['first_name'] 1720 $this->assertEquals( $expected_output['last_name'] 1721 $this->assertEquals( $expected_output['url'] 1876 $this->assertEquals( $expected_output['username'], $user->user_login ); 1877 $this->assertEquals( $expected_output['name'], $user->display_name ); 1878 $this->assertEquals( $expected_output['first_name'], $user->first_name ); 1879 $this->assertEquals( $expected_output['last_name'], $user->last_name ); 1880 $this->assertEquals( $expected_output['url'], $user->user_url ); 1722 1881 $this->assertEquals( $expected_output['description'], $user->description ); 1723 $this->assertEquals( $expected_output['nickname'] 1882 $this->assertEquals( $expected_output['nickname'], $user->nickname ); 1724 1883 $this->assertTrue( wp_check_password( addslashes( $expected_output['password'] ), $user->user_pass ) ); 1725 1884 … … 1742 1901 $this->assertEquals( $expected_output['username'], $actual_output['username'] ); 1743 1902 } 1744 $this->assertEquals( $expected_output['name'] 1745 $this->assertEquals( $expected_output['first_name'] 1746 $this->assertEquals( $expected_output['last_name'] 1747 $this->assertEquals( $expected_output['url'] 1903 $this->assertEquals( $expected_output['name'], $actual_output['name'] ); 1904 $this->assertEquals( $expected_output['first_name'], $actual_output['first_name'] ); 1905 $this->assertEquals( $expected_output['last_name'], $actual_output['last_name'] ); 1906 $this->assertEquals( $expected_output['url'], $actual_output['url'] ); 1748 1907 $this->assertEquals( $expected_output['description'], $actual_output['description'] ); 1749 $this->assertEquals( $expected_output['nickname'] 1908 $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] ); 1750 1909 1751 1910 // Compare expected API output to WP internal values … … 1754 1913 $this->assertEquals( $expected_output['username'], $user->user_login ); 1755 1914 } 1756 $this->assertEquals( $expected_output['name'] 1757 $this->assertEquals( $expected_output['first_name'] 1758 $this->assertEquals( $expected_output['last_name'] 1759 $this->assertEquals( $expected_output['url'] 1915 $this->assertEquals( $expected_output['name'], $user->display_name ); 1916 $this->assertEquals( $expected_output['first_name'], $user->first_name ); 1917 $this->assertEquals( $expected_output['last_name'], $user->last_name ); 1918 $this->assertEquals( $expected_output['url'], $user->user_url ); 1760 1919 $this->assertEquals( $expected_output['description'], $user->description ); 1761 $this->assertEquals( $expected_output['nickname'] 1920 $this->assertEquals( $expected_output['nickname'], $user->nickname ); 1762 1921 $this->assertTrue( wp_check_password( addslashes( $expected_output['password'] ), $user->user_pass ) ); 1763 1922 } … … 1766 1925 wp_set_current_user( self::$editor ); 1767 1926 $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) ); 1768 $this->verify_user_roundtrip( array( 1769 'id' => self::$editor, 1770 'name' => '\o/ ¯\_(ツ)_/¯', 1771 'first_name' => '\o/ ¯\_(ツ)_/¯', 1772 'last_name' => '\o/ ¯\_(ツ)_/¯', 1773 'url' => '\o/ ¯\_(ツ)_/¯', 1774 'description' => '\o/ ¯\_(ツ)_/¯', 1775 'nickname' => '\o/ ¯\_(ツ)_/¯', 1776 'password' => 'o/ ¯_(ツ)_/¯ \'"', 1777 ), array( 1778 'name' => '\o/ ¯\_(ツ)_/¯', 1779 'first_name' => '\o/ ¯\_(ツ)_/¯', 1780 'last_name' => '\o/ ¯\_(ツ)_/¯', 1781 'url' => 'http://o/%20¯_(ツ)_/¯', 1782 'description' => '\o/ ¯\_(ツ)_/¯', 1783 'nickname' => '\o/ ¯\_(ツ)_/¯', 1784 'password' => 'o/ ¯_(ツ)_/¯ \'"', 1785 ) ); 1927 $this->verify_user_roundtrip( 1928 array( 1929 'id' => self::$editor, 1930 'name' => '\o/ ¯\_(ツ)_/¯', 1931 'first_name' => '\o/ ¯\_(ツ)_/¯', 1932 'last_name' => '\o/ ¯\_(ツ)_/¯', 1933 'url' => '\o/ ¯\_(ツ)_/¯', 1934 'description' => '\o/ ¯\_(ツ)_/¯', 1935 'nickname' => '\o/ ¯\_(ツ)_/¯', 1936 'password' => 'o/ ¯_(ツ)_/¯ \'"', 1937 ), array( 1938 'name' => '\o/ ¯\_(ツ)_/¯', 1939 'first_name' => '\o/ ¯\_(ツ)_/¯', 1940 'last_name' => '\o/ ¯\_(ツ)_/¯', 1941 'url' => 'http://o/%20¯_(ツ)_/¯', 1942 'description' => '\o/ ¯\_(ツ)_/¯', 1943 'nickname' => '\o/ ¯\_(ツ)_/¯', 1944 'password' => 'o/ ¯_(ツ)_/¯ \'"', 1945 ) 1946 ); 1786 1947 } 1787 1948 … … 1790 1951 if ( is_multisite() ) { 1791 1952 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 1792 $this->verify_user_roundtrip( array( 1793 'id' => self::$editor, 1953 $this->verify_user_roundtrip( 1954 array( 1955 'id' => self::$editor, 1956 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1957 'first_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1958 'last_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1959 'url' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1960 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1961 'nickname' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1962 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1963 ), array( 1964 'name' => 'div strong', 1965 'first_name' => 'div strong', 1966 'last_name' => 'div strong', 1967 'url' => 'http://divdiv/div%20strongstrong/strong%20scriptoh%20noes/script', 1968 'description' => 'div <strong>strong</strong> oh noes', 1969 'nickname' => 'div strong', 1970 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1971 ) 1972 ); 1973 } else { 1974 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 1975 $this->verify_user_roundtrip( 1976 array( 1977 'id' => self::$editor, 1978 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1979 'first_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1980 'last_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1981 'url' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1982 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1983 'nickname' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1984 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1985 ), array( 1986 'name' => 'div strong', 1987 'first_name' => 'div strong', 1988 'last_name' => 'div strong', 1989 'url' => 'http://divdiv/div%20strongstrong/strong%20scriptoh%20noes/script', 1990 'description' => 'div <strong>strong</strong> oh noes', 1991 'nickname' => 'div strong', 1992 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1993 ) 1994 ); 1995 } 1996 } 1997 1998 public function test_user_roundtrip_as_superadmin() { 1999 wp_set_current_user( self::$superadmin ); 2000 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 2001 $valid_username = is_multisite() ? 'noinvalidcharshere' : 'no-invalid-chars-here'; 2002 $this->verify_user_roundtrip( 2003 array( 2004 'username' => $valid_username, 2005 'name' => '\\\&\\\ & &invalid; < < &lt;', 2006 'first_name' => '\\\&\\\ & &invalid; < < &lt;', 2007 'last_name' => '\\\&\\\ & &invalid; < < &lt;', 2008 'url' => '\\\&\\\ & &invalid; < < &lt;', 2009 'description' => '\\\&\\\ & &invalid; < < &lt;', 2010 'nickname' => '\\\&\\\ & &invalid; < < &lt;', 2011 'password' => '& & &invalid; < < &lt;', 2012 ), array( 2013 'username' => $valid_username, 2014 'name' => '\\\&\\\ & &invalid; < < &lt;', 2015 'first_name' => '\\\&\\\ & &invalid; < < &lt;', 2016 'last_name' => '\\\&\\\ & &invalid; < < &lt;', 2017 'url' => 'http://&%20&%20&invalid;%20%20<%20&lt;', 2018 'description' => '\\\&\\\ & &invalid; < < &lt;', 2019 'nickname' => '\\\&\\\ & &invalid; < < &lt;', 2020 'password' => '& & &invalid; < < &lt;', 2021 ) 2022 ); 2023 } 2024 2025 public function test_user_roundtrip_as_superadmin_html() { 2026 wp_set_current_user( self::$superadmin ); 2027 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 2028 $valid_username = is_multisite() ? 'noinvalidcharshere' : 'no-invalid-chars-here'; 2029 $this->verify_user_roundtrip( 2030 array( 2031 'username' => $valid_username, 1794 2032 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1795 2033 'first_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', … … 1800 2038 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1801 2039 ), array( 2040 'username' => $valid_username, 1802 2041 'name' => 'div strong', 1803 2042 'first_name' => 'div strong', … … 1807 2046 'nickname' => 'div strong', 1808 2047 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1809 ) ); 1810 } else { 1811 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 1812 $this->verify_user_roundtrip( array( 1813 'id' => self::$editor, 1814 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1815 'first_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1816 'last_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1817 'url' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1818 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1819 'nickname' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1820 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1821 ), array( 1822 'name' => 'div strong', 1823 'first_name' => 'div strong', 1824 'last_name' => 'div strong', 1825 'url' => 'http://divdiv/div%20strongstrong/strong%20scriptoh%20noes/script', 1826 'description' => 'div <strong>strong</strong> oh noes', 1827 'nickname' => 'div strong', 1828 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1829 ) ); 1830 } 1831 } 1832 1833 public function test_user_roundtrip_as_superadmin() { 1834 wp_set_current_user( self::$superadmin ); 1835 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 1836 $valid_username = is_multisite() ? 'noinvalidcharshere' : 'no-invalid-chars-here'; 1837 $this->verify_user_roundtrip( array( 1838 'username' => $valid_username, 1839 'name' => '\\\&\\\ & &invalid; < < &lt;', 1840 'first_name' => '\\\&\\\ & &invalid; < < &lt;', 1841 'last_name' => '\\\&\\\ & &invalid; < < &lt;', 1842 'url' => '\\\&\\\ & &invalid; < < &lt;', 1843 'description' => '\\\&\\\ & &invalid; < < &lt;', 1844 'nickname' => '\\\&\\\ & &invalid; < < &lt;', 1845 'password' => '& & &invalid; < < &lt;', 1846 ), array( 1847 'username' => $valid_username, 1848 'name' => '\\\&\\\ & &invalid; < < &lt;', 1849 'first_name' => '\\\&\\\ & &invalid; < < &lt;', 1850 'last_name' => '\\\&\\\ & &invalid; < < &lt;', 1851 'url' => 'http://&%20&%20&invalid;%20%20<%20&lt;', 1852 'description' => '\\\&\\\ & &invalid; < < &lt;', 1853 'nickname' => '\\\&\\\ & &invalid; < < &lt;', 1854 'password' => '& & &invalid; < < &lt;', 1855 ) ); 1856 } 1857 1858 public function test_user_roundtrip_as_superadmin_html() { 1859 wp_set_current_user( self::$superadmin ); 1860 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 1861 $valid_username = is_multisite() ? 'noinvalidcharshere' : 'no-invalid-chars-here'; 1862 $this->verify_user_roundtrip( array( 1863 'username' => $valid_username, 1864 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1865 'first_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1866 'last_name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1867 'url' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1868 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1869 'nickname' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1870 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1871 ), array( 1872 'username' => $valid_username, 1873 'name' => 'div strong', 1874 'first_name' => 'div strong', 1875 'last_name' => 'div strong', 1876 'url' => 'http://divdiv/div%20strongstrong/strong%20scriptoh%20noes/script', 1877 'description' => 'div <strong>strong</strong> oh noes', 1878 'nickname' => 'div strong', 1879 'password' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 1880 ) ); 2048 ) 2049 ); 1881 2050 } 1882 2051 … … 1888 2057 1889 2058 $userdata = get_userdata( $user_id ); // cache for later 1890 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );2059 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1891 2060 $request->set_param( 'force', true ); 1892 2061 $request->set_param( 'reassign', false ); … … 1935 2104 1936 2105 public function test_delete_current_item() { 1937 $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) ); 2106 $user_id = $this->factory->user->create( 2107 array( 2108 'role' => 'administrator', 2109 'display_name' => 'Deleted User', 2110 ) 2111 ); 1938 2112 1939 2113 wp_set_current_user( $user_id ); … … 1941 2115 update_site_option( 'site_admins', array( $user->user_login ) ); 1942 2116 1943 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' );2117 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 1944 2118 $request['force'] = true; 1945 2119 $request->set_param( 'reassign', false ); … … 1959 2133 1960 2134 public function test_delete_current_item_no_trash() { 1961 $user_id = $this->factory->user->create( array( 'role' => 'administrator', 'display_name' => 'Deleted User' ) ); 2135 $user_id = $this->factory->user->create( 2136 array( 2137 'role' => 'administrator', 2138 'display_name' => 'Deleted User', 2139 ) 2140 ); 1962 2141 1963 2142 wp_set_current_user( $user_id ); … … 1992 2171 wp_set_current_user( self::$editor ); 1993 2172 1994 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );2173 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 1995 2174 $request['force'] = true; 1996 2175 $request->set_param( 'reassign', false ); … … 1999 2178 $this->assertErrorResponse( 'rest_user_cannot_delete', $response, 403 ); 2000 2179 2001 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' );2180 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me' ); 2002 2181 $request['force'] = true; 2003 2182 $request->set_param( 'reassign', false ); … … 2011 2190 wp_set_current_user( self::$user ); 2012 2191 2013 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/100' );2192 $request = new WP_REST_Request( 'DELETE', '/wp/v2/users/100' ); 2014 2193 $request['force'] = true; 2015 2194 $request->set_param( 'reassign', false ); … … 2023 2202 2024 2203 // Test with a new user, to avoid any complications 2025 $user_id = $this->factory->user->create();2204 $user_id = $this->factory->user->create(); 2026 2205 $reassign_id = $this->factory->user->create(); 2027 $test_post = $this->factory->post->create(array( 2028 'post_author' => $user_id, 2029 )); 2206 $test_post = $this->factory->post->create( 2207 array( 2208 'post_author' => $user_id, 2209 ) 2210 ); 2030 2211 2031 2212 // Sanity check to ensure the factory created the post correctly … … 2035 2216 // Delete our test user, and reassign to the new author 2036 2217 wp_set_current_user( self::$user ); 2037 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );2218 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2038 2219 $request['force'] = true; 2039 2220 $request->set_param( 'reassign', $reassign_id ); … … 2059 2240 wp_set_current_user( self::$user ); 2060 2241 2061 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );2242 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2062 2243 $request['force'] = true; 2063 2244 $request->set_param( 'reassign', 100 ); … … 2079 2260 wp_set_current_user( self::$user ); 2080 2261 2081 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) );2262 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2082 2263 $request['force'] = true; 2083 2264 $request->set_param( 'reassign', 'null' ); … … 2093 2274 wp_set_current_user( self::$user ); 2094 2275 2095 $test_post = $this->factory->post->create(array( 2096 'post_author' => $user_id, 2097 )); 2098 2099 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2276 $test_post = $this->factory->post->create( 2277 array( 2278 'post_author' => $user_id, 2279 ) 2280 ); 2281 2282 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2100 2283 $request['force'] = true; 2101 2284 $request->set_param( 'reassign', false ); … … 2118 2301 wp_set_current_user( self::$user ); 2119 2302 2120 $test_post = $this->factory->post->create(array( 2121 'post_author' => $user_id, 2122 )); 2123 2124 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2303 $test_post = $this->factory->post->create( 2304 array( 2305 'post_author' => $user_id, 2306 ) 2307 ); 2308 2309 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2125 2310 $request['force'] = true; 2126 2311 $request->set_param( 'reassign', 'false' ); … … 2143 2328 wp_set_current_user( self::$user ); 2144 2329 2145 $test_post = $this->factory->post->create(array( 2146 'post_author' => $user_id, 2147 )); 2148 2149 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2330 $test_post = $this->factory->post->create( 2331 array( 2332 'post_author' => $user_id, 2333 ) 2334 ); 2335 2336 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2150 2337 $request['force'] = true; 2151 2338 $request->set_param( 'reassign', '' ); … … 2168 2355 wp_set_current_user( self::$user ); 2169 2356 2170 $test_post = $this->factory->post->create(array( 2171 'post_author' => $user_id, 2172 )); 2173 2174 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2357 $test_post = $this->factory->post->create( 2358 array( 2359 'post_author' => $user_id, 2360 ) 2361 ); 2362 2363 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); 2175 2364 $request['force'] = true; 2176 2365 $request->set_param( 'reassign', 0 ); … … 2188 2377 2189 2378 public function test_get_item_schema() { 2190 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );2191 $response = $this->server->dispatch( $request );2192 $data = $response->get_data();2379 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2380 $response = $this->server->dispatch( $request ); 2381 $data = $response->get_data(); 2193 2382 $properties = $data['schema']['properties']; 2194 2383 … … 2218 2407 public function test_get_item_schema_show_avatar() { 2219 2408 update_option( 'show_avatars', false ); 2220 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );2221 $response = $this->server->dispatch( $request );2222 $data = $response->get_data();2409 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2410 $response = $this->server->dispatch( $request ); 2411 $data = $response->get_data(); 2223 2412 $properties = $data['schema']['properties']; 2224 2413 … … 2235 2424 ); 2236 2425 2237 register_rest_field( 'user', 'my_custom_int', array( 2238 'schema' => $schema, 2239 'get_callback' => array( $this, 'additional_field_get_callback' ), 2240 'update_callback' => array( $this, 'additional_field_update_callback' ), 2241 ) ); 2426 register_rest_field( 2427 'user', 'my_custom_int', array( 2428 'schema' => $schema, 2429 'get_callback' => array( $this, 'additional_field_get_callback' ), 2430 'update_callback' => array( $this, 'additional_field_update_callback' ), 2431 ) 2432 ); 2242 2433 2243 2434 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2244 2435 2245 2436 $response = $this->server->dispatch( $request ); 2246 $data = $response->get_data();2437 $data = $response->get_data(); 2247 2438 2248 2439 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 2261 2452 2262 2453 $request = new WP_REST_Request( 'POST', '/wp/v2/users/1' ); 2263 $request->set_body_params(array( 2264 'my_custom_int' => 123, 2265 )); 2454 $request->set_body_params( 2455 array( 2456 'my_custom_int' => 123, 2457 ) 2458 ); 2266 2459 2267 2460 $response = $this->server->dispatch( $request ); … … 2269 2462 2270 2463 $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); 2271 $request->set_body_params(array( 2272 'my_custom_int' => 123, 2273 'email' => 'joe@foobar.com', 2274 'username' => 'abc123', 2275 'password' => 'hello', 2276 )); 2464 $request->set_body_params( 2465 array( 2466 'my_custom_int' => 123, 2467 'email' => 'joe@foobar.com', 2468 'username' => 'abc123', 2469 'password' => 'hello', 2470 ) 2471 ); 2277 2472 2278 2473 $response = $this->server->dispatch( $request ); … … 2292 2487 ); 2293 2488 2294 register_rest_field( 'user', 'my_custom_int', array( 2295 'schema' => $schema, 2296 'get_callback' => array( $this, 'additional_field_get_callback' ), 2297 'update_callback' => array( $this, 'additional_field_update_callback' ), 2298 ) ); 2489 register_rest_field( 2490 'user', 'my_custom_int', array( 2491 'schema' => $schema, 2492 'get_callback' => array( $this, 'additional_field_get_callback' ), 2493 'update_callback' => array( $this, 'additional_field_update_callback' ), 2494 ) 2495 ); 2299 2496 2300 2497 wp_set_current_user( 1 ); … … 2306 2503 // Check for error on update. 2307 2504 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/users/%d', self::$user ) ); 2308 $request->set_body_params( array( 2309 'my_custom_int' => 'returnError', 2310 ) ); 2505 $request->set_body_params( 2506 array( 2507 'my_custom_int' => 'returnError', 2508 ) 2509 ); 2311 2510 2312 2511 $response = $this->server->dispatch( $request ); … … 2324 2523 public function test_get_item_from_different_site_as_site_administrator() { 2325 2524 switch_to_blog( self::$site ); 2326 $user_id = $this->factory->user->create( array( 2327 'role' => 'author', 2328 ) ); 2525 $user_id = $this->factory->user->create( 2526 array( 2527 'role' => 'author', 2528 ) 2529 ); 2329 2530 restore_current_blog(); 2330 2531 … … 2342 2543 public function test_get_item_from_different_site_as_network_administrator() { 2343 2544 switch_to_blog( self::$site ); 2344 $user_id = $this->factory->user->create( array( 2345 'role' => 'author', 2346 ) ); 2545 $user_id = $this->factory->user->create( 2546 array( 2547 'role' => 'author', 2548 ) 2549 ); 2347 2550 restore_current_blog(); 2348 2551 … … 2360 2563 public function test_update_item_from_different_site_as_site_administrator() { 2361 2564 switch_to_blog( self::$site ); 2362 $user_id = $this->factory->user->create( array( 2363 'role' => 'author', 2364 ) ); 2565 $user_id = $this->factory->user->create( 2566 array( 2567 'role' => 'author', 2568 ) 2569 ); 2365 2570 restore_current_blog(); 2366 2571 … … 2380 2585 public function test_update_item_from_different_site_as_network_administrator() { 2381 2586 switch_to_blog( self::$site ); 2382 $user_id = $this->factory->user->create( array( 2383 'role' => 'author', 2384 ) ); 2587 $user_id = $this->factory->user->create( 2588 array( 2589 'role' => 'author', 2590 ) 2591 ); 2385 2592 restore_current_blog(); 2386 2593 … … 2400 2607 public function test_delete_item_from_different_site_as_site_administrator() { 2401 2608 switch_to_blog( self::$site ); 2402 $user_id = $this->factory->user->create( array( 2403 'role' => 'author', 2404 ) ); 2609 $user_id = $this->factory->user->create( 2610 array( 2611 'role' => 'author', 2612 ) 2613 ); 2405 2614 restore_current_blog(); 2406 2615 … … 2420 2629 public function test_delete_item_from_different_site_as_network_administrator() { 2421 2630 switch_to_blog( self::$site ); 2422 $user_id = $this->factory->user->create( array( 2423 'role' => 'author', 2424 ) ); 2631 $user_id = $this->factory->user->create( 2632 array( 2633 'role' => 'author', 2634 ) 2635 ); 2425 2636 restore_current_blog(); 2426 2637 … … 2484 2695 } 2485 2696 2486 $this->assertEqualSets( array( 2487 'self', 2488 'collection', 2489 ), array_keys( $links ) ); 2697 $this->assertEqualSets( 2698 array( 2699 'self', 2700 'collection', 2701 ), array_keys( $links ) 2702 ); 2490 2703 2491 2704 $this->assertArrayNotHasKey( 'password', $data ); … … 2495 2708 $this->assertEquals( 200, $response->get_status() ); 2496 2709 2497 $data = $response->get_data();2710 $data = $response->get_data(); 2498 2711 $userdata = get_userdata( $data['id'] ); 2499 2712 $this->check_user_data( $userdata, $data, $context, $response->get_links() ); … … 2507 2720 } 2508 2721 2509 $data = $response->get_data();2722 $data = $response->get_data(); 2510 2723 $userdata = get_userdata( $data['id'] ); 2511 2724 $this->check_user_data( $userdata, $data, 'edit', $response->get_links() );
Note: See TracChangeset
for help on using the changeset viewer.