Skip to content

Commit

Permalink
Tests: Use assertSame() in wp_validate_redirect() tests.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SergeyBiryukov committed May 1, 2024
1 parent 2f2dbbf commit ebc66bb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/phpunit/tests/formatting/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ebc66bb

Please sign in to comment.