Make WordPress Core

Changeset 43512


Ignore:
Timestamp:
07/19/2018 07:52:41 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Tests: Introduce Tests_HTTP_Functions::skipTestOnTimeout(), mirroring the same WP_HTTP_UnitTestCase method.

See #44613.

Location:
trunk/tests/phpunit/tests/http
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/http/base.php

    r43511 r43512  
    1919
    2020        /**
    21          * Mark test as skipped if the HTTP request times out
     21         * Mark test as skipped if the HTTP request times out.
    2222         */
    2323        function skipTestOnTimeout( $response ) {
  • trunk/tests/phpunit/tests/http/functions.php

    r42343 r43512  
    66 */
    77class 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
    830        public function setUp() {
    931                if ( ! extension_loaded( 'openssl' ) ) {
     
    1840                $url      = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
    1941                $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 );
    2146
    2247                $this->assertInternalType( 'array', $response );
     
    3156                $url      = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    3257                $response = wp_remote_head( $url );
     58
     59                $this->skipTestOnTimeout( $response );
    3360                $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
    3461        }
    3562
    3663        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 ) );
    4169        }
    4270
     
    4573
    4674                $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 );
    4879
    4980                $this->assertInternalType( 'array', $response );
     
    6091
    6192                $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 );
    6397
    6498                // should return the same headers as a head request
     
    74108                // pretend we've already redirected 5 times
    75109                $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
     110
     111                $this->skipTestOnTimeout( $response );
    76112                $this->assertWPError( $response );
    77113        }
     
    84120
    85121                $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 );
    87126
    88127                $this->assertNotEmpty( $cookies );
     
    121160                        )
    122161                );
    123                 $cookies  = wp_remote_retrieve_cookies( $response );
     162
     163                $this->skipTestOnTimeout( $response );
     164
     165                $cookies = wp_remote_retrieve_cookies( $response );
    124166
    125167                $this->assertNotEmpty( $cookies );
     
    144186                        )
    145187                );
    146                 $cookies  = wp_remote_retrieve_cookies( $response );
     188
     189                $this->skipTestOnTimeout( $response );
     190
     191                $cookies = wp_remote_retrieve_cookies( $response );
    147192
    148193                $this->assertNotEmpty( $cookies );
Note: See TracChangeset for help on using the changeset viewer.