- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r47012 r47122 165 165 166 166 public function test_context_param() { 167 // Collection 167 // Collection. 168 168 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 169 169 $response = rest_get_server()->dispatch( $request ); … … 171 171 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 172 172 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 173 // Single 173 // Single. 174 174 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user ); 175 175 $response = rest_get_server()->dispatch( $request ); … … 664 664 $response = rest_get_server()->dispatch( $request ); 665 665 $this->assertEquals( 1, count( $response->get_data() ) ); 666 // default to wildcard search666 // Default to wildcard search. 667 667 $adam_id = $this->factory->user->create( 668 668 array( … … 789 789 } 790 790 791 // Note: Do not test using editor role as there is an editor role created in testing and it makes it hard to test this functionality. 791 /** 792 * Note: Do not test using editor role as there is an editor role created in testing, 793 * and it makes it hard to test this functionality. 794 */ 792 795 public function test_get_items_roles() { 793 796 wp_set_current_user( self::$user ); … … 948 951 949 952 $user = get_user_by( 'id', self::$editor ); 950 /** 951 * Ignore the subdomain, since 'get_avatar_url randomly sets the Gravatar 952 * server when building the url string. 953 */ 953 // Ignore the subdomain, since get_avatar_url() randomly sets 954 // the Gravatar server when building the URL string. 954 955 $this->assertEquals( substr( get_avatar_url( $user->user_email ), 9 ), substr( $data['avatar_urls'][96], 9 ) ); 955 956 } … … 1197 1198 ); 1198 1199 1199 // Username rules are different (more strict) for multisite; see `wpmu_validate_user_signup` 1200 // Username rules are different (more strict) for multisite; see `wpmu_validate_user_signup`. 1200 1201 if ( is_multisite() ) { 1201 1202 $params['username'] = 'no-dashes-allowed'; … … 1522 1523 $this->check_add_edit_user_response( $response, true ); 1523 1524 1524 // Check that the name has been updated correctly 1525 // Check that the name has been updated correctly. 1525 1526 $new_data = $response->get_data(); 1526 1527 $this->assertEquals( 'New Name', $new_data['first_name'] ); … … 1547 1548 $request->set_param( 'slug', $user->user_nicename ); 1548 1549 1549 // Run twice to make sure that the update still succeeds even if no DB1550 // rows are updated.1550 // Run twice to make sure that the update still succeeds 1551 // even if no DB rows are updated. 1551 1552 $response = rest_get_server()->dispatch( $request ); 1552 1553 $this->assertEquals( 200, $response->get_status() ); … … 1769 1770 $this->check_add_edit_user_response( $response, true ); 1770 1771 1771 // Check that the name has been updated correctly 1772 // Check that the name has been updated correctly. 1772 1773 $new_data = $response->get_data(); 1773 1774 $this->assertEquals( 'JSON Name', $new_data['first_name'] ); … … 2036 2037 2037 2038 if ( is_multisite() ) { 2038 // Site administrators can promote users, as verified by the 2039 // previous test, but they cannot perform other user-editing 2040 // operations. This also tests the branch of logic that verifies 2041 // that no parameters other than 'id' and 'roles' are specified for 2042 // a roles update. 2039 /* 2040 * Site administrators can promote users, as verified by the previous test, 2041 * but they cannot perform other user-editing operations. 2042 * This also tests the branch of logic that verifies that no parameters 2043 * other than 'id' and 'roles' are specified for a roles update. 2044 */ 2043 2045 $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); 2044 2046 } else { … … 2067 2069 public function verify_user_roundtrip( $input = array(), $expected_output = array() ) { 2068 2070 if ( isset( $input['id'] ) ) { 2069 // Existing user; don't try to create one 2071 // Existing user; don't try to create one. 2070 2072 $user_id = $input['id']; 2071 2073 } else { 2072 // Create a new user 2074 // Create a new user. 2073 2075 $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); 2074 2076 foreach ( $input as $name => $value ) { … … 2080 2082 $actual_output = $response->get_data(); 2081 2083 2082 // Compare expected API output to actual API output 2084 // Compare expected API output to actual API output. 2083 2085 $this->assertEquals( $expected_output['username'], $actual_output['username'] ); 2084 2086 $this->assertEquals( $expected_output['name'], $actual_output['name'] ); … … 2089 2091 $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] ); 2090 2092 2091 // Compare expected API output to WP internal values 2093 // Compare expected API output to WP internal values. 2092 2094 $user = get_userdata( $actual_output['id'] ); 2093 2095 $this->assertEquals( $expected_output['username'], $user->user_login ); … … 2103 2105 } 2104 2106 2105 // Update the user 2107 // Update the user. 2106 2108 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); 2107 2109 foreach ( $input as $name => $value ) { … … 2114 2116 $actual_output = $response->get_data(); 2115 2117 2116 // Compare expected API output to actual API output 2118 // Compare expected API output to actual API output. 2117 2119 if ( isset( $expected_output['username'] ) ) { 2118 2120 $this->assertEquals( $expected_output['username'], $actual_output['username'] ); … … 2125 2127 $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] ); 2126 2128 2127 // Compare expected API output to WP internal values 2129 // Compare expected API output to WP internal values. 2128 2130 $user = get_userdata( $actual_output['id'] ); 2129 2131 if ( isset( $expected_output['username'] ) ) { … … 2388 2390 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 2389 2391 2390 // Ensure the user still exists 2392 // Ensure the user still exists. 2391 2393 $user = get_user_by( 'id', $user_id ); 2392 2394 $this->assertNotEmpty( $user ); … … 2460 2462 $this->assertEquals( 200, $response->get_status() ); 2461 2463 2462 // Check that the post has been updated correctly 2464 // Check that the post has been updated correctly. 2463 2465 $post = get_post( $test_post ); 2464 2466 $this->assertEquals( $reassign_id, $post->post_author );
Note: See TracChangeset
for help on using the changeset viewer.