Changeset 50089 for branches/4.6
- Timestamp:
- 01/30/2021 11:45:38 AM (4 years ago)
- Location:
- branches/4.6
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.6
- Property svn:mergeinfo changed
/trunk merged: 38757,43511-43512,46682,46996
- Property svn:mergeinfo changed
-
branches/4.6/tests/phpunit/includes/testcase.php
r40249 r50089 163 163 164 164 /** 165 * Allow tests to be skipped on some automated runs 165 * Allow tests to be skipped on some automated runs. 166 166 * 167 167 * For test runs on Travis for something other than trunk/master … … 218 218 _unregister_post_status( $post_status ); 219 219 } 220 } 221 222 /** 223 * Allow tests to be skipped if the HTTP request times out. 224 * 225 * @param array|WP_Error $response HTTP response. 226 */ 227 public function skipTestOnTimeout( $response ) { 228 if ( ! is_wp_error( $response ) ) { 229 return; 230 } 231 if ( 'connect() timed out!' === $response->get_error_message() ) { 232 $this->markTestSkipped( 'HTTP timeout' ); 233 } 234 235 if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) { 236 $this->markTestSkipped( 'HTTP timeout' ); 237 } 238 239 if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) { 240 $this->markTestSkipped( 'HTTP timeout' ); 241 } 242 220 243 } 221 244 -
branches/4.6/tests/phpunit/tests/external-http/basic.php
r42101 r50089 10 10 11 11 $readme = file_get_contents( ABSPATH . 'readme.html' ); 12 12 13 preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches ); 13 14 14 15 $response = wp_remote_get( 'https://secure.php.net/supported-versions.php' ); 15 if ( 200 != wp_remote_retrieve_response_code( $response ) ) { 16 $this->markTestSkipped( 'Could not contact PHP.net to check versions.' ); 16 17 $this->skipTestOnTimeout( $response ); 18 19 $response_code = wp_remote_retrieve_response_code( $response ); 20 if ( 200 !== $response_code ) { 21 $this->fail( sprintf( 'Could not contact PHP.net to check versions. Response code: %s', $response_code ) ); 17 22 } 23 18 24 $php = wp_remote_retrieve_body( $response ); 19 25 … … 25 31 26 32 $response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" ); 27 if ( 200 != wp_remote_retrieve_response_code( $response ) ) { 28 $this->markTestSkipped( 'Could not contact dev.MySQL.com to check versions.' ); 33 34 $this->skipTestOnTimeout( $response ); 35 36 $response_code = wp_remote_retrieve_response_code( $response ); 37 if ( 200 !== $response_code ) { 38 $this->fail( sprintf( 'Could not contact dev.MySQL.com to check versions. Response code: %s', $response_code ) ); 29 39 } 40 30 41 $mysql = wp_remote_retrieve_body( $response ); 31 42 -
branches/4.6/tests/phpunit/tests/http/base.php
r38485 r50089 18 18 protected $http_request_args; 19 19 20 /**21 * Mark test as skipped if the HTTP request times out22 */23 function skipTestOnTimeout( $response ) {24 if( ! is_wp_error( $response ) ){25 return;26 }27 if ( 'connect() timed out!' === $response->get_error_message() ){28 $this->markTestSkipped( 'HTTP timeout' );29 }30 31 if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ){32 $this->markTestSkipped( 'HTTP timeout' );33 }34 35 if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {36 $this->markTestSkipped( 'HTTP timeout' );37 }38 39 }40 41 20 function setUp() { 42 21 … … 74 53 // 5 : 5 & 301 75 54 $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) ); 55 56 $this->skipTestOnTimeout( $res ); 76 57 $this->assertNotWPError( $res ); 77 58 $this->assertEquals(200, (int)$res['response']['code'] ); … … 81 62 // 5 : 5 & 302 82 63 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) ); 64 65 $this->skipTestOnTimeout( $res ); 83 66 $this->assertNotWPError( $res ); 84 67 $this->assertEquals(200, (int)$res['response']['code'] ); … … 91 74 // 5 > 0 & 301 92 75 $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) ); 76 77 $this->skipTestOnTimeout( $res ); 93 78 $this->assertNotWPError( $res ); 94 79 $this->assertEquals(301, (int)$res['response']['code'] ); … … 101 86 // 5 > 0 & 302 102 87 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) ); 88 89 $this->skipTestOnTimeout( $res ); 103 90 $this->assertNotWPError( $res ); 104 91 $this->assertEquals(302, (int)$res['response']['code'] ); … … 108 95 // 5 - 5 109 96 $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) ); 97 98 $this->skipTestOnTimeout( $res ); 110 99 $this->assertNotWPError( $res ); 111 100 $this->assertEquals(200, (int)$res['response']['code'] ); … … 115 104 // No redirections on HEAD request: 116 105 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') ); 106 107 $this->skipTestOnTimeout( $res ); 117 108 $this->assertNotWPError( $res ); 118 109 $this->assertEquals( 302, (int)$res['response']['code'] ); … … 125 116 // Redirections on HEAD request when Requested 126 117 $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') ); 118 119 $this->skipTestOnTimeout( $res ); 127 120 $this->assertNotWPError( $res ); 128 121 $this->assertEquals( 200, (int)$res['response']['code'] ); … … 132 125 // 10 > 5 133 126 $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) ); 134 $this->assertTrue( is_wp_error($res), print_r($res, true) ); 127 128 $this->skipTestOnTimeout( $res ); 129 $this->assertWPError( $res ); 135 130 } 136 131 … … 138 133 // 6 > 5 (close edgecase) 139 134 $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) ); 140 $this->assertTrue( is_wp_error($res) ); 135 136 $this->skipTestOnTimeout( $res ); 137 $this->assertWPError( $res ); 141 138 } 142 139 … … 144 141 // 4 < 5 (close edgecase) 145 142 $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) ); 143 144 $this->skipTestOnTimeout( $res ); 146 145 $this->assertNotWPError( $res ); 147 146 } … … 153 152 // 0 redirections asked for, Should return the document? 154 153 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) ); 154 155 $this->skipTestOnTimeout( $res ); 155 156 $this->assertNotWPError( $res ); 156 157 $this->assertEquals( 302, (int)$res['response']['code'] ); … … 165 166 // Prints PASS on initial load, FAIL if the client follows the specified redirection 166 167 $res = wp_remote_request( $this->redirection_script . '?201-location=true' ); 168 169 $this->skipTestOnTimeout( $res ); 167 170 $this->assertNotWPError( $res ); 168 171 $this->assertEquals( 'PASS', $res['body']); … … 179 182 // Test 301 - POST to POST 180 183 $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) ); 184 185 $this->skipTestOnTimeout( $res ); 181 186 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 182 187 $this->assertTrue( !empty( $res['headers']['location'] ) ); … … 191 196 $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) ); 192 197 198 $this->skipTestOnTimeout( $res ); 193 199 $this->assertNotWPError( $res ); 194 200 … … 221 227 222 228 $this->skipTestOnTimeout( $res ); 223 224 229 $this->assertNotWPError( $res ); 225 230 $this->assertEquals( '', $res['body'] ); // The body should be empty. … … 244 249 245 250 $this->skipTestOnTimeout( $res ); 246 247 251 $this->assertNotWPError( $res ); 248 252 $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters … … 262 266 263 267 $this->skipTestOnTimeout( $res ); 264 265 268 $this->assertNotWPError( $res ); 266 269 $this->assertEquals( $size, strlen( $res['body'] ) ); … … 270 273 * Test POST redirection methods 271 274 * 275 * @dataProvider data_post_redirect_to_method_300 276 * 272 277 * @ticket 17588 273 278 */ 274 function test_post_redirect_to_method_300( ) {279 function test_post_redirect_to_method_300( $response_code, $method ) { 275 280 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1'; 276 281 277 // Test 300 - POST to POST 278 $res = wp_remote_post( add_query_arg( 'response_code', 300, $url ), array( 'timeout' => 30 ) ); 279 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 280 281 // Test 301 - POST to POST 282 $res = wp_remote_post( add_query_arg( 'response_code', 301, $url ), array( 'timeout' => 30 ) ); 283 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 284 285 // Test 302 - POST to GET 286 $res = wp_remote_post( add_query_arg( 'response_code', 302, $url ), array( 'timeout' => 30 ) ); 287 $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 288 289 // Test 303 - POST to GET 290 $res = wp_remote_post( add_query_arg( 'response_code', 303, $url ), array( 'timeout' => 30 ) ); 291 $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 282 $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) ); 283 284 $this->skipTestOnTimeout( $res ); 285 $this->assertEquals( $method, wp_remote_retrieve_body( $res ) ); 286 } 287 288 public function data_post_redirect_to_method_300() { 289 return array( 290 // Test 300 - POST to POST 291 array( 292 300, 293 'POST', 294 ), 295 // Test 301 - POST to POST 296 array( 297 301, 298 'POST', 299 ), 300 // Test 302 - POST to GET 301 array( 302 302, 303 'GET', 304 ), 305 // Test 303 - POST to GET 306 array( 307 303, 308 'GET', 309 ), 310 ); 292 311 } 293 312 … … 309 328 310 329 $res = wp_remote_get( $url, $args ); 330 331 $this->skipTestOnTimeout( $res ); 311 332 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 312 333 … … 330 351 remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) ); 331 352 353 $this->skipTestOnTimeout( $res ); 332 354 $this->assertNotEmpty( $this->http_request_args['sslcertificates'] ); 333 355 $this->assertNotWPError( $res ); … … 343 365 $res = wp_remote_head( $url, array( 'timeout' => 30 ) ); 344 366 367 $this->skipTestOnTimeout( $res ); 345 368 $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) ); 346 369 $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) ); 347 370 348 371 $res = wp_remote_get( $url, array( 'timeout' => 30 ) ); 372 373 $this->skipTestOnTimeout( $res ); 349 374 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 350 375 … … 360 385 361 386 $res = wp_remote_get( $url ); 387 388 $this->skipTestOnTimeout( $res ); 362 389 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 363 390 } … … 374 401 375 402 $res = wp_remote_get( 'https://wordpress.org/' ); 376 $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) ); 403 404 $this->skipTestOnTimeout( $res ); 405 $this->assertNotWPError( $res ); 377 406 } 378 407 … … 387 416 388 417 $res = wp_remote_request( $url ); 418 419 $this->skipTestOnTimeout( $res ); 389 420 $this->assertNotWPError( $res ); 390 421 } -
branches/4.6/tests/phpunit/tests/http/functions.php
r38164 r50089 6 6 */ 7 7 class Tests_HTTP_Functions extends WP_UnitTestCase { 8 8 9 public function setUp() { 9 10 if ( ! extension_loaded( 'openssl' ) ) { … … 18 19 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; 19 20 $response = wp_remote_head( $url ); 21 22 $this->skipTestOnTimeout( $response ); 23 20 24 $headers = wp_remote_retrieve_headers( $response ); 21 25 … … 38 42 $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; 39 43 $response = wp_remote_head( $url ); 44 45 $this->skipTestOnTimeout( $response ); 40 46 $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) ); 41 47 } … … 43 49 function test_head_404() { 44 50 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; 45 $ headers= wp_remote_head( $url );51 $response = wp_remote_head( $url ); 46 52 47 $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) ); 53 $this->skipTestOnTimeout( $response ); 54 $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) ); 48 55 } 49 56 … … 52 59 53 60 $response = wp_remote_get( $url ); 61 62 $this->skipTestOnTimeout( $response ); 63 54 64 $headers = wp_remote_retrieve_headers( $response ); 55 65 … … 65 75 66 76 $response = wp_remote_get( $url ); 77 78 $this->skipTestOnTimeout( $response ); 79 67 80 $headers = wp_remote_retrieve_headers( $response ); 68 81 … … 79 92 // pretend we've already redirected 5 times 80 93 $response = wp_remote_get( $url, array( 'redirection' => -1 ) ); 94 95 $this->skipTestOnTimeout( $response ); 81 96 $this->assertWPError( $response ); 82 97 } … … 89 104 90 105 $response = wp_remote_head( $url ); 91 $cookies = wp_remote_retrieve_cookies( $response ); 106 107 $this->skipTestOnTimeout( $response ); 108 109 $cookies = wp_remote_retrieve_cookies( $response ); 92 110 93 111 $this->assertNotEmpty( $cookies ); … … 119 137 ), 120 138 ) ); 121 $cookies = wp_remote_retrieve_cookies( $response ); 139 140 $this->skipTestOnTimeout( $response ); 141 142 $cookies = wp_remote_retrieve_cookies( $response ); 122 143 123 144 $this->assertNotEmpty( $cookies ); … … 140 161 ), 141 162 ) ); 142 $cookies = wp_remote_retrieve_cookies( $response ); 163 164 $this->skipTestOnTimeout( $response ); 165 166 $cookies = wp_remote_retrieve_cookies( $response ); 143 167 144 168 $this->assertNotEmpty( $cookies );
Note: See TracChangeset
for help on using the changeset viewer.