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.6 branch.
See #51669.

git-svn-id: https://develop.svn.wordpress.org/branches/4.6@50089 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-01-30 11:45:38 +00:00
parent a70e33d3bc
commit 70452d0e4a
4 changed files with 290 additions and 201 deletions

View File

@ -162,7 +162,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
} }
/** /**
* Allow tests to be skipped on some automated runs * Allow tests to be skipped on some automated runs.
* *
* For test runs on Travis for something other than trunk/master * For test runs on Travis for something other than trunk/master
* we want to skip tests that only need to run for master. * we want to skip tests that only need to run for master.
@ -219,6 +219,29 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
} }
} }
/**
* 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 * Reset `$_SERVER` variables
*/ */

View File

@ -9,12 +9,18 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
$this->skipOnAutomatedBranches(); $this->skipOnAutomatedBranches();
$readme = file_get_contents( ABSPATH . 'readme.html' ); $readme = file_get_contents( ABSPATH . 'readme.html' );
preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches ); preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches );
$response = wp_remote_get( 'https://secure.php.net/supported-versions.php' ); $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.' ); $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 ); $php = wp_remote_retrieve_body( $response );
preg_match_all( '#<tr class="stable">\s*<td>\s*<a [^>]*>\s*([0-9.]*)#s', $php, $phpmatches ); preg_match_all( '#<tr class="stable">\s*<td>\s*<a [^>]*>\s*([0-9.]*)#s', $php, $phpmatches );
@ -24,9 +30,14 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches ); 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/" ); $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.' ); $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 ); $mysql = wp_remote_retrieve_body( $response );
preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $mysql, $mysqlmatches ); preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $mysql, $mysqlmatches );

View File

@ -17,27 +17,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
protected $http_request_args; 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() { function setUp() {
if ( is_callable( array('WP_Http', '_getTransport') ) ) { if ( is_callable( array('WP_Http', '_getTransport') ) ) {
@ -73,6 +52,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_301() { function test_redirect_on_301() {
// 5 : 5 & 301 // 5 : 5 & 301
$res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) ); $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] ); $this->assertEquals(200, (int)$res['response']['code'] );
} }
@ -80,6 +61,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_302() { function test_redirect_on_302() {
// 5 : 5 & 302 // 5 : 5 & 302
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) ); $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] ); $this->assertEquals(200, (int)$res['response']['code'] );
} }
@ -90,6 +73,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_301_no_redirect() { function test_redirect_on_301_no_redirect() {
// 5 > 0 & 301 // 5 > 0 & 301
$res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) ); $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals(301, (int)$res['response']['code'] ); $this->assertEquals(301, (int)$res['response']['code'] );
} }
@ -100,6 +85,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_302_no_redirect() { function test_redirect_on_302_no_redirect() {
// 5 > 0 & 302 // 5 > 0 & 302
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) ); $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals(302, (int)$res['response']['code'] ); $this->assertEquals(302, (int)$res['response']['code'] );
} }
@ -107,6 +94,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_equal() { function test_redirections_equal() {
// 5 - 5 // 5 - 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) ); $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals(200, (int)$res['response']['code'] ); $this->assertEquals(200, (int)$res['response']['code'] );
} }
@ -114,6 +103,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_no_head_redirections() { function test_no_head_redirections() {
// No redirections on HEAD request: // No redirections on HEAD request:
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') ); $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( 302, (int)$res['response']['code'] ); $this->assertEquals( 302, (int)$res['response']['code'] );
} }
@ -124,6 +115,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_head() { function test_redirect_on_head() {
// Redirections on HEAD request when Requested // Redirections on HEAD request when Requested
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') ); $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( 200, (int)$res['response']['code'] ); $this->assertEquals( 200, (int)$res['response']['code'] );
} }
@ -131,18 +124,24 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_greater() { function test_redirections_greater() {
// 10 > 5 // 10 > 5
$res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) ); $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
$this->assertTrue( is_wp_error($res), print_r($res, true) );
$this->skipTestOnTimeout( $res );
$this->assertWPError( $res );
} }
function test_redirections_greater_edgecase() { function test_redirections_greater_edgecase() {
// 6 > 5 (close edgecase) // 6 > 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) ); $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
$this->assertTrue( is_wp_error($res) );
$this->skipTestOnTimeout( $res );
$this->assertWPError( $res );
} }
function test_redirections_less_edgecase() { function test_redirections_less_edgecase() {
// 4 < 5 (close edgecase) // 4 < 5 (close edgecase)
$res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) ); $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
} }
@ -152,6 +151,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_zero_redirections_specified() { function test_redirections_zero_redirections_specified() {
// 0 redirections asked for, Should return the document? // 0 redirections asked for, Should return the document?
$res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) ); $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( 302, (int)$res['response']['code'] ); $this->assertEquals( 302, (int)$res['response']['code'] );
} }
@ -164,6 +165,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_location_header_on_201() { function test_location_header_on_201() {
// Prints PASS on initial load, FAIL if the client follows the specified redirection // Prints PASS on initial load, FAIL if the client follows the specified redirection
$res = wp_remote_request( $this->redirection_script . '?201-location=true' ); $res = wp_remote_request( $this->redirection_script . '?201-location=true' );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( 'PASS', $res['body']); $this->assertEquals( 'PASS', $res['body']);
} }
@ -178,6 +181,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
// Test 301 - POST to POST // Test 301 - POST to POST
$res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) ); $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$this->assertTrue( !empty( $res['headers']['location'] ) ); $this->assertTrue( !empty( $res['headers']['location'] ) );
} }
@ -190,6 +195,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$headers = array('test1' => 'test', 'test2' => 0, 'test3' => ''); $headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
$res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) ); $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$headers = array(); $headers = array();
@ -220,7 +226,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
} }
$this->skipTestOnTimeout( $res ); $this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( '', $res['body'] ); // The body should be empty. $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, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..)
@ -243,7 +248,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
} }
$this->skipTestOnTimeout( $res ); $this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
@ -261,7 +265,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) ); $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
$this->skipTestOnTimeout( $res ); $this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
$this->assertEquals( $size, strlen( $res['body'] ) ); $this->assertEquals( $size, strlen( $res['body'] ) );
} }
@ -269,26 +272,42 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/** /**
* Test POST redirection methods * Test POST redirection methods
* *
* @dataProvider data_post_redirect_to_method_300
*
* @ticket 17588 * @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'; $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1';
$res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
}
public function data_post_redirect_to_method_300() {
return array(
// Test 300 - POST to POST // Test 300 - POST to POST
$res = wp_remote_post( add_query_arg( 'response_code', 300, $url ), array( 'timeout' => 30 ) ); array(
$this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 300,
'POST',
),
// Test 301 - POST to POST // Test 301 - POST to POST
$res = wp_remote_post( add_query_arg( 'response_code', 301, $url ), array( 'timeout' => 30 ) ); array(
$this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 301,
'POST',
),
// Test 302 - POST to GET // Test 302 - POST to GET
$res = wp_remote_post( add_query_arg( 'response_code', 302, $url ), array( 'timeout' => 30 ) ); array(
$this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 302,
'GET',
),
// Test 303 - POST to GET // Test 303 - POST to GET
$res = wp_remote_post( add_query_arg( 'response_code', 303, $url ), array( 'timeout' => 30 ) ); array(
$this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 303,
'GET',
),
);
} }
/** /**
@ -308,6 +327,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
); );
$res = wp_remote_get( $url, $args ); $res = wp_remote_get( $url, $args );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
} }
@ -329,6 +350,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) ); remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
$this->skipTestOnTimeout( $res );
$this->assertNotEmpty( $this->http_request_args['sslcertificates'] ); $this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
} }
@ -342,10 +364,13 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1'; $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1';
$res = wp_remote_head( $url, array( 'timeout' => 30 ) ); $res = wp_remote_head( $url, array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) ); $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
$this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) ); $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
$res = wp_remote_get( $url, array( 'timeout' => 30 ) ); $res = wp_remote_get( $url, array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
} }
@ -359,6 +384,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1'; $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1';
$res = wp_remote_get( $url ); $res = wp_remote_get( $url );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
} }
@ -373,7 +400,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$this->markTestSkipped( 'This install of PHP does not support SSL' ); $this->markTestSkipped( 'This install of PHP does not support SSL' );
$res = wp_remote_get( 'https://wordpress.org/' ); $res = wp_remote_get( 'https://wordpress.org/' );
$this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
} }
/** /**
@ -386,6 +415,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = str_replace( $path, '/' . $path, $url ); $url = str_replace( $path, '/' . $path, $url );
$res = wp_remote_request( $url ); $res = wp_remote_request( $url );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res ); $this->assertNotWPError( $res );
} }

View File

@ -5,6 +5,7 @@
* @group external-http * @group external-http
*/ */
class Tests_HTTP_Functions extends WP_UnitTestCase { class Tests_HTTP_Functions extends WP_UnitTestCase {
public function setUp() { public function setUp() {
if ( ! extension_loaded( 'openssl' ) ) { if ( ! extension_loaded( 'openssl' ) ) {
$this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' ); $this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
@ -17,6 +18,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
// this url give a direct 200 response // this url give a direct 200 response
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url ); $response = wp_remote_head( $url );
$this->skipTestOnTimeout( $response );
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
$this->assertEquals( 'image/jpeg', $headers['content-type'] ); $this->assertEquals( 'image/jpeg', $headers['content-type'] );
@ -37,20 +41,26 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
// this url will 301 redirect // this url will 301 redirect
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url ); $response = wp_remote_head( $url );
$this->skipTestOnTimeout( $response );
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) ); $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
} }
function test_head_404() { function test_head_404() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
$headers = wp_remote_head( $url ); $response = wp_remote_head( $url );
$this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) ); $this->skipTestOnTimeout( $response );
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
} }
function test_get_request() { function test_get_request() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_get( $url ); $response = wp_remote_get( $url );
$this->skipTestOnTimeout( $response );
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
// should return the same headers as a head request // should return the same headers as a head request
@ -64,6 +74,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_get( $url ); $response = wp_remote_get( $url );
$this->skipTestOnTimeout( $response );
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
// should return the same headers as a head request // should return the same headers as a head request
@ -78,6 +91,8 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
// pretend we've already redirected 5 times // pretend we've already redirected 5 times
$response = wp_remote_get( $url, array( 'redirection' => -1 ) ); $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
$this->skipTestOnTimeout( $response );
$this->assertWPError( $response ); $this->assertWPError( $response );
} }
@ -88,6 +103,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
$url = 'https://login.wordpress.org/wp-login.php'; $url = 'https://login.wordpress.org/wp-login.php';
$response = wp_remote_head( $url ); $response = wp_remote_head( $url );
$this->skipTestOnTimeout( $response );
$cookies = wp_remote_retrieve_cookies( $response ); $cookies = wp_remote_retrieve_cookies( $response );
$this->assertNotEmpty( $cookies ); $this->assertNotEmpty( $cookies );
@ -118,6 +136,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
new WP_Http_Cookie( array( 'name' => 'test', 'value' => 'foo' ) ), new WP_Http_Cookie( array( 'name' => 'test', 'value' => 'foo' ) ),
), ),
) ); ) );
$this->skipTestOnTimeout( $response );
$cookies = wp_remote_retrieve_cookies( $response ); $cookies = wp_remote_retrieve_cookies( $response );
$this->assertNotEmpty( $cookies ); $this->assertNotEmpty( $cookies );
@ -139,6 +160,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
'test' => 'foo', 'test' => 'foo',
), ),
) ); ) );
$this->skipTestOnTimeout( $response );
$cookies = wp_remote_retrieve_cookies( $response ); $cookies = wp_remote_retrieve_cookies( $response );
$this->assertNotEmpty( $cookies ); $this->assertNotEmpty( $cookies );