Skip to content

Tests: Restore theme features after each Tests_Image_Header test. - #16182

Closed
mayankmajeji wants to merge 1 commit into
WordPress:trunkfrom
mayankmajeji:tests/66755-isolation
Closed

mayankmajeji wants to merge 1 commit into
WordPress:trunkfrom
mayankmajeji:tests/66755-isolation

Conversation

@mayankmajeji

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/66755

The Tests_Image_Header tests write custom header dimensions (width 1200, height 230) straight into the $_wp_theme_features global and never restore it. If a later test calls add_theme_support( 'custom-header' ) without removing the feature first, the leaked values win ("the first value registered wins"), and add_theme_support() defines the HEADER_IMAGE_WIDTH and HEADER_IMAGE_HEIGHT constants from them. Constants cannot be undone, so every later custom header registration in the run gets 1200 x 230. Tests_WP_Customize_Manager::test_import_theme_starter_content() is one such caller, and WP_Test_REST_Themes_Controller::test_theme_supports_custom_header() then fails with width 1200 and height 230 instead of 0 and 0, although it passes on its own.

tests/phpunit/tests/theme/customHeader.php already avoids add_theme_support( 'custom-header' ) for this reason, and Tests_Admin_Includes_Template_GetMediaStates restores the global after each test.

What changes

  • Tests_Image_Header::set_up() saves $_wp_theme_features, and a new tear_down() restores it, as Tests_Admin_Includes_Template_GetMediaStates does.

Testing

Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65744:

  • With the config below, which runs image/header.php, customize/manager.php and then rest-api/rest-themes-controller.php, vendor/bin/phpunit -c pair.xml: 1 failure on trunk (WP_Test_REST_Themes_Controller::test_theme_supports_custom_header, width 1200 and height 230), OK (174 tests, 1,232 assertions) with this change. Same on multisite (the config with <const name="WP_TESTS_MULTISITE" value="1" /> added).
  • The same config without image/header.php: OK (167 tests, 1,218 assertions) on trunk.
  • vendor/bin/phpunit --filter 'Tests_Image_Header::': OK (7 tests, 14 assertions) with this change.
  • vendor/bin/phpunit --group header,customize,restapi-themes: OK (345 tests, 2,817 assertions) with this change.
  • Found in a full-suite run with --order-by=random --random-order-seed=303, where Tests_Image_Header ran before Tests_WP_Customize_Manager and WP_Test_REST_Themes_Controller.
  • PHPCS reports nothing on the changed file.
<phpunit bootstrap="tests/phpunit/includes/bootstrap.php" backupGlobals="false" convertErrorsToExceptions="true" convertWarningsToExceptions="true" convertNoticesToExceptions="true" convertDeprecationsToExceptions="true">
	<testsuites>
		<testsuite name="pair">
			<file>tests/phpunit/tests/image/header.php</file>
			<file>tests/phpunit/tests/customize/manager.php</file>
			<file>tests/phpunit/tests/rest-api/rest-themes-controller.php</file>
		</testsuite>
	</testsuites>
	<php>
		<const name="WP_RUN_CORE_TESTS" value="1" />
	</php>
</phpunit>

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigation, code, local testing and PR wording. I reviewed the reasoning, the code and the test results, and I take responsibility for the contribution.

The image header tests write custom header dimensions into `$_wp_theme_features`. A later `add_theme_support( 'custom-header' )` call picks them up and defines the header size constants, so the REST themes custom header test sees 1200 x 230.

See #66755.
@github-actions

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 mayankmajeji.

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 recorded for the change restoring theme features between image header tests.

No open issues 🎉

What changed in this PR

This PR improves test isolation by restoring theme features after each Tests_Image_Header test, preventing custom header dimensions from leaking into later tests.

Changes:

  • Save $_wp_theme_features during test setup.
  • Restore the saved value during teardown before calling the parent teardown.
File Description
tests/​phpunit/​tests/​image/​header.php Adds per-test backup and restoration of global theme features.

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.

I reproduced the REST theme failure by running the image header, Customizer manager, and REST themes tests in that order. The REST response inherited a 1200 × 230 header. With this change, all 173 tests passed on both single-site and multisite. Restoring the original theme features fixes an observable leak.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Nov 23, 2026
Keep custom header dimensions set by these tests from affecting later REST theme responses.

Developed in: #16182

Props mayankmajeji.
See #66755.


git-svn-id: https://develop.svn.wordpress.org/trunk@65745 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 23, 2026
Keep custom header dimensions set by these tests from affecting later REST theme responses.

Developed in: WordPress/wordpress-develop#16182

Props mayankmajeji.
See #66755.

Built from https://develop.svn.wordpress.org/trunk@65745


git-svn-id: http://core.svn.wordpress.org/trunk@64775 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