Make WordPress Core

Changeset 43696 for branches/5.0


Ignore:
Timestamp:
10/11/2018 03:19:47 AM (6 years ago)
Author:
SergeyBiryukov
Message:

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

Merges [43512] to the 5.0 branch.
Fixes #44613.

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  
    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 ) {
  • branches/5.0/tests/phpunit/tests/http/functions.php

    r41279 r43696  
    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 );
     42
     43        $this->skipTestOnTimeout( $response );
     44
    2045        $headers = wp_remote_retrieve_headers( $response );
    2146
     
    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 );
     64        $url      = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     65        $response = wp_remote_head( $url );
    3966
    40         $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
     67        $this->skipTestOnTimeout( $response );
     68        $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
    4169    }
    4270
     
    4573
    4674        $response = wp_remote_get( $url );
     75
     76        $this->skipTestOnTimeout( $response );
     77
    4778        $headers = wp_remote_retrieve_headers( $response );
    4879
     
    6091
    6192        $response = wp_remote_get( $url );
     93
     94        $this->skipTestOnTimeout( $response );
     95
    6296        $headers = wp_remote_retrieve_headers( $response );
    6397
     
    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 );
     
    114153            ),
    115154        ) );
    116         $cookies  = wp_remote_retrieve_cookies( $response );
     155
     156        $this->skipTestOnTimeout( $response );
     157
     158        $cookies = wp_remote_retrieve_cookies( $response );
    117159
    118160        $this->assertNotEmpty( $cookies );
     
    135177            ),
    136178        ) );
    137         $cookies  = wp_remote_retrieve_cookies( $response );
     179
     180        $this->skipTestOnTimeout( $response );
     181
     182        $cookies = wp_remote_retrieve_cookies( $response );
    138183
    139184        $this->assertNotEmpty( $cookies );
Note: See TracChangeset for help on using the changeset viewer.