Changeset 50106 for branches/3.9/tests/phpunit/tests/http/base.php
- Timestamp:
- 01/30/2021 09:28:27 PM (4 years ago)
- Location:
- branches/3.9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.9
- Property svn:mergeinfo changed
/trunk merged: 38757,43511-43512,46682,46996
- Property svn:mergeinfo changed
-
branches/3.9/tests/phpunit/tests/http/base.php
r47329 r50106 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 … … 185 212 $res = wp_remote_request( $url, array( 'stream' => true, 'timeout' => 30 ) ); //Auto generate the filename. 186 213 214 // Cleanup before we assert, as it'll return early. 215 if ( ! is_wp_error( $res ) ) { 216 $filesize = filesize( $res['filename'] ); 217 unlink( $res['filename'] ); 218 } 219 220 $this->skipTestOnTimeout( $res ); 187 221 $this->assertFalse( is_wp_error( $res ) ); 188 222 $this->assertEquals( '', $res['body'] ); // The body should be empty. 189 223 $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..) 190 $this->assertEquals( $size, filesize($res['filename']) ); // Check that the file is written to disk correctly without any extra characters 191 192 unlink($res['filename']); // Remove the temporary file 224 $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters 193 225 } 194 226 … … 196 228 * Test POST redirection methods 197 229 * 230 * @dataProvider data_post_redirect_to_method_300 231 * 198 232 * @ticket 17588 199 233 */ 200 function test_post_redirect_to_method_300( ) {234 function test_post_redirect_to_method_300( $response_code, $method ) { 201 235 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1'; 202 236 203 // Test 300 - POST to POST 204 $res = wp_remote_post( add_query_arg( 'response_code', 300, $url ), array( 'timeout' => 30 ) ); 205 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 206 207 // Test 301 - POST to POST 208 $res = wp_remote_post( add_query_arg( 'response_code', 301, $url ), array( 'timeout' => 30 ) ); 209 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 210 211 // Test 302 - POST to GET 212 $res = wp_remote_post( add_query_arg( 'response_code', 302, $url ), array( 'timeout' => 30 ) ); 213 $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 214 215 // Test 303 - POST to GET 216 $res = wp_remote_post( add_query_arg( 'response_code', 303, $url ), array( 'timeout' => 30 ) ); 217 $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) ); 218 219 // Test 304 - POST to POST 220 $res = wp_remote_post( add_query_arg( 'response_code', 304, $url ), array( 'timeout' => 30 ) ); 221 $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) ); 237 $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) ); 238 239 $this->skipTestOnTimeout( $res ); 240 $this->assertEquals( $method, wp_remote_retrieve_body( $res ) ); 241 } 242 243 public function data_post_redirect_to_method_300() { 244 return array( 245 // Test 300 - POST to POST 246 array( 247 300, 248 'POST', 249 ), 250 // Test 301 - POST to POST 251 array( 252 301, 253 'POST', 254 ), 255 // Test 302 - POST to GET 256 array( 257 302, 258 'GET', 259 ), 260 // Test 303 - POST to GET 261 array( 262 303, 263 'GET', 264 ), 265 // Test 304 - POST to POST 266 array( 267 304, 268 'POST', 269 ), 270 ); 222 271 } 223 272 … … 239 288 240 289 $res = wp_remote_get( $url, $args ); 290 291 $this->skipTestOnTimeout( $res ); 241 292 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 242 293 … … 252 303 $res = wp_remote_head( $url, array( 'timeout' => 30 ) ); 253 304 305 $this->skipTestOnTimeout( $res ); 254 306 $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) ); 255 307 $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) ); 256 308 257 309 $res = wp_remote_get( $url, array( 'timeout' => 30 ) ); 310 311 $this->skipTestOnTimeout( $res ); 258 312 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 259 313 … … 269 323 270 324 $res = wp_remote_get( $url ); 325 326 $this->skipTestOnTimeout( $res ); 271 327 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 272 328 } … … 283 339 284 340 $res = wp_remote_get( 'https://wordpress.org/' ); 341 342 $this->skipTestOnTimeout( $res ); 285 343 $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) ); 286 344 }
Note: See TracChangeset
for help on using the changeset viewer.