<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[50089] branches/4.6/tests/phpunit/tests: Tests: Use `skipTestOnTimeout()` in more HTTP tests.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/50089">50089</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/50089","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-01-30 11:45:38 +0000 (Sat, 30 Jan 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Use `skipTestOnTimeout()` in more HTTP tests.
Adjust it to handle more types of timeouts, e.g. "Resolving timed out", "Connection timed out".
Merges <a href="https://core.trac.wordpress.org/changeset/38757">[38757]</a>, <a href="https://core.trac.wordpress.org/changeset/43511">[43511]</a>, <a href="https://core.trac.wordpress.org/changeset/43512">[43512]</a>, <a href="https://core.trac.wordpress.org/changeset/46682">[46682]</a>, <a href="https://core.trac.wordpress.org/changeset/46996">[46996]</a> to the 4.6 branch.
See <a href="https://core.trac.wordpress.org/ticket/51669">#51669</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches46testsphpunitincludestestcasephp">branches/4.6/tests/phpunit/includes/testcase.php</a></li>
<li><a href="#branches46testsphpunittestsexternalhttpbasicphp">branches/4.6/tests/phpunit/tests/external-http/basic.php</a></li>
<li><a href="#branches46testsphpunittestshttpbasephp">branches/4.6/tests/phpunit/tests/http/base.php</a></li>
<li><a href="#branches46testsphpunittestshttpfunctionsphp">branches/4.6/tests/phpunit/tests/http/functions.php</a></li>
</ul>
<h3>Property Changed</h3>
<ul>
<li><a href="#branches46">branches/4.6/</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/4.6
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/4.6 2021-01-30 11:29:34 UTC (rev 50088)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/4.6 2021-01-30 11:45:38 UTC (rev 50089)
</ins><a id="branches46"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/4.6</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/4.9:42434,49653
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.0:43988,43994,44014,44017,44047,45005
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.5:49373-49379,49381
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:38181,38183,38185-38186,38189,38191,38194,38196,38199,38201,38205,38207,38209,38211-38213,38215-38216,38218,38221,38225,38227,38234-38235,38242,38244,38248,38251,38255,38257,38261,38263,38267,38274,38276-38277,38281,38286,38349,38415,38426-38427,38429-38431,38433,38439,38441,38443,38447,38524,38580,38727,38894,39645,39659,39759-39760,39772,39795,39807-39808,39831,39850,39956,40148,40160,40169,40183,40195,40241,40269,40271,40400,40538,40604,40677,40689,40692,40704,40716,40723,40736,40851-40852,41072,41393,41395,41397-41398,41448,41457,41470,41483,41496,41662,41712,41870,42056,42119-42120,42258-42261,42424,42433,42892-42894,44021,44048,44833,44842,44993,45067,45745,45762,45783-45784,45800,45819,45885,45936,45971,45990,45997,46320,46474-46478,46483,46485,46895,46999,47225,47341,47634-47635,47637-47638,47912,47947-47951,48121,48241,49335,49358,49360,49362,49380,49382-49388,49876
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:38181,38183,38185-38186,38189,38191,38194,38196,38199,38201,38205,38207,38209,38211-38213,38215-38216,38218,38221,38225,38227,38234-38235,38242,38244,38248,38251,38255,38257,38261,38263,38267,38274,38276-38277,38281,38286,38349,38415,38426-38427,38429-38431,38433,38439,38441,38443,38447,38524,38580,38727,38757,38894,39645,39659,39759-39760,39772,39795,39807-39808,39831,39850,39956,40148,40160,40169,40183,40195,40241,40269,40271,40400,40538,40604,40677,40689,40692,40704,40716,40723,40736,40851-40852,41072,41393,41395,41397-41398,41448,41457,41470,41483,41496,41662,41712,41870,42056,42119-42120,42258-42261,42424,42433,42892-42894,43511-43512,44021,44048,44833,44842,44993,45067,45745,45762,45783-45784,45800,45819,45885,45936,45971,45990,45997,46320,46474-46478,46483,46485,46682,46895,46996,46999,47225,47341,47634-47635,47637-47638,47912,47947-47951,48121,48241,49335,49358,49360,49362
,49380,49382-49388,49876
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches46testsphpunitincludestestcasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.6/tests/phpunit/includes/testcase.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.6/tests/phpunit/includes/testcase.php 2021-01-30 11:29:34 UTC (rev 50088)
+++ branches/4.6/tests/phpunit/includes/testcase.php 2021-01-30 11:45:38 UTC (rev 50089)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -160,11 +160,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->flush_cache();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- /**
- * Allow tests to be skipped on some automated runs
- *
- * For test runs on Travis for something other than trunk/master
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Allow tests to be skipped on some automated runs.
+ *
+ * For test runs on Travis for something other than trunk/master
</ins><span class="cx" style="display: block; padding: 0 10px"> * we want to skip tests that only need to run for master.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function skipOnAutomatedBranches() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -215,10 +215,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function reset_post_statuses() {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( get_post_stati( array( '_builtin' => false ) ) as $post_status ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- _unregister_post_status( $post_status );
- }
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _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' );
+ }
+
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Reset `$_SERVER` variables
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="branches46testsphpunittestsexternalhttpbasicphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.6/tests/phpunit/tests/external-http/basic.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.6/tests/phpunit/tests/external-http/basic.php 2021-01-30 11:29:34 UTC (rev 50088)
+++ branches/4.6/tests/phpunit/tests/external-http/basic.php 2021-01-30 11:45:38 UTC (rev 50089)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7,28 +7,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function test_readme() {
</span><span class="cx" style="display: block; padding: 0 10px"> // This test is designed to only run on trunk/master
</span><span class="cx" style="display: block; padding: 0 10px"> $this->skipOnAutomatedBranches();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $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 );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $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 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> preg_match_all( '#<tr class="stable">\s*<td>\s*<a [^>]*>\s*([0-9.]*)#s', $php, $phpmatches );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( $matches[1], $phpmatches[1], "readme.html's Recommended PHP version is too old. Remember to update the WordPress.org Requirements page, too." );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $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 );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $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 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> preg_match( '#(\d{4}-\d{2}-\d{2}), General Availability#', $mysql, $mysqlmatches );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Per https://www.mysql.com/support/, Oracle actively supports MySQL releases for 5 years from GA release
</span></span></pre></div>
<a id="branches46testsphpunittestshttpbasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.6/tests/phpunit/tests/http/base.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.6/tests/phpunit/tests/http/base.php 2021-01-30 11:29:34 UTC (rev 50088)
+++ branches/4.6/tests/phpunit/tests/http/base.php 2021-01-30 11:45:38 UTC (rev 50089)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,31 +15,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var $redirection_script = 'http://api.wordpress.org/core/tests/1.0/redirection.php';
</span><span class="cx" style="display: block; padding: 0 10px"> var $fileStreamUrl = 'http://s.w.org/screenshots/3.9/dashboard.png';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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() {
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $http_request_args;
+
+ function setUp() {
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_callable( array('WP_Http', '_getTransport') ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->markTestSkipped('The WP_Http tests require a class-http.php file of r17550 or later.');
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,17 +50,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirect_on_301() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirect_on_302() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,10 +71,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 16855
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirect_on_301_no_redirect() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -98,24 +83,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 16855
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirect_on_302_no_redirect() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirections_equal() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 5 - 5
- $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
- $this->assertNotWPError( $res );
- $this->assertEquals(200, (int)$res['response']['code'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_no_head_redirections() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -122,38 +113,48 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 16855
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirect_on_head() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirections_greater() {
</span><span class="cx" style="display: block; padding: 0 10px"> // 10 > 5
</span><span class="cx" style="display: block; padding: 0 10px"> $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( is_wp_error($res), print_r($res, true) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->skipTestOnTimeout( $res );
+ $this->assertWPError( $res );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirections_greater_edgecase() {
</span><span class="cx" style="display: block; padding: 0 10px"> // 6 > 5 (close edgecase)
</span><span class="cx" style="display: block; padding: 0 10px"> $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( is_wp_error($res) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->skipTestOnTimeout( $res );
+ $this->assertWPError( $res );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirections_less_edgecase() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 4 < 5 (close edgecase)
- $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
- $this->assertNotWPError( $res );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 4 < 5 (close edgecase)
+ $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 16855
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_redirections_zero_redirections_specified() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -162,10 +163,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 16889
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_location_header_on_201() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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']);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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']);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -176,10 +179,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function test_no_redirection_on_PUT() {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?201-location=1';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -188,10 +193,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function test_send_headers() {
</span><span class="cx" style="display: block; padding: 0 10px"> // Test that the headers sent are recieved by the server
</span><span class="cx" style="display: block; padding: 0 10px"> $headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
-
- $this->assertNotWPError( $res );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $headers = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( explode("\n", $res['body']) as $key => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty($value) )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -218,11 +224,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $filesize = filesize( $res['filename'] );
</span><span class="cx" style="display: block; padding: 0 10px"> unlink( $res['filename'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $this->skipTestOnTimeout( $res );
-
- $this->assertNotWPError( $res );
- $this->assertEquals( '', $res['body'] ); // The body should be empty.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
+ $this->assertEquals( '', $res['body'] ); // The body should be empty.
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..)
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertStringStartsWith( get_temp_dir(), $res['filename'] ); // Check it's saving within the temp dir
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -241,12 +246,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $filesize = filesize( $res['filename'] );
</span><span class="cx" style="display: block; padding: 0 10px"> unlink( $res['filename'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
+ $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->skipTestOnTimeout( $res );
-
- $this->assertNotWPError( $res );
- $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
-
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -259,36 +263,51 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $size = 10000;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $this->skipTestOnTimeout( $res );
-
- $this->assertNotWPError( $res );
- $this->assertEquals( $size, strlen( $res['body'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
+ $this->assertEquals( $size, strlen( $res['body'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Test POST redirection methods
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @dataProvider data_post_redirect_to_method_300
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 17588
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function test_post_redirect_to_method_300() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_post_redirect_to_method_300( $response_code, $method ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->skipTestOnTimeout( $res );
+ $this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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',
+ ),
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,10 +325,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => 30,
</span><span class="cx" style="display: block; padding: 0 10px"> 'redirection' => 0,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $res = wp_remote_get( $url, $args );
- $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $res = wp_remote_get( $url, $args );
+
+ $this->skipTestOnTimeout( $res );
+ $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -327,10 +348,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $res = wp_remote_head( $url, $args );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
-
- $this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
- $this->assertNotWPError( $res );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
+ $this->assertNotWPError( $res );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -340,14 +362,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_multiple_location_headers() {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 ) );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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 ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -357,11 +382,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_cookie_handling() {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $res = wp_remote_get( $url );
+
+ $this->skipTestOnTimeout( $res );
+ $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $res = wp_remote_get( $url );
- $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Test if HTTPS support works
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -373,7 +400,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->markTestSkipped( 'This install of PHP does not support SSL' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $res = wp_remote_get( 'https://wordpress.org/' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -384,10 +413,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $path = parse_url( $url, PHP_URL_PATH );
</span><span class="cx" style="display: block; padding: 0 10px"> $url = str_replace( $path, '/' . $path, $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $res = wp_remote_request( $url );
+
+ $this->skipTestOnTimeout( $res );
+ $this->assertNotWPError( $res );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $res = wp_remote_request( $url );
- $this->assertNotWPError( $res );
- }
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="branches46testsphpunittestshttpfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.6/tests/phpunit/tests/http/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.6/tests/phpunit/tests/http/functions.php 2021-01-30 11:29:34 UTC (rev 50088)
+++ branches/4.6/tests/phpunit/tests/http/functions.php 2021-01-30 11:45:38 UTC (rev 50089)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,10 +3,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @group http
</span><span class="cx" style="display: block; padding: 0 10px"> * @group external-http
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- */
-class Tests_HTTP_Functions extends WP_UnitTestCase {
- public function setUp() {
- if ( ! extension_loaded( 'openssl' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ */
+class Tests_HTTP_Functions extends WP_UnitTestCase {
+
+ public function setUp() {
+ if ( ! extension_loaded( 'openssl' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->markTestSkipped( 'Tests_HTTP_Functions requires openssl.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,10 +16,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_head_request() {
</span><span class="cx" style="display: block; padding: 0 10px"> // this url give a direct 200 response
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'image/jpeg', $headers['content-type'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( '40148', $headers['content-length'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -35,24 +39,30 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function test_head_redirect() {
</span><span class="cx" style="display: block; padding: 0 10px"> // this url will 301 redirect
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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 ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function test_head_404() {
- $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
- $headers = wp_remote_head( $url );
-
- $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_head_404() {
+ $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
+ $response = wp_remote_head( $url );
+
+ $this->skipTestOnTimeout( $response );
+ $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_get_request() {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $response = wp_remote_get( $url );
- $headers = wp_remote_retrieve_headers( $response );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $response = wp_remote_get( $url );
+
+ $this->skipTestOnTimeout( $response );
+
+ $headers = wp_remote_retrieve_headers( $response );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // should return the same headers as a head request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'image/jpeg', $headers['content-type'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( '40148', $headers['content-length'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -62,10 +72,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function test_get_redirect() {
</span><span class="cx" style="display: block; padding: 0 10px"> // this will redirect to asdftestblog1.files.wordpress.com
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- $response = wp_remote_get( $url );
- $headers = wp_remote_retrieve_headers( $response );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $response = wp_remote_get( $url );
+
+ $this->skipTestOnTimeout( $response );
+
+ $headers = wp_remote_retrieve_headers( $response );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // should return the same headers as a head request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'image/jpeg', $headers['content-type'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( '40148', $headers['content-length'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -76,10 +89,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // this will redirect to asdftestblog1.files.wordpress.com
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // pretend we've already redirected 5 times
- $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
- $this->assertWPError( $response );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // pretend we've already redirected 5 times
+ $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
+
+ $this->skipTestOnTimeout( $response );
+ $this->assertWPError( $response );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 33711
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,12 +101,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_get_response_cookies() {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = 'https://login.wordpress.org/wp-login.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $response = wp_remote_head( $url );
+
+ $this->skipTestOnTimeout( $response );
+
+ $cookies = wp_remote_retrieve_cookies( $response );
+
+ $this->assertNotEmpty( $cookies );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_head( $url );
- $cookies = wp_remote_retrieve_cookies( $response );
-
- $this->assertNotEmpty( $cookies );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $cookie = wp_remote_retrieve_cookie( $response, 'wordpress_test_cookie' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertInstanceOf( 'WP_Http_Cookie', $cookie );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( 'wordpress_test_cookie', $cookie->name );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -116,12 +134,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $response = wp_remote_get( $url, array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'cookies' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> new WP_Http_Cookie( array( 'name' => 'test', 'value' => 'foo' ) ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ),
- ) );
- $cookies = wp_remote_retrieve_cookies( $response );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ),
+ ) );
+
+ $this->skipTestOnTimeout( $response );
+
+ $cookies = wp_remote_retrieve_cookies( $response );
+
+ $this->assertNotEmpty( $cookies );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertNotEmpty( $cookies );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $cookie = wp_remote_retrieve_cookie( $response, 'test' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertInstanceOf( 'WP_Http_Cookie', $cookie );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( 'test', $cookie->name );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -137,12 +158,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $response = wp_remote_get( $url, array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'cookies' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'test' => 'foo',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ),
- ) );
- $cookies = wp_remote_retrieve_cookies( $response );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ),
+ ) );
+
+ $this->skipTestOnTimeout( $response );
+
+ $cookies = wp_remote_retrieve_cookies( $response );
+
+ $this->assertNotEmpty( $cookies );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertNotEmpty( $cookies );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $cookie = wp_remote_retrieve_cookie( $response, 'test' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertInstanceOf( 'WP_Http_Cookie', $cookie );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( 'test', $cookie->name );
</span></span></pre>
</div>
</div>
</body>
</html>