Changeset 50101 for branches/4.3/tests/phpunit/tests/http/base.php
- Timestamp:
- 01/30/2021 08:45:47 PM (5 years ago)
- Location:
- branches/4.3
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tests/phpunit/tests/http/base.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.3
- Property svn:mergeinfo changed
/trunk merged: 38757,43511-43512,46682,46996
- Property svn:mergeinfo changed
-
branches/4.3/tests/phpunit/tests/http/base.php
r32712 r50101 45 45 // 5 : 5 & 301 46 46 $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) ); 47 48 $this->skipTestOnTimeout( $res ); 47 49 $this->assertFalse( is_wp_error($res) ); 48 50 $this->assertEquals(200, (int)$res['response']['code'] ); … … 52 54 // 5 : 5 & 302 53 55 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) ); 56 57 $this->skipTestOnTimeout( $res ); 54 58 $this->assertFalse( is_wp_error($res) ); 55 59 $this->assertEquals(200, (int)$res['response']['code'] ); … … 62 66 // 5 > 0 & 301 63 67 $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) ); 68 69 $this->skipTestOnTimeout( $res ); 64 70 $this->assertFalse( is_wp_error($res) ); 65 71 $this->assertEquals(301, (int)$res['response']['code'] ); … … 72 78 // 5 > 0 & 302 73 79 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) ); 80 81 $this->skipTestOnTimeout( $res ); 74 82 $this->assertFalse( is_wp_error($res) ); 75 83 $this->assertEquals(302, (int)$res['response']['code'] ); … … 79 87 // 5 - 5 80 88 $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) ); 89 90 $this->skipTestOnTimeout( $res ); 81 91 $this->assertFalse( is_wp_error($res) ); 82 92 $this->assertEquals(200, (int)$res['response']['code'] ); … … 86 96 // No redirections on HEAD request: 87 97 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') ); 98 99 $this->skipTestOnTimeout( $res ); 88 100 $this->assertFalse( is_wp_error($res) ); 89 101 $this->assertEquals( 302, (int)$res['response']['code'] ); … … 96 108 // Redirections on HEAD request when Requested 97 109 $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') ); 110 111 $this->skipTestOnTimeout( $res ); 98 112 $this->assertFalse( is_wp_error($res) ); 99 113 $this->assertEquals( 200, (int)$res['response']['code'] ); … … 103 117 // 10 > 5 104 118 $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) ); 119 120 $this->skipTestOnTimeout( $res ); 105 121 $this->assertTrue( is_wp_error($res), print_r($res, true) ); 106 122 } … … 109 125 // 6 > 5 (close edgecase) 110 126 $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) ); 127 128 $this->skipTestOnTimeout( $res ); 111 129 $this->assertTrue( is_wp_error($res) ); 112 130 } … … 115 133 // 4 < 5 (close edgecase) 116 134 $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) ); 135 136 $this->skipTestOnTimeout( $res ); 117 137 $this->assertFalse( is_wp_error($res) ); 118 138 } … … 124 144 // 0 redirections asked for, Should return the document? 125 145 $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) ); 146 147 $this->skipTestOnTimeout( $res ); 126 148 $this->assertFalse( is_wp_error($res) ); 127 149 $this->assertEquals( 302, (int)$res['response']['code'] ); … … 136 158 // Prints PASS on initial load, FAIL if the client follows the specified redirection 137 159 $res = wp_remote_request( $this->redirection_script . '?201-location=true' ); 160 161 $this->skipTestOnTimeout( $res ); 138 162 $this->assertFalse( is_wp_error( $res ) ); 139 163 $this->assertEquals( 'PASS', $res['body']); … … 150 174 // Test 301 - POST to POST 151 175 $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) ); 176 177 $this->skipTestOnTimeout( $res ); 152 178 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 153 179 $this->assertTrue( !empty( $res['headers']['location'] ) ); … … 162 188 $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) ); 163 189 190 $this->skipTestOnTimeout( $res ); 164 191 $this->assertFalse( is_wp_error($res) ); 165 192 … … 191 218 } 192 219 220 $this->skipTestOnTimeout( $res ); 193 221 $this->assertFalse( is_wp_error( $res ) ); 194 222 $this->assertEquals( '', $res['body'] ); // The body should be empty. … … 212 240 } 213 241 242 $this->skipTestOnTimeout( $res ); 214 243 $this->assertFalse( is_wp_error( $res ) ); 215 244 $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters … … 229 258 $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) ); 230 259 260 $this->skipTestOnTimeout( $res ); 231 261 $this->assertFalse( is_wp_error( $res ) ); 232 262 $this->assertEquals( $size, strlen( $res['body'] ) ); … … 236 266 * Test POST redirection methods 237 267 * 268 * @dataProvider data_post_redirect_to_method_300 269 * 238 270 * @ticket 17588 239 271 */ 240 function test_post_redirect_to_method_300( ) {272 function test_post_redirect_to_method_300( $response_code, $method ) { 241 273 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1'; 242 274 243 // Test 300 - POST to POST 244 $res = wp_remote_post( add_query_arg( 'response_code', 300, $url ), array( 'timeout' => 30 ) ); 245 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 246 247 // Test 301 - POST to POST 248 $res = wp_remote_post( add_query_arg( 'response_code', 301, $url ), array( 'timeout' => 30 ) ); 249 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 250 251 // Test 302 - POST to GET 252 $res = wp_remote_post( add_query_arg( 'response_code', 302, $url ), array( 'timeout' => 30 ) ); 253 $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 254 255 // Test 303 - POST to GET 256 $res = wp_remote_post( add_query_arg( 'response_code', 303, $url ), array( 'timeout' => 30 ) ); 257 $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 258 259 // Test 304 - POST to POST 260 $res = wp_remote_post( add_query_arg( 'response_code', 304, $url ), array( 'timeout' => 30 ) ); 261 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 275 $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) ); 276 277 $this->skipTestOnTimeout( $res ); 278 $this->assertEquals( $method, wp_remote_retrieve_body( $res ) ); 279 } 280 281 public function data_post_redirect_to_method_300() { 282 return array( 283 // Test 300 - POST to POST 284 array( 285 300, 286 'POST', 287 ), 288 // Test 301 - POST to POST 289 array( 290 301, 291 'POST', 292 ), 293 // Test 302 - POST to GET 294 array( 295 302, 296 'GET', 297 ), 298 // Test 303 - POST to GET 299 array( 300 303, 301 'GET', 302 ), 303 // Test 304 - POST to POST 304 array( 305 304, 306 'POST', 307 ), 308 ); 262 309 } 263 310 … … 279 326 280 327 $res = wp_remote_get( $url, $args ); 328 329 $this->skipTestOnTimeout( $res ); 281 330 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 282 331 … … 292 341 $res = wp_remote_head( $url, array( 'timeout' => 30 ) ); 293 342 343 $this->skipTestOnTimeout( $res ); 294 344 $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) ); 295 345 $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) ); 296 346 297 347 $res = wp_remote_get( $url, array( 'timeout' => 30 ) ); 348 349 $this->skipTestOnTimeout( $res ); 298 350 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 299 351 … … 309 361 310 362 $res = wp_remote_get( $url ); 363 364 $this->skipTestOnTimeout( $res ); 311 365 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 312 366 } … … 323 377 324 378 $res = wp_remote_get( 'https://wordpress.org/' ); 379 380 $this->skipTestOnTimeout( $res ); 325 381 $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) ); 326 382 }
Note: See TracChangeset
for help on using the changeset viewer.