Changeset 50101 for branches/4.3/tests/phpunit/tests/http/functions.php
- Timestamp:
- 01/30/2021 08:45:47 PM (4 years ago)
- Location:
- branches/4.3
- Files:
-
- 2 edited
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/functions.php
r31258 r50101 18 18 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; 19 19 $response = wp_remote_head( $url ); 20 21 $this->skipTestOnTimeout( $response ); 22 20 23 $headers = wp_remote_retrieve_headers( $response ); 21 24 … … 30 33 $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; 31 34 $response = wp_remote_head( $url ); 35 36 $this->skipTestOnTimeout( $response ); 32 37 $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) ); 33 38 } … … 35 40 function test_head_404() { 36 41 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; 37 $ headers= wp_remote_head( $url );42 $response = wp_remote_head( $url ); 38 43 39 $this->assertInternalType( 'array', $headers, "Reply wasn't array." ); 40 $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) ); 44 $this->skipTestOnTimeout( $response ); 45 $this->assertInternalType( 'array', $response, "Reply wasn't array." ); 46 $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) ); 41 47 } 42 48 43 49 function test_get_request() { 44 50 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; 45 $file = tempnam('/tmp', 'testfile');46 51 47 $headers = wp_get_http($url, $file); 52 $response = wp_remote_get( $url ); 53 54 $this->skipTestOnTimeout( $response ); 55 56 $headers = wp_remote_retrieve_headers( $response ); 48 57 49 58 // should return the same headers as a head request … … 51 60 $this->assertEquals( 'image/jpeg', $headers['content-type'] ); 52 61 $this->assertEquals( '40148', $headers['content-length'] ); 53 $this->assertEquals( '200', $headers['response'] ); 54 55 // make sure the file is ok 56 $this->assertEquals( 40148, filesize($file) ); 57 $this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) ); 62 $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) ); 58 63 } 59 64 … … 61 66 // this will redirect to asdftestblog1.files.wordpress.com 62 67 $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; 63 $file = tempnam('/tmp', 'testfile');64 68 65 $headers = wp_get_http($url, $file); 69 $response = wp_remote_get( $url ); 70 71 $this->skipTestOnTimeout( $response ); 72 73 $headers = wp_remote_retrieve_headers( $response ); 66 74 67 75 // should return the same headers as a head request … … 69 77 $this->assertEquals( 'image/jpeg', $headers['content-type'] ); 70 78 $this->assertEquals( '40148', $headers['content-length'] ); 71 $this->assertEquals( '200', $headers['response'] ); 72 73 // make sure the file is ok 74 $this->assertEquals( 40148, filesize($file) ); 75 $this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) ); 79 $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) ); 76 80 } 77 81 … … 79 83 // this will redirect to asdftestblog1.files.wordpress.com 80 84 $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; 81 $file = tempnam('/tmp', 'testfile'); 85 82 86 // pretend we've already redirected 5 times 83 $headers = wp_get_http( $url, $file, 6 ); 84 $this->assertFalse( $headers ); 87 $response = wp_remote_get( $url, array( 'redirection' => -1 ) ); 88 89 $this->skipTestOnTimeout( $response ); 90 $this->assertTrue( is_wp_error( $response ) ); 85 91 } 86 92 }
Note: See TracChangeset
for help on using the changeset viewer.