From c231bb4869869a9903e2d5378d620a3190c87116 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 4 Nov 2019 12:57:17 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@46649 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 2 +- tests/phpunit/tests/formatting/redirect.php | 25 +++++++++++++++++++++ tests/phpunit/tests/pluggable.php | 24 -------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index fb44dc35d5..3b81242f4d 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1251,7 +1251,7 @@ if ( ! function_exists( 'wp_redirect' ) ) : return false; } - if ( 300 > $status || 399 < $status ) { + if ( $status < 300 || 399 < $status ) { wp_die( __( 'HTTP redirect status code must be a redirection code, 3xx.' ) ); } diff --git a/tests/phpunit/tests/formatting/redirect.php b/tests/phpunit/tests/formatting/redirect.php index df69d8470f..ff897b094c 100644 --- a/tests/phpunit/tests/formatting/redirect.php +++ b/tests/phpunit/tests/formatting/redirect.php @@ -20,6 +20,31 @@ class Tests_Formatting_Redirect extends WP_UnitTestCase { return 'http://example.com/'; } + /** + * @ticket 44317 + * + * @dataProvider get_bad_status_codes + * @expectedException WPDieException + * + * @param string $location The path or URL to redirect to. + * @param int $status HTTP response status code to use. + */ + public function test_wp_redirect_bad_status_code( $location, $status ) { + wp_redirect( $location, $status ); + } + + public function get_bad_status_codes() { + return array( + // Tests for bad arguments + array( '/wp-admin', 404 ), + array( '/wp-admin', 410 ), + array( '/wp-admin', 500 ), + // Tests for condition. + array( '/wp-admin', 299 ), + array( '/wp-admin', 400 ), + ); + } + function test_wp_sanitize_redirect() { $this->assertEquals( 'http://example.com/watchthelinefeedgo', wp_sanitize_redirect( 'http://example.com/watchthelinefeed%0Ago' ) ); $this->assertEquals( 'http://example.com/watchthelinefeedgo', wp_sanitize_redirect( 'http://example.com/watchthelinefeed%0ago' ) ); diff --git a/tests/phpunit/tests/pluggable.php b/tests/phpunit/tests/pluggable.php index 26a15c0bbc..fd97a2dd77 100644 --- a/tests/phpunit/tests/pluggable.php +++ b/tests/phpunit/tests/pluggable.php @@ -5,30 +5,6 @@ */ class Tests_Pluggable extends WP_UnitTestCase { - /** - * @expectedException WPDieException - * @dataProvider get_bad_status_codes - * - * @ticket 44317 - * @param string $location The path or URL to redirect to. - * @param int $status HTTP response status code to use. - */ - public function test_wp_redirect_bad_status_code( $location, $status ) { - wp_redirect( $location, $status ); - } - - public function get_bad_status_codes() { - return [ - // Tests for bad arguments - [ '/wp-admin', 404 ], - [ '/wp-admin', 410 ], - [ '/wp-admin', 500 ], - // Tests for condition. - [ '/wp-admin', 299 ], - [ '/wp-admin', 400 ], - ]; - } - /** * Tests that the signatures of all functions in pluggable.php match their expected signature. *