Skip to content

Tests: Add unit tests for register_default_headers() and unregister_default_headers(). - #16190

Closed
rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/theme-default-headers
Closed

rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/theme-default-headers

Conversation

@rejaulalomkhan

@rejaulalomkhan rejaulalomkhan commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Description

Adds dedicated unit tests for register_default_headers() and unregister_default_headers() in src/wp-includes/theme.php. While unregister_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_headers and 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 returns true.
  • test_unregister_default_headers_single_failure(): Verifies that attempting to unregister a non-existent header returns false.
  • test_unregister_default_headers_array(): Verifies that unregistering multiple headers using an array unsets each specified header and returns null (matching documented core behavior).

Testing Instructions

Run single-site and multisite test suites and coding standards:

php ./vendor/bin/phpunit tests/phpunit/tests/theme/defaultHeaders.php
php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml tests/phpunit/tests/theme/defaultHeaders.php
php ./vendor/bin/phpcs tests/phpunit/tests/theme/defaultHeaders.php

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.

…efault_headers().

Cover registering headers, merging with existing headers, unregistering single header with bool return, and unregistering multiple headers with null return.

See #21876.
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

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:

Props rejaulalomkhan, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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, and null removal return values.
  • Backs up and restores $_wp_default_headers around 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 lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rejaulalomkhan

Copy link
Copy Markdown
Member Author

Thanks for the review and guidance, @lancewillett! Updated per your feedback:

  • Switched @group theme to @group themes.
  • Combined the two registration tests into test_register_default_headers(), registering two batches and asserting that both headers and their metadata survive subsequent registrations without replacement.
  • Dropped redundant pre-removal key assertions in single- and multiple-header removal tests while keeping return value assertions (true, false, null).

All single-site and multisite tests pass with 0 PHPCS errors.

AI assistance · Gemini 3.8 Flash

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the added PHPUnit coverage of default-header registration and removal.

No open issues 🎉

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

wporg-sync pushed a commit that referenced this pull request Nov 25, 2026
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
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65787
GitHub commit: 6674eea

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 25, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 25, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants