<!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>[50104] branches/4.0/tests/phpunit/tests/http: 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/50104">50104</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/50104","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 21:03:08 +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.0 branch.
See <a href="https://core.trac.wordpress.org/ticket/51669">#51669</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches40testsphpunitincludestestcasephp">branches/4.0/tests/phpunit/includes/testcase.php</a></li>
<li><a href="#branches40testsphpunittestshttpbasephp">branches/4.0/tests/phpunit/tests/http/base.php</a></li>
<li><a href="#branches40testsphpunittestshttpfunctionsphp">branches/4.0/tests/phpunit/tests/http/functions.php</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#branches40">branches/4.0/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/4.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">--- branches/4.0 2021-01-30 21:01:52 UTC (rev 50103)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/4.0  2021-01-30 21:03:08 UTC (rev 50104)
</ins><a id="branches40"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/4.0</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
</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:29723-29725,29727,29730,29733,29738,29745-29746,29751,29755,29765-29766,29777,29783,29829,29860,29869,29884,29886,29954,29979,30001,30090,30160,30185,30242,30263-30264,30282,30285,30378,30401,30412,30417,30422,30425,30430,30435,30438,30443,30458,30466,30513-30514,30517-30521,30526,30529-30530,31253-31254,31257-31259,33124,33142,33374,36083,36435,37651,38524,39645,39659,39759,39772,39795,39807-39808,39831,39850,39956,40148,40160,40169,40183,40241,40400,40538,40604,40677,40692,40704,40723,40736,41072,41393,41395,41398,41457,41470,41483,41496,41522,41662,41712,42056,42119-42120,42258-42261,42424,42433,42892-42893,44021,44048,44842,44993,45936,45971,45997,46895,47341,47947-47951,48241,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:29723-29725,29727,29730,29733,29738,29745-29746,29751,29755,29765-29766,29777,29783,29829,29860,29869,29884,29886,29954,29979,30001,30090,30160,30185,30242,30263-30264,30282,30285,30378,30401,30412,30417,30422,30425,30430,30435,30438,30443,30458,30466,30513-30514,30517-30521,30526,30529-30530,31253-31254,31257-31259,33124,33142,33374,36083,36435,37651,38524,38757,39645,39659,39759,39772,39795,39807-39808,39831,39850,39956,40148,40160,40169,40183,40241,40400,40538,40604,40677,40692,40704,40723,40736,41072,41393,41395,41398,41457,41470,41483,41496,41522,41662,41712,42056,42119-42120,42258-42261,42424,42433,42892-42893,43511-43512,44021,44048,44842,44993,45936,45971,45997,46682,46895,46996,47341,47947-47951,48241,49380,49382-49388,49876
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches40testsphpunitincludestestcasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/tests/phpunit/includes/testcase.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/tests/phpunit/includes/testcase.php  2021-01-30 21:01:52 UTC (rev 50103)
+++ branches/4.0/tests/phpunit/includes/testcase.php    2021-01-30 21:03:08 UTC (rev 50104)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,6 +55,29 @@
</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">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * 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">          * Unregister existing post types and register defaults.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * Run before each test in order to clean up the global scope, in case
</span></span></pre></div>
<a id="branches40testsphpunittestshttpbasephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/tests/phpunit/tests/http/base.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/tests/phpunit/tests/http/base.php    2021-01-30 21:01:52 UTC (rev 50103)
+++ branches/4.0/tests/phpunit/tests/http/base.php      2021-01-30 21:03:08 UTC (rev 50104)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,6 +44,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirect_on_301() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 5 : 5 & 301
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals(200, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -51,6 +53,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirect_on_302() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 5 : 5 & 302
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals(200, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -61,6 +65,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirect_on_301_no_redirect() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 5 > 0 & 301
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals(301, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,6 +77,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirect_on_302_no_redirect() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 5 > 0 & 302
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals(302, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,6 +86,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirections_equal() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 5 - 5
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals(200, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -85,6 +95,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_no_head_redirections() {
</span><span class="cx" style="display: block; padding: 0 10px">                // No redirections on HEAD request:
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 302, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,6 +107,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirect_on_head() {
</span><span class="cx" style="display: block; padding: 0 10px">                // Redirections on HEAD request when Requested
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 200, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,6 +116,8 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertTrue( is_wp_error($res), print_r($res, true) );
</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">@@ -108,6 +124,8 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertTrue( is_wp_error($res) );
</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">@@ -114,6 +132,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirections_less_edgecase() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 4 < 5 (close edgecase)
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</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">@@ -123,6 +143,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_redirections_zero_redirections_specified() {
</span><span class="cx" style="display: block; padding: 0 10px">                // 0 redirections asked for, Should return the document?
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 302, (int)$res['response']['code'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -135,6 +157,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_location_header_on_201() {
</span><span class="cx" style="display: block; padding: 0 10px">                // Prints PASS on initial load, FAIL if the client follows the specified redirection
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request( $this->redirection_script . '?201-location=true' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error( $res ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'PASS', $res['body']);
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -149,6 +173,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Test 301 - POST to POST
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertTrue( !empty( $res['headers']['location'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -161,6 +187,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
</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 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error($res) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $headers = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -184,41 +211,63 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $size = 87348;
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_request( $url, array( 'stream' => true, 'timeout' => 30 ) ); //Auto generate the 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">+                // Cleanup before we assert, as it'll return early. 
+               if ( ! is_wp_error( $res ) ) {
+                       $filesize = filesize( $res['filename'] );
+                       unlink( $res['filename'] );
+               }
+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertFalse( is_wp_error( $res ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( '', $res['body'] ); // The body should be empty.
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $size, filesize($res['filename']) ); // Check that the file is written to disk correctly without any extra characters
-
-               unlink($res['filename']); // Remove the temporary file
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $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><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 ) );
-
-               // 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 ) );
</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',
+                       ),
+                       // Test 304 - POST to POST
+                       array(
+                               304,
+                               'POST',
+                       ),
+               );
</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">@@ -238,6 +287,8 @@
</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">                $res = wp_remote_get( $url, $args );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
</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">@@ -251,10 +302,13 @@
</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><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_head( $url, array( 'timeout' => 30 ) );
</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 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_get( $url, array( 'timeout' => 30 ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
</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">@@ -268,6 +322,8 @@
</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><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $res = wp_remote_get( $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
</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">@@ -282,6 +338,8 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $res );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="branches40testsphpunittestshttpfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.0/tests/phpunit/tests/http/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.0/tests/phpunit/tests/http/functions.php       2021-01-30 21:01:52 UTC (rev 50103)
+++ branches/4.0/tests/phpunit/tests/http/functions.php 2021-01-30 21:03:08 UTC (rev 50104)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +17,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // this url give a direct 200 response
</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><span class="cx" style="display: block; padding: 0 10px">                $response = wp_remote_head( $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $response );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $headers = wp_remote_retrieve_headers( $response );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertInternalType( 'array', $headers, "Reply wasn't array." );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -29,58 +32,61 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // this url will 301 redirect
</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">                $response = wp_remote_head( $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $this->skipTestOnTimeout( $response );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
</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_head_404() {
</span><span class="cx" style="display: block; padding: 0 10px">                $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $headers = wp_remote_head( $url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = wp_remote_head( $url );
</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->assertInternalType( 'array', $headers, "Reply wasn't array." );
-               $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->skipTestOnTimeout( $response );
+               $this->assertInternalType( 'array', $response, "Reply wasn't array." );
+               $this->assertEquals( '404', wp_remote_retrieve_response_code( $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">        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">-                $file = tempnam('/tmp', 'testfile');
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $headers = wp_get_http($url, $file);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = wp_remote_get( $url );
</ins><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( $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->assertInternalType( 'array', $headers, "Reply wasn't array." );
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( '200', $headers['response'] );
-
-               // make sure the file is ok
-               $this->assertEquals( 40148, filesize($file) );
-               $this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( '200', wp_remote_retrieve_response_code( $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">        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">-                $file = tempnam('/tmp', 'testfile');
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $headers = wp_get_http($url, $file);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = wp_remote_get( $url );
</ins><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( $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->assertInternalType( 'array', $headers, "Reply wasn't array." );
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( '200', $headers['response'] );
-
-               // make sure the file is ok
-               $this->assertEquals( 40148, filesize($file) );
-               $this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( '200', wp_remote_retrieve_response_code( $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">        function test_get_redirect_limit_exceeded() {
</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">-                $file = tempnam('/tmp', 'testfile');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // pretend we've already redirected 5 times
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $headers = wp_get_http( $url, $file, 6 );
-               $this->assertFalse( $headers );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
+
+               $this->skipTestOnTimeout( $response );
+               $this->assertTrue( is_wp_error( $response ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>