Make WordPress Core

Changeset 46649


Ignore:
Timestamp:
11/04/2019 12:57:17 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Adjust the test for wp_redirect() status codes added in [46641] per the documentation and coding standards.

Move the test to a more appropriate place for consistency with wp_sanitize_redirect() and wp_validate_redirect() tests.

See #44317.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r46641 r46649  
    12521252        }
    12531253
    1254         if ( 300 > $status || 399 < $status ) {
     1254        if ( $status < 300 || 399 < $status ) {
    12551255            wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) );
    12561256        }
  • trunk/tests/phpunit/tests/formatting/redirect.php

    r46586 r46649  
    1919    function home_url() {
    2020        return 'http://example.com/';
     21    }
     22
     23    /**
     24     * @ticket 44317
     25     *
     26     * @dataProvider get_bad_status_codes
     27     * @expectedException WPDieException
     28     *
     29     * @param string $location The path or URL to redirect to.
     30     * @param int    $status   HTTP response status code to use.
     31     */
     32    public function test_wp_redirect_bad_status_code( $location, $status ) {
     33        wp_redirect( $location, $status );
     34    }
     35
     36    public function get_bad_status_codes() {
     37        return array(
     38            // Tests for bad arguments
     39            array( '/wp-admin', 404 ),
     40            array( '/wp-admin', 410 ),
     41            array( '/wp-admin', 500 ),
     42            // Tests for condition.
     43            array( '/wp-admin', 299 ),
     44            array( '/wp-admin', 400 ),
     45        );
    2146    }
    2247
  • trunk/tests/phpunit/tests/pluggable.php

    r46645 r46649  
    55 */
    66class Tests_Pluggable extends WP_UnitTestCase {
    7 
    8     /**
    9      * @expectedException WPDieException
    10      * @dataProvider get_bad_status_codes
    11      *
    12      * @ticket 44317
    13      * @param string $location The path or URL to redirect to.
    14      * @param int $status HTTP response status code to use.
    15      */
    16     public function test_wp_redirect_bad_status_code( $location, $status ) {
    17         wp_redirect( $location, $status );
    18     }
    19 
    20     public function get_bad_status_codes() {
    21         return [
    22             // Tests for bad arguments
    23             [ '/wp-admin', 404 ],
    24             [ '/wp-admin', 410 ],
    25             [ '/wp-admin', 500 ],
    26             // Tests for condition.
    27             [ '/wp-admin', 299 ],
    28             [ '/wp-admin', 400 ],
    29         ];
    30     }
    317
    328    /**
Note: See TracChangeset for help on using the changeset viewer.