Changeset 43512
- Timestamp:
- 07/19/2018 07:52:41 PM (6 years ago)
- Location:
- trunk/tests/phpunit/tests/http
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/http/base.php
r43511 r43512 19 19 20 20 /** 21 * Mark test as skipped if the HTTP request times out 21 * Mark test as skipped if the HTTP request times out. 22 22 */ 23 23 function skipTestOnTimeout( $response ) { -
trunk/tests/phpunit/tests/http/functions.php
r42343 r43512 6 6 */ 7 7 class Tests_HTTP_Functions extends WP_UnitTestCase { 8 9 /** 10 * Mark test as skipped if the HTTP request times out. 11 */ 12 function skipTestOnTimeout( $response ) { 13 if ( ! is_wp_error( $response ) ) { 14 return; 15 } 16 if ( 'connect() timed out!' === $response->get_error_message() ) { 17 $this->markTestSkipped( 'HTTP timeout' ); 18 } 19 20 if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) { 21 $this->markTestSkipped( 'HTTP timeout' ); 22 } 23 24 if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) { 25 $this->markTestSkipped( 'HTTP timeout' ); 26 } 27 28 } 29 8 30 public function setUp() { 9 31 if ( ! extension_loaded( 'openssl' ) ) { … … 18 40 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; 19 41 $response = wp_remote_head( $url ); 20 $headers = wp_remote_retrieve_headers( $response ); 42 43 $this->skipTestOnTimeout( $response ); 44 45 $headers = wp_remote_retrieve_headers( $response ); 21 46 22 47 $this->assertInternalType( 'array', $response ); … … 31 56 $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; 32 57 $response = wp_remote_head( $url ); 58 59 $this->skipTestOnTimeout( $response ); 33 60 $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) ); 34 61 } 35 62 36 63 function test_head_404() { 37 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; 38 $headers = wp_remote_head( $url ); 39 40 $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) ); 64 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; 65 $response = wp_remote_head( $url ); 66 67 $this->skipTestOnTimeout( $response ); 68 $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) ); 41 69 } 42 70 … … 45 73 46 74 $response = wp_remote_get( $url ); 47 $headers = wp_remote_retrieve_headers( $response ); 75 76 $this->skipTestOnTimeout( $response ); 77 78 $headers = wp_remote_retrieve_headers( $response ); 48 79 49 80 $this->assertInternalType( 'array', $response ); … … 60 91 61 92 $response = wp_remote_get( $url ); 62 $headers = wp_remote_retrieve_headers( $response ); 93 94 $this->skipTestOnTimeout( $response ); 95 96 $headers = wp_remote_retrieve_headers( $response ); 63 97 64 98 // should return the same headers as a head request … … 74 108 // pretend we've already redirected 5 times 75 109 $response = wp_remote_get( $url, array( 'redirection' => -1 ) ); 110 111 $this->skipTestOnTimeout( $response ); 76 112 $this->assertWPError( $response ); 77 113 } … … 84 120 85 121 $response = wp_remote_head( $url ); 86 $cookies = wp_remote_retrieve_cookies( $response ); 122 123 $this->skipTestOnTimeout( $response ); 124 125 $cookies = wp_remote_retrieve_cookies( $response ); 87 126 88 127 $this->assertNotEmpty( $cookies ); … … 121 160 ) 122 161 ); 123 $cookies = wp_remote_retrieve_cookies( $response ); 162 163 $this->skipTestOnTimeout( $response ); 164 165 $cookies = wp_remote_retrieve_cookies( $response ); 124 166 125 167 $this->assertNotEmpty( $cookies ); … … 144 186 ) 145 187 ); 146 $cookies = wp_remote_retrieve_cookies( $response ); 188 189 $this->skipTestOnTimeout( $response ); 190 191 $cookies = wp_remote_retrieve_cookies( $response ); 147 192 148 193 $this->assertNotEmpty( $cookies );
Note: See TracChangeset
for help on using the changeset viewer.