Skip to content

Commit ed6101b

Browse files
committed
Tests_Admin_includesFile: add yet another test for the download_url() function
The output of the call to `parse_url()` stored in the `$url_path` variable is used in more places in the function logic. This test exposes a second PHP 8.1 deprecation notice, this time for `substr(): Passing null to parameter #1 ($string) of type string is deprecated`.
1 parent b86da2d commit ed6101b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/phpunit/tests/admin/includesFile.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,35 @@ public function test_download_url_no_warning_with_url_without_path() {
123123
$this->assertIsString( $result );
124124
$this->assertNotEmpty( $result ); // File path will be generated, but will never be empty.
125125
}
126+
127+
/**
128+
* Verify that no "passing null to non-nullable" error is thrown on PHP 8.1,
129+
* when the $url does not have a path component and signature verification
130+
* via a local file is requested.
131+
*
132+
* @covers ::download_url
133+
*
134+
* @ticket 53635
135+
*/
136+
public function test_download_url_no_warning_with_url_without_path_with_signature_verification() {
137+
add_filter(
138+
'wp_signature_hosts',
139+
static function( $urls ) {
140+
$urls[] = 'example.com';
141+
return $urls;
142+
}
143+
);
144+
$error = download_url( 'https://example.com', 300, true );
145+
146+
/*
147+
* Note: This test is not testing the signature verification itself.
148+
* There is no signature available for the domain used in the test,
149+
* which is why an error is expected and that's fine.
150+
* The point of the test is to verify that the call to `verify_file_signature()`
151+
* is actually reached and that no PHP deprecation notice is thrown
152+
* before this point.
153+
*/
154+
$this->assertWPError( $error );
155+
$this->assertSame( 'signature_verification_no_signature', $error->get_error_code() );
156+
}
126157
}

0 commit comments

Comments
 (0)