wordpress-develop/tests/phpunit/tests/admin
Sergey Biryukov 5f5895bf61 Code Modernization: Check the return type of parse_url() in download_url().
As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

This commit adds three unit tests for `download_url()`:

* The first test is "girl-scouting" to make sure that the code up to the point where the error is expected is tested.
* The second test exposed a PHP 8.1 `basename(): Passing null to parameter #1 ($path) of type string is deprecated` error due to the call to `parse_url()` returning `null` when the component requested does not exist in the passed URL.
* The output of the call to `parse_url()` stored in the `$url_path` variable is used in more places in the function logic. The third test exposes a second PHP 8.1 deprecation notice, this time for `substr(): Passing null to parameter #1 ($string) of type string is deprecated`.

This commit also removes duplicate `parse_url()` calls. Neither `$url` nor `$url_filename` are changed between when they are first received/defined and when they are re-used, so there is no need to repeat the function calls.

Follow-up to [51606], [51622].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51626 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-17 00:14:20 +00:00
..
includesComment.php Build/Test Tools: Standardise the name, signature, and usage of the wpSetUpBeforeClass() method that's used in test classes. 2020-11-15 13:59:32 +00:00
includesCommunityEvents.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
includesFile.php Code Modernization: Check the return type of parse_url() in download_url(). 2021-08-17 00:14:20 +00:00
includesListTable.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
includesMisc.php Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests. 2020-09-02 00:35:36 +00:00
includesPlugin.php Tests: Replace assertFileNotExists() with assertFileDoesNotExist(). 2021-08-06 21:45:32 +00:00
includesPost.php Tests: Replace assertContains() with assertStringContainsString() when used with strings. 2021-07-19 14:00:11 +00:00
includesSchema.php Build/Test Tools: Standardise the name, signature, and usage of the wpSetUpBeforeClass() method that's used in test classes. 2020-11-15 13:59:32 +00:00
includesScreen.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
includesTemplate.php Tests: Replace assertContains() with assertStringContainsString() when used with strings. 2021-07-19 14:00:11 +00:00
includesTheme.php Build/Test Tools: Implement use of the void solution. 2021-08-07 10:29:41 +00:00
includesUser.php REST API: Introduce Application Passwords for API authentication. 2020-10-08 22:12:02 +00:00
wpPrivacyRequestsTable.php Tests: Replace assertContains() with assertStringContainsString() when used with strings. 2021-07-19 14:00:11 +00:00