Repository navigation
Tests: Restore theme features after each Tests_Image_Header test. - #16182
mayankmajeji wants to merge 1 commit into
Conversation
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.
|
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 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_featuresduring 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
left a comment
There was a problem hiding this comment.
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
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
|
PR #16182 landed in https://core.trac.wordpress.org/changeset/65745 |
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
Trac ticket: https://core.trac.wordpress.org/ticket/66755
The
Tests_Image_Headertests write custom header dimensions (width1200,height230) straight into the$_wp_theme_featuresglobal and never restore it. If a later test callsadd_theme_support( 'custom-header' )without removing the feature first, the leaked values win ("the first value registered wins"), andadd_theme_support()defines theHEADER_IMAGE_WIDTHandHEADER_IMAGE_HEIGHTconstants 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, andWP_Test_REST_Themes_Controller::test_theme_supports_custom_header()then fails withwidth1200 andheight230 instead of 0 and 0, although it passes on its own.tests/phpunit/tests/theme/customHeader.phpalready avoidsadd_theme_support( 'custom-header' )for this reason, andTests_Admin_Includes_Template_GetMediaStatesrestores the global after each test.What changes
Tests_Image_Header::set_up()saves$_wp_theme_features, and a newtear_down()restores it, asTests_Admin_Includes_Template_GetMediaStatesdoes.Testing
Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65744:
image/header.php,customize/manager.phpand thenrest-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,width1200 andheight230), OK (174 tests, 1,232 assertions) with this change. Same on multisite (the config with<const name="WP_TESTS_MULTISITE" value="1" />added).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.--order-by=random --random-order-seed=303, whereTests_Image_Headerran beforeTests_WP_Customize_ManagerandWP_Test_REST_Themes_Controller.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.