Skip to content

Commit bcbd85d

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 c36572d commit bcbd85d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/phpunit/tests/admin/includesFile.php

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

0 commit comments

Comments
 (0)