Changeset 54982 for branches/5.3
- Timestamp:
- 12/15/2022 04:32:08 AM (2 years ago)
- Location:
- branches/5.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.3
-
branches/5.3/tests/phpunit/tests/http/base.php
r50092 r54982 395 395 396 396 /** 397 * Test HTTP Redirects with multiple Location headers specified398 *399 * @ticket 16890400 */401 function test_multiple_location_headers() {402 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1';403 $res = wp_remote_head( $url, array( 'timeout' => 30 ) );404 405 $this->skipTestOnTimeout( $res );406 $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );407 $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );408 409 $res = wp_remote_get( $url, array( 'timeout' => 30 ) );410 411 $this->skipTestOnTimeout( $res );412 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );413 414 }415 416 /**417 397 * Test HTTP Cookie handling 418 398 * -
branches/5.3/tests/phpunit/tests/http/http.php
r43571 r54982 373 373 } 374 374 375 /** 376 * Test HTTP Redirects with multiple Location headers specified. 377 * 378 * Ensure the WP_HTTP::handle_redirects() method handles multiple Location headers 379 * and the HTTP request it makes uses the last Location header. 380 * 381 * @ticket 16890 382 * @ticket 57306 383 * 384 * @covers WP_HTTP::handle_redirects 385 */ 386 public function test_multiple_location_headers() { 387 $pre_http_request_filter_has_run = false; 388 // Filter the response made by WP_HTTP::handle_redirects(). 389 add_filter( 390 'pre_http_request', 391 function( $response, $args, $url ) use ( &$pre_http_request_filter_has_run ) { 392 $pre_http_request_filter_has_run = true; 393 394 // Assert the redirect URL is correct. 395 $this->assertSame( 396 $url, 397 'http://example.com/?multiple-location-headers=1&redirected=two' 398 ); 399 400 if ( 'http://example.com/?multiple-location-headers=1&redirected=two' === $url ) { 401 $body = 'PASS'; 402 } else { 403 $body = 'FAIL'; 404 } 405 406 return array( 407 'headers' => array(), 408 'body' => $body, 409 'response' => array( 410 'code' => 200, 411 'message' => 'OK', 412 ), 413 'cookies' => array(), 414 'filename' => null, 415 ); 416 }, 417 10, 418 3 419 ); 420 421 $headers = array( 422 'server' => 'nginx', 423 'date' => 'Sun, 11 Dec 2022 23:11:22 GMT', 424 'content-type' => 'text/html; charset=utf-8', 425 'location' => array( 426 'http://example.com/?multiple-location-headers=1&redirected=one', 427 'http://example.com/?multiple-location-headers=1&redirected=two', 428 ), 429 ); 430 431 // Test the tests: ensure multiple locations are passed to WP_HTTP::handle_redirects(). 432 $this->assertIsArray( $headers['location'], 'Location header is expected to be an array.' ); 433 $this->assertCount( 2, $headers['location'], 'Location header is expected to contain two values.' ); 434 435 $args = array( 436 'timeout' => 30, 437 '_redirection' => 3, 438 'redirection' => 2, 439 'method' => 'GET', 440 ); 441 442 $redirect_response = WP_HTTP::handle_redirects( 443 'http://example.com/?multiple-location-headers=1', 444 $args, 445 array( 446 'headers' => $headers, 447 'body' => '', 448 'cookies' => array(), 449 'filename' => null, 450 'response' => array( 451 'code' => 302, 452 'message' => 'Found', 453 ), 454 ) 455 ); 456 $this->assertSame( 'PASS', wp_remote_retrieve_body( $redirect_response ), 'Redirect response body is expected to be PASS.' ); 457 $this->assertTrue( $pre_http_request_filter_has_run, 'The pre_http_request filter is expected to run.' ); 458 } 375 459 }
Note: See TracChangeset
for help on using the changeset viewer.