Changeset 59970
- Timestamp:
- 03/11/2025 02:17:41 PM (12 days ago)
- Location:
- trunk
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
r59899 r59970 308 308 if ( $request->is_method( 'HEAD' ) ) { 309 309 // Return early as this handler doesn't add any response headers. 310 return new WP_REST_Response( );310 return new WP_REST_Response( array() ); 311 311 } 312 312 $response = array(); … … 456 456 if ( $request->is_method( 'HEAD' ) ) { 457 457 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php */ 458 return apply_filters( 'rest_prepare_autosave', new WP_REST_Response( ), $post, $request );458 return apply_filters( 'rest_prepare_autosave', new WP_REST_Response( array() ), $post, $request ); 459 459 } 460 460 $response = $this->revisions_controller->prepare_item_for_response( $post, $request ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php
r59899 r59970 84 84 if ( $request->is_method( 'HEAD' ) ) { 85 85 // Return early as this handler doesn't add any response headers. 86 return new WP_REST_Response( );86 return new WP_REST_Response( array() ); 87 87 } 88 88 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
r59899 r59970 134 134 if ( $request->is_method( 'HEAD' ) ) { 135 135 // Return early as this handler doesn't add any response headers. 136 return new WP_REST_Response( );136 return new WP_REST_Response( array() ); 137 137 } 138 138 … … 259 259 if ( $request->is_method( 'HEAD' ) ) { 260 260 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php */ 261 return apply_filters( 'rest_prepare_block_type', new WP_REST_Response( ), $block_type, $request );261 return apply_filters( 'rest_prepare_block_type', new WP_REST_Response( array() ), $block_type, $request ); 262 262 } 263 263 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r59899 r59970 314 314 } 315 315 316 $response = $is_head_request ? new WP_REST_Response( ) : rest_ensure_response( $comments );316 $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $comments ); 317 317 $response->header( 'X-WP-Total', $total_comments ); 318 318 $response->header( 'X-WP-TotalPages', $max_pages ); … … 1055 1055 if ( $request->is_method( 'HEAD' ) ) { 1056 1056 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */ 1057 return apply_filters( 'rest_prepare_comment', new WP_REST_Response( ), $comment, $request );1057 return apply_filters( 'rest_prepare_comment', new WP_REST_Response( array() ), $comment, $request ); 1058 1058 } 1059 1059 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php
r59899 r59970 114 114 } 115 115 116 $response = $is_head_request ? new WP_REST_Response( ) : rest_ensure_response( $items );116 $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $items ); 117 117 118 118 $response->header( 'X-WP-Total', (int) $total_items ); … … 194 194 if ( $request->is_method( 'HEAD' ) ) { 195 195 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php */ 196 return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response( ), $item, $request );196 return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response( array() ), $item, $request ); 197 197 } 198 198 … … 210 210 if ( $request->is_method( 'HEAD' ) ) { 211 211 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php */ 212 return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response( ), $item, $request );212 return apply_filters( 'rest_prepare_font_collection', new WP_REST_Response( array() ), $item, $request ); 213 213 } 214 214 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
r59899 r59970 249 249 $response = rest_ensure_response( $response ); 250 250 } else { 251 $response = new WP_REST_Response( );251 $response = new WP_REST_Response( array() ); 252 252 } 253 253 … … 292 292 // Don't prepare the response body for HEAD requests. 293 293 if ( $request->is_method( 'HEAD' ) ) { 294 return new WP_REST_Response( );294 return new WP_REST_Response( array() ); 295 295 } 296 296 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
r59899 r59970 164 164 if ( $request->is_method( 'HEAD' ) ) { 165 165 // Return early as this handler doesn't add any response headers. 166 return new WP_REST_Response( );166 return new WP_REST_Response( array() ); 167 167 } 168 168 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
r59899 r59970 112 112 if ( $request->is_method( 'HEAD' ) ) { 113 113 // Return early as this handler doesn't add any response headers. 114 return new WP_REST_Response( );114 return new WP_REST_Response( array() ); 115 115 } 116 116 … … 187 187 if ( $request->is_method( 'HEAD' ) ) { 188 188 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php */ 189 return apply_filters( 'rest_prepare_post_type', new WP_REST_Response( ), $post_type, $request );189 return apply_filters( 'rest_prepare_post_type', new WP_REST_Response( array() ), $post_type, $request ); 190 190 } 191 191 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r59899 r59970 500 500 } 501 501 502 $response = $is_head_request ? new WP_REST_Response( ) : rest_ensure_response( $posts );502 $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $posts ); 503 503 504 504 $response->header( 'X-WP-Total', (int) $total_posts ); … … 1848 1848 if ( $request->is_method( 'HEAD' ) ) { 1849 1849 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ 1850 return apply_filters( "rest_prepare_{$this->post_type}", new WP_REST_Response( ), $post, $request );1850 return apply_filters( "rest_prepare_{$this->post_type}", new WP_REST_Response( array() ), $post, $request ); 1851 1851 } 1852 1852 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r59899 r59970 356 356 $response = rest_ensure_response( $response ); 357 357 } else { 358 $response = new WP_REST_Response( );358 $response = new WP_REST_Response( array() ); 359 359 } 360 360 … … 592 592 if ( $request->is_method( 'HEAD' ) ) { 593 593 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php */ 594 return apply_filters( 'rest_prepare_revision', new WP_REST_Response( ), $post, $request );594 return apply_filters( 'rest_prepare_revision', new WP_REST_Response( array() ), $post, $request ); 595 595 } 596 596 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php
r59899 r59970 166 166 } 167 167 168 $response = $is_head_request ? new WP_REST_Response( ) : rest_ensure_response( $results );168 $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $results ); 169 169 $response->header( 'X-WP-Total', $total ); 170 170 $response->header( 'X-WP-TotalPages', $max_pages ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
r59899 r59970 122 122 if ( $request->is_method( 'HEAD' ) ) { 123 123 // Return early as this handler doesn't add any response headers. 124 return new WP_REST_Response( );124 return new WP_REST_Response( array() ); 125 125 } 126 126 … … 330 330 if ( $request->is_method( 'HEAD' ) ) { 331 331 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php */ 332 return apply_filters( 'rest_prepare_sidebar', new WP_REST_Response( ), $raw_sidebar, $request );332 return apply_filters( 'rest_prepare_sidebar', new WP_REST_Response( array() ), $raw_sidebar, $request ); 333 333 } 334 334 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
r59899 r59970 116 116 if ( $request->is_method( 'HEAD' ) ) { 117 117 // Return early as this handler doesn't add any response headers. 118 return new WP_REST_Response( );118 return new WP_REST_Response( array() ); 119 119 } 120 120 … … 218 218 if ( $request->is_method( 'HEAD' ) ) { 219 219 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php */ 220 return apply_filters( 'rest_prepare_taxonomy', new WP_REST_Response( ), $taxonomy, $request );220 return apply_filters( 'rest_prepare_taxonomy', new WP_REST_Response( array() ), $taxonomy, $request ); 221 221 } 222 222 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r59899 r59970 272 272 if ( $request->is_method( 'HEAD' ) ) { 273 273 // Return early as this handler doesn't add any response headers. 274 return new WP_REST_Response( );274 return new WP_REST_Response( array() ); 275 275 } 276 276 … … 676 676 // Don't prepare the response body for HEAD requests. 677 677 if ( $request->is_method( 'HEAD' ) ) { 678 return new WP_REST_Response( );678 return new WP_REST_Response( array() ); 679 679 } 680 680 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r59899 r59970 371 371 } 372 372 373 $response = $is_head_request ? new WP_REST_Response( ) : rest_ensure_response( $response );373 $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $response ); 374 374 375 375 // Store pagination values for headers. … … 900 900 if ( $request->is_method( 'HEAD' ) ) { 901 901 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ 902 return apply_filters( "rest_prepare_{$this->taxonomy}", new WP_REST_Response( ), $item, $request );902 return apply_filters( "rest_prepare_{$this->taxonomy}", new WP_REST_Response( array() ), $item, $request ); 903 903 } 904 904 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r59899 r59970 385 385 } 386 386 387 $response = $is_head_request ? new WP_REST_Response( ) : rest_ensure_response( $users );387 $response = $is_head_request ? new WP_REST_Response( array() ) : rest_ensure_response( $users ); 388 388 389 389 // Store pagination values for headers then unset for count query. … … 1033 1033 if ( $request->is_method( 'HEAD' ) ) { 1034 1034 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php */ 1035 return apply_filters( 'rest_prepare_user', new WP_REST_Response( ), $user, $request );1035 return apply_filters( 'rest_prepare_user', new WP_REST_Response( array() ), $user, $request ); 1036 1036 } 1037 1037 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
r59899 r59970 148 148 if ( $request->is_method( 'HEAD' ) ) { 149 149 // Return early as this handler doesn't add any response headers. 150 return new WP_REST_Response( );150 return new WP_REST_Response( array() ); 151 151 } 152 152 … … 307 307 if ( $request->is_method( 'HEAD' ) ) { 308 308 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php */ 309 return apply_filters( 'rest_prepare_widget_type', new WP_REST_Response( ), $widget_type, $request );309 return apply_filters( 'rest_prepare_widget_type', new WP_REST_Response( array() ), $widget_type, $request ); 310 310 } 311 311 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
r59899 r59970 139 139 if ( $request->is_method( 'HEAD' ) ) { 140 140 // Return early as this handler doesn't add any response headers. 141 return new WP_REST_Response( );141 return new WP_REST_Response( array() ); 142 142 } 143 143 … … 687 687 if ( $request->is_method( 'HEAD' ) ) { 688 688 /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php */ 689 return apply_filters( 'rest_prepare_widget', new WP_REST_Response( ), $widget, $request );689 return apply_filters( 'rest_prepare_widget', new WP_REST_Response( array() ), $widget, $request ); 690 690 } 691 691 -
trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php
r59899 r59970 109 109 } 110 110 111 $this->assert Null($content, 'The response should be empty.' );111 $this->assertSame( array(), $content, 'The response should be empty.' ); 112 112 $headers = $response->get_headers(); 113 113 $this->assertArrayHasKey( 'X-WP-Total', $headers, 'The "X-WP-Total" header should be present in the response.' ); … … 173 173 return null; 174 174 } 175 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );175 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 176 176 } 177 177 -
trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php
r59899 r59970 197 197 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 198 198 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 199 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );199 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 200 200 } 201 201 … … 315 315 return null; 316 316 } 317 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );317 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 318 318 } 319 319 … … 890 890 $this->assertSame( $autosave['id'], $data['id'], 'Original autosave was not returned' ); 891 891 } 892 893 /** 894 * @dataProvider data_head_request_with_specified_fields_returns_success_response 895 * @ticket 56481 896 * 897 * @param string $path The path to test. 898 */ 899 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 900 wp_set_current_user( self::$editor_id ); 901 $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$post_id, self::$autosave_post_id ) ); 902 $request->set_param( '_fields', 'id' ); 903 $server = rest_get_server(); 904 $response = $server->dispatch( $request ); 905 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 906 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 907 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 908 909 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 910 } 911 912 /** 913 * Data provider intended to provide paths for testing HEAD requests. 914 * 915 * @return array 916 */ 917 public static function data_head_request_with_specified_fields_returns_success_response() { 918 return array( 919 'get_item request' => array( '/wp/v2/posts/%d/autosaves/%d' ), 920 'get_items request' => array( '/wp/v2/posts/%d' ), 921 ); 922 } 892 923 } -
trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php
r59899 r59970 637 637 return null; 638 638 } 639 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );639 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 640 640 } 641 641 … … 660 660 $response = rest_get_server()->dispatch( $request ); 661 661 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 662 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 662 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 663 } 664 665 /** 666 * @dataProvider data_head_request_with_specified_fields_returns_success_response 667 * @ticket 56481 668 * 669 * @param string $path The path to test. 670 */ 671 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 672 wp_set_current_user( self::$admin_id ); 673 $request = new WP_REST_Request( 'HEAD', $path ); 674 $request->set_param( '_fields', 'title' ); 675 $server = rest_get_server(); 676 $response = $server->dispatch( $request ); 677 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 678 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 679 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 680 681 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 682 } 683 684 /** 685 * Data provider intended to provide paths for testing HEAD requests. 686 * 687 * @return array 688 */ 689 public static function data_head_request_with_specified_fields_returns_success_response() { 690 return array( 691 'get_item request' => array( '/wp/v2/block-types/fake/test' ), 692 'get_items request' => array( '/wp/v2/block-types' ), 693 ); 663 694 } 664 695 -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r59899 r59970 1361 1361 return null; 1362 1362 } 1363 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 1363 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 1364 } 1365 1366 /** 1367 * @dataProvider data_head_request_with_specified_fields_returns_success_response 1368 * @ticket 56481 1369 * 1370 * @param string $path The path to test. 1371 */ 1372 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 1373 $request = new WP_REST_Request( 'HEAD', $path ); 1374 $request->set_param( '_fields', 'id' ); 1375 $server = rest_get_server(); 1376 $response = $server->dispatch( $request ); 1377 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 1378 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 1379 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 1380 1381 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 1382 } 1383 1384 /** 1385 * Data provider intended to provide paths for testing HEAD requests. 1386 * 1387 * @return array 1388 */ 1389 public static function data_head_request_with_specified_fields_returns_success_response() { 1390 return array( 1391 'get_item request' => array( '/wp/v2/categories/1' ), 1392 'get_items request' => array( '/wp/v2/categories' ), 1393 ); 1364 1394 } 1365 1395 } -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r59899 r59970 3568 3568 return null; 3569 3569 } 3570 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 3570 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 3571 } 3572 3573 /** 3574 * @dataProvider data_head_request_with_specified_fields_returns_success_response 3575 * @ticket 56481 3576 * 3577 * @param string $path The path to test. 3578 */ 3579 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 3580 $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$approved_id ) ); 3581 $request->set_param( '_fields', 'id' ); 3582 $server = rest_get_server(); 3583 $response = $server->dispatch( $request ); 3584 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 3585 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 3586 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 3587 3588 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 3589 } 3590 3591 /** 3592 * Data provider intended to provide paths for testing HEAD requests. 3593 * 3594 * @return array 3595 */ 3596 public static function data_head_request_with_specified_fields_returns_success_response() { 3597 return array( 3598 'get_item request' => array( '/wp/v2/comments/%d' ), 3599 'get_items request' => array( '/wp/v2/comments' ), 3600 ); 3571 3601 } 3572 3602 } -
trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php
r59899 r59970 337 337 $response = rest_get_server()->dispatch( $request ); 338 338 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 339 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 339 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 340 } 341 342 /** 343 * @dataProvider data_head_request_with_specified_fields_returns_success_response 344 * @ticket 56481 345 * 346 * @param string $path The path to test. 347 */ 348 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 349 wp_set_current_user( self::$admin_id ); 350 $request = new WP_REST_Request( 'GET', sprintf( $path, self::$global_styles_id, $this->revision_1_id ) ); 351 $request->set_param( '_fields', 'id' ); 352 $server = rest_get_server(); 353 $response = $server->dispatch( $request ); 354 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 355 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 356 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 357 358 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 359 } 360 361 /** 362 * Data provider intended to provide paths for testing HEAD requests. 363 * 364 * @return array 365 */ 366 public static function data_head_request_with_specified_fields_returns_success_response() { 367 return array( 368 'get_item request' => array( '/wp/v2/global-styles/%d/revisions/%d' ), 369 'get_items request' => array( '/wp/v2/global-styles/%d/revisions' ), 370 ); 340 371 } 341 372 … … 367 398 $response = rest_get_server()->dispatch( $request ); 368 399 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 369 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );400 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 370 401 } 371 402 -
trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
r59899 r59970 168 168 169 169 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 170 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 170 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 171 } 172 173 /** 174 * @ticket 56481 175 */ 176 public function test_get_items_head_request_with_specified_fields_returns_success_response() { 177 wp_set_current_user( self::$contributor_id ); 178 self::mock_successful_response( 'browse-all', true ); 179 $request = new WP_REST_Request( 'HEAD', '/wp/v2/pattern-directory/patterns' ); 180 $request->set_param( '_fields', 'id' ); 181 $server = rest_get_server(); 182 $response = $server->dispatch( $request ); 183 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 184 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 185 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 186 187 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 171 188 } 172 189 -
trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php
r59899 r59970 112 112 return null; 113 113 } 114 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 114 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 115 } 116 117 /** 118 * @dataProvider data_head_request_with_specified_fields_returns_success_response 119 * @ticket 56481 120 * 121 * @param string $path The path to test. 122 */ 123 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 124 $request = new WP_REST_Request( 'HEAD', $path ); 125 $request->set_param( '_fields', 'slug' ); 126 $server = rest_get_server(); 127 $response = $server->dispatch( $request ); 128 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 129 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 130 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 131 132 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 133 } 134 135 /** 136 * Data provider intended to provide paths for testing HEAD requests. 137 * 138 * @return array 139 */ 140 public static function data_head_request_with_specified_fields_returns_success_response() { 141 return array( 142 'get_item request' => array( '/wp/v2/types/post' ), 143 'get_items request' => array( '/wp/v2/types' ), 144 ); 115 145 } 116 146 … … 325 355 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 326 356 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 327 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );357 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 328 358 } 329 359 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r59899 r59970 296 296 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 297 297 $this->assertArrayHasKey( 'Link', $headers, 'The "Link" header should be present in the response.' ); 298 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );298 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 299 299 } 300 300 … … 321 321 322 322 if ( $request->is_method( 'HEAD' ) ) { 323 $this->assert Null($response->get_data(), 'Failed asserting that response data is null for HEAD request.' );323 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' ); 324 324 } else { 325 325 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is an empty array for GET request.' ); … … 352 352 353 353 } else { 354 $this->assert Null($response->get_data(), 'Failed asserting that response data is null for HEAD request.' );354 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' ); 355 355 $headers = $response->get_headers(); 356 356 $this->assertSame( $total_posts, $headers['X-WP-Total'] ); … … 367 367 $this->assertSameSets( array( self::$editor_id, self::$author_id ), wp_list_pluck( $data, 'author' ) ); 368 368 } else { 369 $this->assert Null($data, 'Failed asserting that response data is null for HEAD request.' );369 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' ); 370 370 $headers = $response->get_headers(); 371 371 $this->assertSame( 2, $headers['X-WP-Total'], 'Failed asserting that X-WP-Total header is 2.' ); … … 382 382 $this->assertSame( self::$editor_id, $data[0]['author'] ); 383 383 } else { 384 $this->assert Null($data, 'Failed asserting that response data is null for HEAD request.' );384 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' ); 385 385 $headers = $response->get_headers(); 386 386 $this->assertSame( 1, $headers['X-WP-Total'], 'Failed asserting that X-WP-Total header is 1.' ); … … 408 408 $this->assertCount( $total_posts, $response->get_data() ); 409 409 } else { 410 $this->assert Null($response->get_data(), 'Failed asserting that response data is null for HEAD request.' );410 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' ); 411 411 $headers = $response->get_headers(); 412 412 $this->assertSame( $total_posts, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' ); … … 425 425 $this->assertNotEquals( self::$author_id, $data[0]['author'] ); 426 426 } else { 427 $this->assert Null($response->get_data(), 'Failed asserting that response data is null for HEAD request.' );427 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' ); 428 428 $headers = $response->get_headers(); 429 429 $this->assertSame( $total_posts - 2, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' ); … … 442 442 $this->assertNotEquals( self::$editor_id, $data[1]['author'] ); 443 443 } else { 444 $this->assert Null($response->get_data(), 'Failed asserting that response data is null for HEAD request.' );444 $this->assertSame( array(), $response->get_data(), 'Failed asserting that response data is null for HEAD request.' ); 445 445 $headers = $response->get_headers(); 446 446 $this->assertSame( $total_posts - 1, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' ); … … 484 484 $this->assertSame( $id2, $data[0]['id'] ); 485 485 } else { 486 $this->assert Null($data, 'Failed asserting that response data is null for HEAD request.' );486 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' ); 487 487 $headers = $response->get_headers(); 488 488 $this->assertSame( 2, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' ); … … 499 499 $this->assertSame( $id1, $data[0]['id'] ); 500 500 } else { 501 $this->assert Null($data, 'Failed asserting that response data is null for HEAD request.' );501 $this->assertSame( array(), $data, 'Failed asserting that response data is null for HEAD request.' ); 502 502 $headers = $response->get_headers(); 503 503 $this->assertSame( 2, $headers['X-WP-Total'], 'Failed asserting that the number of posts is correct.' ); … … 2194 2194 return null; 2195 2195 } 2196 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 2196 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 2197 } 2198 2199 /** 2200 * @dataProvider data_head_request_with_specified_fields_returns_success_response 2201 * @ticket 56481 2202 * 2203 * @param string $path The path to test. 2204 */ 2205 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 2206 $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$post_id ) ); 2207 $request->set_param( '_fields', 'id' ); 2208 $server = rest_get_server(); 2209 $response = $server->dispatch( $request ); 2210 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 2211 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 2212 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 2213 2214 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 2215 } 2216 2217 /** 2218 * Data provider intended to provide paths for testing HEAD requests. 2219 * 2220 * @return array 2221 */ 2222 public static function data_head_request_with_specified_fields_returns_success_response() { 2223 return array( 2224 'get_item request' => array( '/wp/v2/posts/%d' ), 2225 'get_items request' => array( '/wp/v2/posts' ), 2226 ); 2197 2227 } 2198 2228 -
trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php
r59899 r59970 183 183 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 184 184 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 185 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );185 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 186 186 } 187 187 … … 301 301 return null; 302 302 } 303 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 303 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 304 } 305 306 /** 307 * @dataProvider data_head_request_with_specified_fields_returns_success_response 308 * @ticket 56481 309 * 310 * @param string $path The path to test. 311 */ 312 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 313 wp_set_current_user( self::$editor_id ); 314 $request = new WP_REST_Request( 'HEAD', sprintf( $path, self::$post_id, $this->revision_id1 ) ); 315 $request->set_param( '_fields', 'id' ); 316 $server = rest_get_server(); 317 $response = $server->dispatch( $request ); 318 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 319 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 320 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 321 322 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 323 } 324 325 /** 326 * Data provider intended to provide paths for testing HEAD requests. 327 * 328 * @return array 329 */ 330 public static function data_head_request_with_specified_fields_returns_success_response() { 331 return array( 332 333 'get_item request' => array( '/wp/v2/posts/%d/revisions/%d' ), 334 'get_items request' => array( '/wp/v2/posts/%d/revisions' ), 335 ); 304 336 } 305 337 -
trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php
r59899 r59970 172 172 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 173 173 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 174 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );174 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 175 175 } 176 176 … … 568 568 return null; 569 569 } 570 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 570 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 571 } 572 573 /** 574 * @dataProvider data_head_request_with_specified_fields_returns_success_response 575 * @ticket 56481 576 * 577 * @param string $path The path to test. 578 */ 579 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 580 $this->setup_sidebar( 581 'sidebar-1', 582 array( 583 'name' => 'Test sidebar', 584 ) 585 ); 586 587 $request = new WP_REST_Request( 'HEAD', $path ); 588 // This endpoint doesn't seem to support _fields param, but we need to set it to reproduce the fatal error. 589 $request->set_param( '_fields', 'name' ); 590 $server = rest_get_server(); 591 $response = $server->dispatch( $request ); 592 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 593 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 594 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 595 596 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 597 } 598 599 /** 600 * Data provider intended to provide paths for testing HEAD requests. 601 * 602 * @return array 603 */ 604 public static function data_head_request_with_specified_fields_returns_success_response() { 605 return array( 606 607 'get_item request' => array( '/wp/v2/sidebars/sidebar-1' ), 608 'get_items request' => array( '/wp/v2/sidebars' ), 609 ); 571 610 } 572 611 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r59899 r59970 1615 1615 return null; 1616 1616 } 1617 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 1617 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 1618 } 1619 1620 /** 1621 * @dataProvider data_head_request_with_specified_fields_returns_success_response 1622 * @ticket 56481 1623 * 1624 * @param string $path The path to test. 1625 */ 1626 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 1627 $tag_id = self::factory()->tag->create(); 1628 $request = new WP_REST_Request( 'HEAD', sprintf( $path, $tag_id ) ); 1629 $request->set_param( '_fields', 'id' ); 1630 $server = rest_get_server(); 1631 $response = $server->dispatch( $request ); 1632 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 1633 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 1634 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 1635 1636 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 1637 } 1638 1639 /** 1640 * Data provider intended to provide paths for testing HEAD requests. 1641 * 1642 * @return array 1643 */ 1644 public static function data_head_request_with_specified_fields_returns_success_response() { 1645 return array( 1646 'get_item request' => array( '/wp/v2/tags/%d' ), 1647 'get_items request' => array( '/wp/v2/tags' ), 1648 ); 1618 1649 } 1619 1650 } -
trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
r59899 r59970 74 74 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 75 75 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 76 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );76 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 77 77 } 78 78 … … 186 186 return null; 187 187 } 188 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 188 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 189 } 190 191 /** 192 * @dataProvider data_head_request_with_specified_fields_returns_success_response 193 * @ticket 56481 194 * 195 * @param string $path The path to test. 196 */ 197 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 198 $request = new WP_REST_Request( 'HEAD', $path ); 199 $request->set_param( '_fields', 'name' ); 200 $server = rest_get_server(); 201 $response = $server->dispatch( $request ); 202 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 203 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 204 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 205 206 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 207 } 208 209 /** 210 * Data provider intended to provide paths for testing HEAD requests. 211 * 212 * @return array 213 */ 214 public static function data_head_request_with_specified_fields_returns_success_response() { 215 return array( 216 'get_item request' => array( '/wp/v2/taxonomies/category' ), 217 'get_items request' => array( '/wp/v2/taxonomies' ), 218 ); 189 219 } 190 220 -
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 -
trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php
r59899 r59970 130 130 $response = rest_get_server()->dispatch( $request ); 131 131 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 132 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );132 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 133 133 } 134 134 … … 228 228 return null; 229 229 } 230 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );230 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 231 231 } 232 232 … … 240 240 'GET request' => array( 'GET' ), 241 241 'HEAD request' => array( 'HEAD' ), 242 ); 243 } 244 245 /** 246 * @dataProvider data_head_request_with_specified_fields_returns_success_response 247 * @ticket 56481 248 * 249 * @param string $path The path to test. 250 */ 251 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 252 wp_set_current_user( self::$admin_id ); 253 $request = new WP_REST_Request( 'HEAD', $path ); 254 $request->set_param( '_fields', 'id' ); 255 $server = rest_get_server(); 256 $response = $server->dispatch( $request ); 257 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 258 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 259 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 260 261 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 262 } 263 264 /** 265 * Data provider intended to provide paths for testing HEAD requests. 266 * 267 * @return array 268 */ 269 public static function data_head_request_with_specified_fields_returns_success_response() { 270 return array( 271 'get_item request' => array( '/wp/v2/widget-types/calendar' ), 272 'get_items request' => array( '/wp/v2/widget-types' ), 242 273 ); 243 274 } -
trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php
r59899 r59970 473 473 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 474 474 $this->assertSame( 0, $filter->get_call_count(), 'The "' . $hook_name . '" filter was called when it should not be for HEAD requests.' ); 475 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );475 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 476 476 } 477 477 … … 645 645 return null; 646 646 } 647 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 647 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 648 } 649 650 /** 651 * @dataProvider data_head_request_with_specified_fields_returns_success_response 652 * @ticket 56481 653 * 654 * @param string $path The path to test. 655 */ 656 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 657 add_filter( 'pre_http_request', array( $this, 'mocked_rss_response' ) ); 658 global $wp_widget_factory; 659 660 $wp_widget_factory->widgets['WP_Widget_RSS']->widget_options['show_instance_in_rest'] = false; 661 662 $block_content = '<!-- wp:paragraph --><p>Block test</p><!-- /wp:paragraph -->'; 663 664 $this->setup_widget( 665 'rss', 666 1, 667 array( 668 'title' => 'RSS test', 669 'url' => 'https://wordpress.org/news/feed', 670 ) 671 ); 672 $this->setup_widget( 673 'block', 674 1, 675 array( 676 'content' => $block_content, 677 ) 678 ); 679 $this->setup_sidebar( 680 'sidebar-1', 681 array( 682 'name' => 'Test sidebar', 683 ), 684 array( 'block-1', 'rss-1', 'testwidget' ) 685 ); 686 687 $request = new WP_REST_Request( 'HEAD', $path ); 688 $request->set_param( '_fields', 'id' ); 689 $server = rest_get_server(); 690 $response = $server->dispatch( $request ); 691 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 692 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 693 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 694 remove_filter( 'pre_http_request', array( $this, 'mocked_rss_response' ) ); 695 696 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 697 } 698 699 /** 700 * Data provider intended to provide paths for testing HEAD requests. 701 * 702 * @return array 703 */ 704 public static function data_head_request_with_specified_fields_returns_success_response() { 705 return array( 706 'get_item request' => array( '/wp/v2/widgets/block-1' ), 707 'get_items request' => array( '/wp/v2/widgets' ), 708 ); 648 709 } 649 710 -
trunk/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php
r59899 r59970 132 132 $response = rest_get_server()->dispatch( $request ); 133 133 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 134 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 134 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 135 } 136 137 /** 138 * @ticket 56481 139 * 140 * @param string $path The path to test. 141 */ 142 public function test_head_request_with_specified_fields_returns_success_response() { 143 wp_set_current_user( self::$admin_id ); 144 $request = new WP_REST_Request( 'HEAD', static::REQUEST_ROUTE ); 145 $request->set_param( '_fields', 'name' ); 146 $server = rest_get_server(); 147 $response = $server->dispatch( $request ); 148 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 149 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 150 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 151 152 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 135 153 } 136 154 -
trunk/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php
r59899 r59970 317 317 $response = rest_get_server()->dispatch( $request ); 318 318 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 319 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );319 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 320 320 } 321 321 … … 471 471 $response = rest_get_server()->dispatch( $request ); 472 472 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 473 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );473 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 474 474 } 475 475 … … 484 484 'template parts' => array( 'template_part_post', 'template-parts', self::TEST_THEME . '//' . self::TEMPLATE_PART_NAME ), 485 485 ); 486 } 487 488 /** 489 * @dataProvider data_get_item_with_data_provider 490 * @covers WP_REST_Template_Autosaves_Controller::get_item 491 * @ticket 56922 492 * 493 * @param string $parent_post_property_name A class property name that contains the parent post object. 494 * @param string $rest_base Base part of the REST API endpoint to test. 495 * @param string $template_id Template ID to use in the test. 496 */ 497 public function test_get_item_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) { 498 wp_set_current_user( self::$admin_id ); 499 500 $parent_post = self::$$parent_post_property_name; 501 502 $autosave_post_id = wp_create_post_autosave( 503 array( 504 'post_content' => 'Autosave content.', 505 'post_ID' => $parent_post->ID, 506 'post_type' => $parent_post->post_type, 507 ) 508 ); 509 510 $request = new WP_REST_Request( 511 'HEAD', 512 '/wp/v2/' . $rest_base . '/' . $template_id . '/autosaves/' . $autosave_post_id 513 ); 514 $request->set_param( '_fields', 'id' ); 515 $server = rest_get_server(); 516 $response = $server->dispatch( $request ); 517 518 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 519 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 520 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 521 522 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 523 } 524 525 /** 526 * @dataProvider data_get_items_with_data_provider 527 * @covers WP_REST_Template_Autosaves_Controller::get_items 528 * @ticket 56922 529 * 530 * @param string $parent_post_property_name A class property name that contains the parent post object. 531 * @param string $rest_base Base part of the REST API endpoint to test. 532 * @param string $template_id Template ID to use in the test. 533 */ 534 public function test_get_items_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) { 535 wp_set_current_user( self::$admin_id ); 536 // Cannot access this property in the data provider because it is not initialized at the time of execution. 537 $parent_post = self::$$parent_post_property_name; 538 wp_create_post_autosave( 539 array( 540 'post_content' => 'Autosave content.', 541 'post_ID' => $parent_post->ID, 542 'post_type' => $parent_post->post_type, 543 ) 544 ); 545 546 $request = new WP_REST_Request( 547 'HEAD', 548 '/wp/v2/' . $rest_base . '/' . $template_id . '/autosaves' 549 ); 550 $request->set_param( '_fields', 'id' ); 551 $server = rest_get_server(); 552 $response = $server->dispatch( $request ); 553 554 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 555 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 556 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 557 558 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 486 559 } 487 560 -
trunk/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php
r59899 r59970 438 438 $response = rest_get_server()->dispatch( $request ); 439 439 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 440 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );440 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 441 441 } 442 442 … … 628 628 $response = rest_get_server()->dispatch( $request ); 629 629 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 630 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );630 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 631 631 } 632 632 … … 641 641 'template parts' => array( 'template_part_post', 'template-parts', self::TEST_THEME . '//' . self::TEMPLATE_PART_NAME ), 642 642 ); 643 } 644 645 /** 646 * @dataProvider data_get_item_with_data_provider 647 * @covers WP_REST_Template_Revisions_Controller::get_item 648 * @ticket 56922 649 * 650 * @param string $parent_post_property_name A class property name that contains the parent post object. 651 * @param string $rest_base Base part of the REST API endpoint to test. 652 * @param string $template_id Template ID to use in the test. 653 */ 654 public function test_get_item_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) { 655 wp_set_current_user( self::$admin_id ); 656 657 $parent_post = self::$$parent_post_property_name; 658 659 $revisions = wp_get_post_revisions( $parent_post, array( 'fields' => 'ids' ) ); 660 $revision_id = array_shift( $revisions ); 661 662 $request = new WP_REST_Request( 663 'HEAD', 664 '/wp/v2/' . $rest_base . '/' . $template_id . '/revisions/' . $revision_id 665 ); 666 $request->set_param( '_fields', 'id' ); 667 $server = rest_get_server(); 668 $response = $server->dispatch( $request ); 669 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 670 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 671 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 672 673 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 674 } 675 676 /** 677 * @dataProvider data_get_items_with_data_provider 678 * @covers WP_REST_Template_Revisions_Controller::get_items 679 * @ticket 56922 680 * 681 * @param string $parent_post_property_name A class property name that contains the parent post object. 682 * @param string $rest_base Base part of the REST API endpoint to test. 683 * @param string $template_id Template ID to use in the test. 684 */ 685 public function test_get_items_head_request_with_specified_fields_returns_success_response( $parent_post_property_name, $rest_base, $template_id ) { 686 wp_set_current_user( self::$admin_id ); 687 $parent_post = self::$$parent_post_property_name; 688 689 $request = new WP_REST_Request( 690 'HEAD', 691 '/wp/v2/' . $rest_base . '/' . $template_id . '/revisions' 692 ); 693 694 $request->set_param( '_fields', 'id' ); 695 $server = rest_get_server(); 696 $response = $server->dispatch( $request ); 697 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 698 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 699 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 700 701 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 643 702 } 644 703 -
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r59899 r59970 186 186 $response = rest_get_server()->dispatch( $request ); 187 187 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 188 $this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 188 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 189 } 190 191 /** 192 * @dataProvider data_head_request_with_specified_fields_returns_success_response 193 * @ticket 56481 194 * 195 * @param string $path The path to test. 196 */ 197 public function test_head_request_with_specified_fields_returns_success_response( $path ) { 198 wp_set_current_user( self::$admin_id ); 199 $request = new WP_REST_Request( 'HEAD', $path ); 200 $request->set_param( '_fields', 'id' ); 201 $server = rest_get_server(); 202 $response = $server->dispatch( $request ); 203 add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); 204 $response = apply_filters( 'rest_post_dispatch', $response, $server, $request ); 205 remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); 206 207 $this->assertSame( 200, $response->get_status(), 'The response status should be 200.' ); 208 } 209 210 /** 211 * Data provider intended to provide paths for testing HEAD requests. 212 * 213 * @return array 214 */ 215 public static function data_head_request_with_specified_fields_returns_success_response() { 216 return array( 217 'get_item request' => array( '/wp/v2/templates/default//my_template' ), 218 'get_items request' => array( '/wp/v2/templates' ), 219 ); 189 220 } 190 221 … … 292 323 $response = rest_get_server()->dispatch( $request ); 293 324 $this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); 294 $this->assert Null($response->get_data(), 'The server should not generate a body in response to a HEAD request.' );325 $this->assertSame( array(), $response->get_data(), 'The server should not generate a body in response to a HEAD request.' ); 295 326 } 296 327
Note: See TracChangeset
for help on using the changeset viewer.