- 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-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
Note: See TracChangeset
for help on using the changeset viewer.