Changeset 43696
- Timestamp:
- 10/11/2018 03:19:47 AM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0
-
branches/5.0/tests/phpunit/tests/http/base.php
r43695 r43696 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 ) { -
branches/5.0/tests/phpunit/tests/http/functions.php
r41279 r43696 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 ); 42 43 $this->skipTestOnTimeout( $response ); 44 20 45 $headers = wp_remote_retrieve_headers( $response ); 21 46 … … 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 );64 $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; 65 $response = wp_remote_head( $url ); 39 66 40 $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) ); 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 ); 75 76 $this->skipTestOnTimeout( $response ); 77 47 78 $headers = wp_remote_retrieve_headers( $response ); 48 79 … … 60 91 61 92 $response = wp_remote_get( $url ); 93 94 $this->skipTestOnTimeout( $response ); 95 62 96 $headers = wp_remote_retrieve_headers( $response ); 63 97 … … 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 ); … … 114 153 ), 115 154 ) ); 116 $cookies = wp_remote_retrieve_cookies( $response ); 155 156 $this->skipTestOnTimeout( $response ); 157 158 $cookies = wp_remote_retrieve_cookies( $response ); 117 159 118 160 $this->assertNotEmpty( $cookies ); … … 135 177 ), 136 178 ) ); 137 $cookies = wp_remote_retrieve_cookies( $response ); 179 180 $this->skipTestOnTimeout( $response ); 181 182 $cookies = wp_remote_retrieve_cookies( $response ); 138 183 139 184 $this->assertNotEmpty( $cookies );
Note: See TracChangeset
for help on using the changeset viewer.