Repository navigation
Conversation
…unctions. Covers `wp_remote_retrieve_header()`, `wp_remote_retrieve_response_message()`, `allowed_http_request_hosts()` and `ms_allowed_http_request_hosts()`, which had no tests. See #66501.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the added HTTP helper test coverage.
No open issues 🎉
What changed in this PR
Adds PHPUnit coverage for four HTTP helper functions in src/wp-includes/http.php, supporting Trac ticket #66501 without changing production behavior.
Changes:
- Tests response header and message retrieval, including error handling and edge cases.
- Tests single-site and multisite host allowlisting and default filter priorities.
- Verifies multisite query avoidance and per-host query caching.
| File | Description |
|---|---|
tests/phpunit/tests/http/wpRemoteRetrieveResponseMessage.php |
Covers message retrieval and invalid response data. |
tests/phpunit/tests/http/wpRemoteRetrieveHeader.php |
Covers header values, case sensitivity, missing headers, and errors. |
tests/phpunit/tests/http/msAllowedHttpRequestHosts.php |
Covers multisite host rules, query caching, and filter registration. |
tests/phpunit/tests/http/allowedHttpRequestHosts.php |
Covers site and filtered host allowlisting and filter registration. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds unit tests for four functions in
src/wp-includes/http.phpthat were not referenced by any test. No behavior is changed.Functions covered, each in its own test class in
tests/phpunit/tests/http/:wp_remote_retrieve_header()'0'or empty, and an empty string when the header is not set.WpOrg\Requests\Utility\CaseInsensitiveDictionaryin any case, while the name of a header in a plain array is case sensitive.WP_Errorand for a response without headers.wp_remote_retrieve_response_message()WP_Error, for a response without theresponsedata and when it is not an array.allowed_http_request_hosts()allowed_redirect_hostsfilter, and does not allow other hosts.http_request_host_is_externalwith the expected priority.ms_allowed_http_request_hosts()(@group ms-required)send_origin_headers()is not covered, because it callsexit.Testing:
vendor/bin/phpunit --filter 'Tests_HTTP_(WpRemoteRetrieveHeader|WpRemoteRetrieveResponseMessage|AllowedHttpRequestHosts|MsAllowedHttpRequestHosts)'vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_HTTP_(WpRemoteRetrieveHeader|WpRemoteRetrieveResponseMessage|AllowedHttpRequestHosts|MsAllowedHttpRequestHosts)'vendor/bin/phpcs tests/phpunit/tests/http/I also temporarily broke these functions in
src/wp-includes/http.php(lowercasing the header name, dropping falsy values, removing the checks for aWP_Errorand for a response that is not an array, returning the code instead of the message, each of the branches of the two host functions, and the cache of the queried hosts) and confirmed that a new test fails for each one. Replacingisset()andis_array()withis_array( ... ?? null )inwp_remote_retrieve_response_message()is equivalent, so no test can fail for it.Trac ticket: https://core.trac.wordpress.org/ticket/66501
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.