- Timestamp:
- 03/11/2025 02:17:41 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r59899 r59970 255 255 256 256 if ( 'HEAD' === $method ) { 257 $this->assert Null($response->get_data(), 'Expected null response data for HEAD request, but received non-null data.' );257 $this->assertSame( array(), $response->get_data(), 'Expected null response data for HEAD request, but received non-null data.' ); 258 258 return null; 259 259 } … … 3252 3252 return null; 3253 3253 } 3254 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );3254 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 3255 3255 } 3256 3256 … … 3273 3273 $this->assertSame( 200, $response->get_status() ); 3274 3274 if ( $is_head_request ) { 3275 $this->assert Null($response->get_data() );3275 $this->assertSame( array(), $response->get_data() ); 3276 3276 } else { 3277 3277 $this->assertNotEmpty( $response->get_data() ); … … 3305 3305 // Assert that the SQL query only fetches the id column. 3306 3306 $this->assertMatchesRegularExpression( $pattern, $query->request, 'The SQL query does not match the expected string.' ); 3307 } 3308 3309 /** 3310 * @dataProvider data_head_request_with_specified_fields_returns_success_response 3311 * @ticket 56481 3312 * 3313 * @param string $path The path to test. 3314 */ 3315 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 3316 $user_id = self::factory()->user->create(); 3317 wp_set_current_user( self::$user ); 3318 3319 $request = new WP_REST_Request( 'HEAD', sprintf( $path, $user_id ) ); 3320 $request->set_param( '_fields', 'id' ); 3321 $server = rest_get_server(); 3322 $response = $server->dispatch( $request ); 3323 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 3324 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 3325 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 3326 3327 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 3328 } 3329 3330 /** 3331 * Data provider intended to provide paths for testing HEAD requests. 3332 * 3333 * @return array 3334 */ 3335 public static function data_head_request_with_specified_fields_returns_success_response() { 3336 return array( 3337 'get_item request' => array( '/wp/v2/users/%d' ), 3338 'get_items request' => array( '/wp/v2/users' ), 3339 ); 3307 3340 } 3308 3341
Note: See TracChangeset
for help on using the changeset viewer.