From ebc66bb9a13180d85f5a8b374d85ce14e0b7b2db Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 1 May 2024 18:54:36 +0000 Subject: [PATCH] Tests: Use `assertSame()` in `wp_validate_redirect()` tests. This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Follow-up to [36444]. Props costdev. See #60706. git-svn-id: https://develop.svn.wordpress.org/trunk@58070 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/formatting/redirect.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/formatting/redirect.php b/tests/phpunit/tests/formatting/redirect.php index 4fdcf0f62175b..c4b1d682094f4 100644 --- a/tests/phpunit/tests/formatting/redirect.php +++ b/tests/phpunit/tests/formatting/redirect.php @@ -76,6 +76,9 @@ public function test_wp_sanitize_redirect_should_encode_spaces() { * @dataProvider data_wp_validate_redirect_valid_url * * @covers ::wp_validate_redirect + * + * @param string $url Redirect requested. + * @param string $expected Expected destination. */ public function test_wp_validate_redirect_valid_url( $url, $expected ) { $this->assertSame( $expected, wp_validate_redirect( $url ) ); @@ -101,15 +104,18 @@ public function data_wp_validate_redirect_valid_url() { * @dataProvider data_wp_validate_redirect_invalid_url * * @covers ::wp_validate_redirect + * + * @param string $url Redirect requested. + * @param string|false $expected Optional. Expected destination. Default false. */ - public function test_wp_validate_redirect_invalid_url( $url ) { - $this->assertEquals( false, wp_validate_redirect( $url, false ) ); + public function test_wp_validate_redirect_invalid_url( $url, $expected = false ) { + $this->assertSame( $expected, wp_validate_redirect( $url, false ) ); } public function data_wp_validate_redirect_invalid_url() { return array( // parse_url() fails. - array( '' ), + array( '', '' ), array( 'http://:' ), // Non-safelisted domain. @@ -179,6 +185,10 @@ public function data_wp_validate_redirect_invalid_url() { * @dataProvider data_wp_validate_redirect_relative_url * * @covers ::wp_validate_redirect + * + * @param string $current_uri Current URI (i.e. path and query string only). + * @param string $url Redirect requested. + * @param string $expected Expected destination. */ public function test_wp_validate_redirect_relative_url( $current_uri, $url, $expected ) { // Backup the global.