Changeset 50088 for branches/4.7/tests/phpunit/tests/http/base.php
- Timestamp:
- 01/30/2021 11:29:34 AM (4 years ago)
- Location:
- branches/4.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
- Property svn:mergeinfo changed
/trunk merged: 43511-43512,46682,46996
- Property svn:mergeinfo changed
-
branches/4.7/tests/phpunit/tests/http/base.php
r39174 r50088 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) ); 127 128 $this->skipTestOnTimeout( $res ); 134 129 $this->assertWPError( $res ); 135 130 } … … 138 133 // 6 > 5 (close edgecase) 139 134 $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) ); 135 136 $this->skipTestOnTimeout( $res ); 140 137 $this->assertWPError( $res ); 141 138 } … … 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'] ) ); … … 278 281 279 282 $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) ); 283 284 $this->skipTestOnTimeout( $res ); 280 285 $this->assertEquals( $method, wp_remote_retrieve_body( $res ) ); 281 286 } … … 323 328 324 329 $res = wp_remote_get( $url, $args ); 330 331 $this->skipTestOnTimeout( $res ); 325 332 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 326 333 … … 344 351 remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) ); 345 352 353 $this->skipTestOnTimeout( $res ); 346 354 $this->assertNotEmpty( $this->http_request_args['sslcertificates'] ); 347 355 $this->assertNotWPError( $res ); … … 357 365 $res = wp_remote_head( $url, array( 'timeout' => 30 ) ); 358 366 367 $this->skipTestOnTimeout( $res ); 359 368 $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) ); 360 369 $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) ); 361 370 362 371 $res = wp_remote_get( $url, array( 'timeout' => 30 ) ); 372 373 $this->skipTestOnTimeout( $res ); 363 374 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 364 375 … … 374 385 375 386 $res = wp_remote_get( $url ); 387 388 $this->skipTestOnTimeout( $res ); 376 389 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 377 390 } … … 388 401 389 402 $res = wp_remote_get( 'https://wordpress.org/' ); 403 404 $this->skipTestOnTimeout( $res ); 390 405 $this->assertNotWPError( $res ); 391 406 } … … 401 416 402 417 $res = wp_remote_request( $url ); 418 419 $this->skipTestOnTimeout( $res ); 403 420 $this->assertNotWPError( $res ); 404 421 }
Note: See TracChangeset
for help on using the changeset viewer.