Tests: Use skipTestOnTimeout() in more HTTP tests.

Adjust it to handle more types of timeouts, e.g. "Resolving timed out", "Connection timed out".

Merges [38757], [43511], [43512], [46682], [46996] to the 4.5 branch.
See #51669.

git-svn-id: https://develop.svn.wordpress.org/branches/4.5@50090 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-01-30 12:04:12 +00:00
parent 9fc560b07b
commit f8317b35a7
4 changed files with 279 additions and 197 deletions

View File

@ -160,11 +160,11 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
$_POST = array();
$this->flush_cache();
}
/**
* Allow tests to be skipped on some automated runs
*
* For test runs on Travis for something other than trunk/master
/**
* Allow tests to be skipped on some automated runs.
*
* For test runs on Travis for something other than trunk/master
* we want to skip tests that only need to run for master.
*/
public function skipOnAutomatedBranches() {
@ -215,10 +215,33 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
*/
protected function reset_post_statuses() {
foreach ( get_post_stati( array( '_builtin' => false ) ) as $post_status ) {
_unregister_post_status( $post_status );
}
}
_unregister_post_status( $post_status );
}
}
/**
* Allow tests to be skipped if the HTTP request times out.
*
* @param array|WP_Error $response HTTP response.
*/
public function skipTestOnTimeout( $response ) {
if ( ! is_wp_error( $response ) ) {
return;
}
if ( 'connect() timed out!' === $response->get_error_message() ) {
$this->markTestSkipped( 'HTTP timeout' );
}
if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
$this->markTestSkipped( 'HTTP timeout' );
}
if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
$this->markTestSkipped( 'HTTP timeout' );
}
}
/**
* Reset `$_SERVER` variables
*/

View File

@ -7,28 +7,39 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
function test_readme() {
// This test is designed to only run on trunk/master
$this->skipOnAutomatedBranches();
$readme = file_get_contents( ABSPATH . 'readme.html' );
preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches );
$response = wp_remote_get( 'https://secure.php.net/supported-versions.php' );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
$this->markTestSkipped( 'Could not contact PHP.net to check versions.' );
}
$php = wp_remote_retrieve_body( $response );
$readme = file_get_contents( ABSPATH . 'readme.html' );
preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches );
$response = wp_remote_get( 'https://secure.php.net/supported-versions.php' );
$this->skipTestOnTimeout( $response );
$response_code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $response_code ) {
$this->fail( sprintf( 'Could not contact PHP.net to check versions. Response code: %s', $response_code ) );
}
$php = wp_remote_retrieve_body( $response );
preg_match_all( '#<tr class="stable">\s*<td>\s*<a [^>]*>\s*([0-9.]*)#s', $php, $phpmatches );
$this->assertContains( $matches[1], $phpmatches[1], "readme.html's Recommended PHP version is too old. Remember to update the WordPress.org Requirements page, too." );
preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );
$response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
$this->markTestSkipped( 'Could not contact dev.MySQL.com to check versions.' );
}
$mysql = wp_remote_retrieve_body( $response );
$response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );
$this->skipTestOnTimeout( $response );
$response_code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $response_code ) {
$this->fail( sprintf( 'Could not contact dev.MySQL.com to check versions. Response code: %s', $response_code ) );
}
$mysql = wp_remote_retrieve_body( $response );
preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $mysql, $mysqlmatches );
// Per https://www.mysql.com/support/, Oracle actively supports MySQL releases for 5 years from GA release

View File

@ -15,31 +15,10 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
var $redirection_script = 'http://api.wordpress.org/core/tests/1.0/redirection.php';
var $fileStreamUrl = 'http://s.w.org/screenshots/3.9/dashboard.png';
protected $http_request_args;
/**
* Mark test as skipped if the HTTP request times out
*/
function skipTestOnTimeout( $response ) {
if( ! is_wp_error( $response ) ){
return;
}
if ( 'connect() timed out!' === $response->get_error_message() ){
$this->markTestSkipped( 'HTTP timeout' );
}
if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ){
$this->markTestSkipped( 'HTTP timeout' );
}
if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
$this->markTestSkipped( 'HTTP timeout' );
}
}
function setUp() {
protected $http_request_args;
function setUp() {
if ( is_callable( array('WP_Http', '_getTransport') ) ) {
$this->markTestSkipped('The WP_Http tests require a class-http.php file of r17550 or later.');
return;
@ -71,89 +50,111 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
}
function test_redirect_on_301() {
// 5 : 5 & 301
$res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
$this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] );
// 5 : 5 & 301
$res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] );
}
function test_redirect_on_302() {
// 5 : 5 & 302
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
$this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] );
// 5 : 5 & 302
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] );
}
/**
* @ticket 16855
*/
function test_redirect_on_301_no_redirect() {
// 5 > 0 & 301
$res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
$this->assertNotWPError( $res );
$this->assertEquals(301, (int)$res['response']['code'] );
// 5 > 0 & 301
$res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals(301, (int)$res['response']['code'] );
}
/**
* @ticket 16855
*/
function test_redirect_on_302_no_redirect() {
// 5 > 0 & 302
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
$this->assertNotWPError( $res );
$this->assertEquals(302, (int)$res['response']['code'] );
// 5 > 0 & 302
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals(302, (int)$res['response']['code'] );
}
function test_redirections_equal() {
// 5 - 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
$this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] );
// 5 - 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] );
}
function test_no_head_redirections() {
// No redirections on HEAD request:
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int)$res['response']['code'] );
// No redirections on HEAD request:
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int)$res['response']['code'] );
}
/**
* @ticket 16855
*/
function test_redirect_on_head() {
// Redirections on HEAD request when Requested
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int)$res['response']['code'] );
// Redirections on HEAD request when Requested
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int)$res['response']['code'] );
}
function test_redirections_greater() {
// 10 > 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
$this->assertTrue( is_wp_error($res), print_r($res, true) );
}
// 10 > 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertWPError( $res );
}
function test_redirections_greater_edgecase() {
// 6 > 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
$this->assertTrue( is_wp_error($res) );
}
// 6 > 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertWPError( $res );
}
function test_redirections_less_edgecase() {
// 4 < 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
$this->assertNotWPError( $res );
}
// 4 < 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}
/**
* @ticket 16855
*/
function test_redirections_zero_redirections_specified() {
// 0 redirections asked for, Should return the document?
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int)$res['response']['code'] );
// 0 redirections asked for, Should return the document?
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int)$res['response']['code'] );
}
/**
@ -162,10 +163,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
* @ticket 16889
*/
function test_location_header_on_201() {
// Prints PASS on initial load, FAIL if the client follows the specified redirection
$res = wp_remote_request( $this->redirection_script . '?201-location=true' );
$this->assertNotWPError( $res );
$this->assertEquals( 'PASS', $res['body']);
// Prints PASS on initial load, FAIL if the client follows the specified redirection
$res = wp_remote_request( $this->redirection_script . '?201-location=true' );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 'PASS', $res['body']);
}
/**
@ -176,10 +179,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_no_redirection_on_PUT() {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?201-location=1';
// Test 301 - POST to POST
$res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$this->assertTrue( !empty( $res['headers']['location'] ) );
// Test 301 - POST to POST
$res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$this->assertTrue( !empty( $res['headers']['location'] ) );
}
/**
@ -188,10 +193,11 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_send_headers() {
// Test that the headers sent are recieved by the server
$headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
$res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
$this->assertNotWPError( $res );
$res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$headers = array();
foreach ( explode("\n", $res['body']) as $key => $value ) {
if ( empty($value) )
@ -218,11 +224,10 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$filesize = filesize( $res['filename'] );
unlink( $res['filename'] );
}
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( '', $res['body'] ); // The body should be empty.
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( '', $res['body'] ); // The body should be empty.
$this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..)
$this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
$this->assertStringStartsWith( get_temp_dir(), $res['filename'] ); // Check it's saving within the temp dir
@ -241,11 +246,10 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$filesize = filesize( $res['filename'] );
unlink( $res['filename'] );
}
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
}
@ -259,40 +263,56 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$size = 10000;
$res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, strlen( $res['body'] ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, strlen( $res['body'] ) );
}
/**
* Test POST redirection methods
*
* @dataProvider data_post_redirect_to_method_300
*
* @ticket 17588
*/
function test_post_redirect_to_method_300() {
function test_post_redirect_to_method_300( $response_code, $method ) {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1';
// Test 300 - POST to POST
$res = wp_remote_post( add_query_arg( 'response_code', 300, $url ), array( 'timeout' => 30 ) );
$this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) );
$res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
// Test 301 - POST to POST
$res = wp_remote_post( add_query_arg( 'response_code', 301, $url ), array( 'timeout' => 30 ) );
$this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
}
// Test 302 - POST to GET
$res = wp_remote_post( add_query_arg( 'response_code', 302, $url ), array( 'timeout' => 30 ) );
$this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) );
// Test 303 - POST to GET
$res = wp_remote_post( add_query_arg( 'response_code', 303, $url ), array( 'timeout' => 30 ) );
$this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) );
// Test 304 - POST to POST
$res = wp_remote_post( add_query_arg( 'response_code', 304, $url ), array( 'timeout' => 30 ) );
$this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) );
public function data_post_redirect_to_method_300() {
return array(
// Test 300 - POST to POST
array(
300,
'POST',
),
// Test 301 - POST to POST
array(
301,
'POST',
),
// Test 302 - POST to GET
array(
302,
'GET',
),
// Test 303 - POST to GET
array(
303,
'GET',
),
// Test 304 - POST to POST
array(
304,
'POST',
),
);
}
/**
@ -310,10 +330,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
'timeout' => 30,
'redirection' => 0,
);
$res = wp_remote_get( $url, $args );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$res = wp_remote_get( $url, $args );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
/**
@ -331,10 +353,11 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$res = wp_remote_head( $url, $args );
remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
$this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
$this->assertNotWPError( $res );
remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
$this->skipTestOnTimeout( $res );
$this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
$this->assertNotWPError( $res );
}
/**
@ -344,14 +367,17 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*/
function test_multiple_location_headers() {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1';
$res = wp_remote_head( $url, array( 'timeout' => 30 ) );
$this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
$this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
$res = wp_remote_get( $url, array( 'timeout' => 30 ) );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$res = wp_remote_head( $url, array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
$this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
$res = wp_remote_get( $url, array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
/**
@ -361,10 +387,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*/
function test_cookie_handling() {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1';
$res = wp_remote_get( $url );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
$res = wp_remote_get( $url );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
/**
* Test if HTTPS support works
@ -375,10 +403,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_ssl() {
if ( ! wp_http_supports( array( 'ssl' ) ) )
$this->markTestSkipped( 'This install of PHP does not support SSL' );
$res = wp_remote_get( 'https://wordpress.org/' );
$this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
}
$res = wp_remote_get( 'https://wordpress.org/' );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}
}

View File

@ -3,10 +3,11 @@
/**
* @group http
* @group external-http
*/
class Tests_HTTP_Functions extends WP_UnitTestCase {
public function setUp() {
if ( ! extension_loaded( 'openssl' ) ) {
*/
class Tests_HTTP_Functions extends WP_UnitTestCase {
public function setUp() {
if ( ! extension_loaded( 'openssl' ) ) {
$this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
}
@ -15,10 +16,13 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
function test_head_request() {
// this url give a direct 200 response
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$headers = wp_remote_retrieve_headers( $response );
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$this->skipTestOnTimeout( $response );
$headers = wp_remote_retrieve_headers( $response );
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
$this->assertEquals( '40148', $headers['content-length'] );
@ -27,25 +31,31 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
function test_head_redirect() {
// this url will 301 redirect
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
}
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
$this->skipTestOnTimeout( $response );
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
}
function test_head_404() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
$headers = wp_remote_head( $url );
$response = wp_remote_head( $url );
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
$this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
$this->skipTestOnTimeout( $response );
$this->assertInternalType( 'array', $response, "Reply wasn't array." );
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
}
function test_get_request() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_get( $url );
$headers = wp_remote_retrieve_headers( $response );
$response = wp_remote_get( $url );
$this->skipTestOnTimeout( $response );
$headers = wp_remote_retrieve_headers( $response );
// should return the same headers as a head request
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
@ -56,10 +66,13 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
function test_get_redirect() {
// this will redirect to asdftestblog1.files.wordpress.com
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_get( $url );
$headers = wp_remote_retrieve_headers( $response );
$response = wp_remote_get( $url );
$this->skipTestOnTimeout( $response );
$headers = wp_remote_retrieve_headers( $response );
// should return the same headers as a head request
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
@ -71,10 +84,12 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
// this will redirect to asdftestblog1.files.wordpress.com
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
// pretend we've already redirected 5 times
$response = wp_remote_get( $url, array( 'redirection' => -1 ) );
$this->assertWPError( $response );
}
// pretend we've already redirected 5 times
$response = wp_remote_get( $url, array( 'redirection' => -1 ) );
$this->skipTestOnTimeout( $response );
$this->assertWPError( $response );
}
/**
* @ticket 33711
@ -82,9 +97,12 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
function test_get_response_cookies() {
$url = 'https://login.wordpress.org/wp-login.php';
$response = wp_remote_head( $url );
$cookies = wp_remote_retrieve_cookies( $response );
$response = wp_remote_head( $url );
$this->skipTestOnTimeout( $response );
$cookies = wp_remote_retrieve_cookies( $response );
$this->assertInternalType( 'array', $cookies );
$this->assertNotEmpty( $cookies );