Repository navigation
Tests: Add unit tests for register_default_headers() and unregister_default_headers(). - #16190
rejaulalomkhan wants to merge 2 commits into
Conversation
…efault_headers(). Cover registering headers, merging with existing headers, unregistering single header with bool return, and unregistering multiple headers with null return. See #21876.
|
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 identified for the added PHPUnit coverage of WordPress’s default-header registration and removal APIs.
No open issues 🎉
What changed in this PR
Adds dedicated PHPUnit coverage for WordPress’s default-header registration and removal APIs, addressing the testing gap associated with Trac #21876. No production code changes are included.
Changes:
- Adds five tests covering registration, merging, single-header removal success and failure, and array-based removal.
- Checks stored metadata and the
true,false, andnullremoval return values. - Backs up and restores
$_wp_default_headersaround each test.
| File | Description |
|---|---|
tests/phpunit/tests/theme/defaultHeaders.php |
Adds default-header API tests with global-state backup and restoration. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
Could you combine the two registration tests? Register two batches and check that both headers and their metadata survive the second call. That catches accidental replacement and covers the first registration as well. Keep the single- and multiple-header removal behavior, including the documented return values. The pre-removal key assertions repeat the registration coverage.
Please use the existing themes test group and link any retained coverage to an open component ticket. The historical ticket can stay as context.
AI review · gpt-6
|
Thanks for the review and guidance, @lancewillett! Updated per your feedback:
All single-site and multisite tests pass with 0 PHPCS errors. AI assistance · |
lancewillett
left a comment
There was a problem hiding this comment.
The combined registration case catches the regression we discussed: when I made the second call replace the headers, the assertion for the first header failed. The unregister cases still check the single-key return values and the bulk removal. These passed on both single-site and multisite.
The code looks ready. Please link the open Themes coverage ticket before landing; #21876 documents the historical return-value contract.
AI review · gpt-6
Check that successive registrations preserve existing headers and that removing one or more headers updates the registry. Developed in: #16190 Follow-up to r27575. Props rejaulalomkhan. Fixes #66826. git-svn-id: https://develop.svn.wordpress.org/trunk@65787 602fd350-edb4-49c9-b593-d223f7449a82
Check that successive registrations preserve existing headers and that removing one or more headers updates the registry. Developed in: WordPress/wordpress-develop#16190 Follow-up to r27575. Props rejaulalomkhan. Fixes #66826. Built from https://develop.svn.wordpress.org/trunk@65787 git-svn-id: http://core.svn.wordpress.org/trunk@64816 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Description
Adds dedicated unit tests for
register_default_headers()andunregister_default_headers()insrc/wp-includes/theme.php. Whileunregister_default_headers()return behavior was clarified in [27575] (#21876), neither function had unit tests covering their registration, merging, and unregistering behaviors.Tests added in
tests/phpunit/tests/theme/defaultHeaders.php:test_register_default_headers(): Verifies that registering multiple batches of default headers populates$_wp_default_headersand preserves existing header keys and metadata without replacement.test_unregister_default_headers_single_success(): Verifies that unregistering a single header key successfully unsets it from the global array and returnstrue.test_unregister_default_headers_single_failure(): Verifies that attempting to unregister a non-existent header returnsfalse.test_unregister_default_headers_array(): Verifies that unregistering multiple headers using an array unsets each specified header and returnsnull(matching documented core behavior).Testing Instructions
Run single-site and multisite test suites and coding standards:
All 4 tests and 11 assertions pass cleanly with 0 PHPCS errors.
Trac ticket: https://core.trac.wordpress.org/ticket/66826
This Pull Request is for code review only. Please keep all other discussion to the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
Use of AI Tools
AI assistance: Yes
Tool(s): Google Antigravity
Model(s): Gemini 3.8 Flash
Used for: Identifying untested default header functions, authoring PHPUnit test cases per committer review, and running verification suites locally. I reviewed every line, ran the tests, and take responsibility for the change.