Skip to content

Commit ebc66bb

Browse files
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
1 parent 2f2dbbf commit ebc66bb

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

tests/phpunit/tests/formatting/redirect.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function test_wp_sanitize_redirect_should_encode_spaces() {
7676
* @dataProvider data_wp_validate_redirect_valid_url
7777
*
7878
* @covers ::wp_validate_redirect
79+
*
80+
* @param string $url Redirect requested.
81+
* @param string $expected Expected destination.
7982
*/
8083
public function test_wp_validate_redirect_valid_url( $url, $expected ) {
8184
$this->assertSame( $expected, wp_validate_redirect( $url ) );
@@ -101,15 +104,18 @@ public function data_wp_validate_redirect_valid_url() {
101104
* @dataProvider data_wp_validate_redirect_invalid_url
102105
*
103106
* @covers ::wp_validate_redirect
107+
*
108+
* @param string $url Redirect requested.
109+
* @param string|false $expected Optional. Expected destination. Default false.
104110
*/
105-
public function test_wp_validate_redirect_invalid_url( $url ) {
106-
$this->assertEquals( false, wp_validate_redirect( $url, false ) );
111+
public function test_wp_validate_redirect_invalid_url( $url, $expected = false ) {
112+
$this->assertSame( $expected, wp_validate_redirect( $url, false ) );
107113
}
108114

109115
public function data_wp_validate_redirect_invalid_url() {
110116
return array(
111117
// parse_url() fails.
112-
array( '' ),
118+
array( '', '' ),
113119
array( 'http://:' ),
114120

115121
// Non-safelisted domain.
@@ -179,6 +185,10 @@ public function data_wp_validate_redirect_invalid_url() {
179185
* @dataProvider data_wp_validate_redirect_relative_url
180186
*
181187
* @covers ::wp_validate_redirect
188+
*
189+
* @param string $current_uri Current URI (i.e. path and query string only).
190+
* @param string $url Redirect requested.
191+
* @param string $expected Expected destination.
182192
*/
183193
public function test_wp_validate_redirect_relative_url( $current_uri, $url, $expected ) {
184194
// Backup the global.

0 commit comments

Comments
 (0)