WordPress.org

Make WordPress Core

Changeset 50105


Ignore:
Timestamp:
01/30/2021 09:24:12 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Tests: Reorder WP_UnitTestCase methods for consistency with other branches.

Follow-up to [45013], [50104].

See #51669.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0/tests/phpunit/includes/testcase.php

    r50104 r50105  
    5555    }
    5656
    57     /**
    58      * Allow tests to be skipped if the HTTP request times out.
    59      *
    60      * @param array|WP_Error $response HTTP response.
    61      */
    62     public function skipTestOnTimeout( $response ) {
    63         if ( ! is_wp_error( $response ) ) {
    64             return;
    65         }
    66         if ( 'connect() timed out!' === $response->get_error_message() ) {
    67             $this->markTestSkipped( 'HTTP timeout' );
    68         }
    69 
    70         if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    71             $this->markTestSkipped( 'HTTP timeout' );
    72         }
    73 
    74         if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
    75             $this->markTestSkipped( 'HTTP timeout' );
    76         }
    77 
    78     }
    79 
    80     /**
    81      * Unregister existing post types and register defaults.
    82      *
    83      * Run before each test in order to clean up the global scope, in case
    84      * a test forgets to unregister a post type on its own, or fails before
    85      * it has a chance to do so.
    86      */
    87     protected function reset_post_types() {
    88         foreach ( get_post_types() as $pt ) {
    89             _unregister_post_type( $pt );
    90         }
    91         create_initial_post_types();
    92     }
    93 
    94     /**
    95      * Unregister existing taxonomies and register defaults.
    96      *
    97      * Run before each test in order to clean up the global scope, in case
    98      * a test forgets to unregister a taxonomy on its own, or fails before
    99      * it has a chance to do so.
    100      */
    101     protected function reset_taxonomies() {
    102         foreach ( get_taxonomies() as $tax ) {
    103             _unregister_taxonomy( $tax );
    104         }
    105         create_initial_taxonomies();
    106     }
    107 
    10857    function tearDown() {
    10958        global $wpdb, $wp_query, $post;
     
    15099            $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
    151100        }
     101    }
     102
     103    /**
     104     * Allow tests to be skipped if the HTTP request times out.
     105     *
     106     * @param array|WP_Error $response HTTP response.
     107     */
     108    public function skipTestOnTimeout( $response ) {
     109        if ( ! is_wp_error( $response ) ) {
     110            return;
     111        }
     112        if ( 'connect() timed out!' === $response->get_error_message() ) {
     113            $this->markTestSkipped( 'HTTP timeout' );
     114        }
     115
     116        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     117            $this->markTestSkipped( 'HTTP timeout' );
     118        }
     119
     120        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     121            $this->markTestSkipped( 'HTTP timeout' );
     122        }
     123
     124    }
     125
     126    /**
     127     * Unregister existing post types and register defaults.
     128     *
     129     * Run before each test in order to clean up the global scope, in case
     130     * a test forgets to unregister a post type on its own, or fails before
     131     * it has a chance to do so.
     132     */
     133    protected function reset_post_types() {
     134        foreach ( get_post_types() as $pt ) {
     135            _unregister_post_type( $pt );
     136        }
     137        create_initial_post_types();
     138    }
     139
     140    /**
     141     * Unregister existing taxonomies and register defaults.
     142     *
     143     * Run before each test in order to clean up the global scope, in case
     144     * a test forgets to unregister a taxonomy on its own, or fails before
     145     * it has a chance to do so.
     146     */
     147    protected function reset_taxonomies() {
     148        foreach ( get_taxonomies() as $tax ) {
     149            _unregister_taxonomy( $tax );
     150        }
     151        create_initial_taxonomies();
    152152    }
    153153
Note: See TracChangeset for help on using the changeset viewer.