Repository navigation
Tests: Restore the widget and sidebar globals after Tests_Widgets. - #16249
mayankmajeji wants to merge 1 commit into
Conversation
The class empties the registered sidebars and widgets before each test, so a later class got the sidebars of the last test and no core widgets. Save the globals before the class and restore them after it. 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 reported for the change that restores widget and sidebar state to improve test isolation.
No open issues 🎉
What changed in this PR
This PR improves test isolation by restoring widget and sidebar state after Tests_Widgets, preventing leftover registrations from affecting later test classes.
Changes:
- Saves four registration globals and the widget factory’s widget collection before the class runs.
- Restores the saved state after the class, leaving per-test cleanup unchanged.
| File | Description |
|---|---|
tests/phpunit/tests/widgets.php |
Adds class-level setup and teardown hooks to preserve and restore widget and sidebar state. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
I reproduced the Customizer failure after the sidebar guessing test on single-site and multisite. Restoring the widget and sidebar registries after the class made both ordered runs pass (2 tests, 8 assertions each). All 62 widget tests also passed in random order. Thanks for including the two-test reproducer.
AI review · gpt-6.2-astra
Preserve the sidebar and widget registrations that later Customizer tests inherit. Developed in: #16249 Props mayankmajeji. See #66755. git-svn-id: https://develop.svn.wordpress.org/trunk@65795 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #16249 landed in https://core.trac.wordpress.org/changeset/65795 |
Preserve the sidebar and widget registrations that later Customizer tests inherit. Developed in: WordPress/wordpress-develop#16249 Props mayankmajeji. See #66755. Built from https://develop.svn.wordpress.org/trunk@65795 git-svn-id: http://core.svn.wordpress.org/trunk@64824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/66755
Tests_Widgets::clean_up_global_scope()empties$wp_registered_sidebars,$wp_registered_widgets,$wp_registered_widget_controls,$wp_registered_widget_updatesand$wp_widget_factory->widgetsbefore each test, but nothing puts them back after the class. The next class gets whatever the lastTests_Widgetstest registered, and none of the core widgets.When the last test is
test_sidebar_guessing(), theprimaryandsecondarysidebars it registers stay registered.Tests_WP_Customize_Manager::test_wp_customize_publish_changeset()then fails at$this->assertFalse( has_filter( 'option_sidebars_widgets' ) ): when it publishes the changeset,customize_registeralso runs for the previewing manager fromset_up(), whoseWP_Customize_Widgetsadds a newsidebars_widgets[primary]setting for the leftover sidebar and previews it. The test passes on its own.WP_Test_REST_Widgets_ControllerandWP_Test_REST_Sidebars_Controlleralready rebuild the widgets inwpTearDownAfterClass().What changes
Tests_Widgetssaves the five globals inwpSetUpBeforeClass()and restores them inwpTearDownAfterClass(). The tests still start from empty globals, sinceclean_up_global_scope()is unchanged.Testing
Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65781.
The config below runs
widgets.phpand thencustomize/manager.php. The--filtermakestest_sidebar_guessing()the last test ofTests_Widgets, as in the random run.vendor/bin/phpunit -c pair.xml --filter 'Tests_Widgets::test_sidebar_guessing$|test_wp_customize_publish_changeset': 1 failure on trunk ("Failed asserting that true is false"), OK (2 tests, 8 assertions) with this change.<const name="WP_TESTS_MULTISITE" value="1" />added).--group widgets(505 tests) and--group customize(243 tests): OK with this change, and--group widgetsalso on multisite.--filter Tests_Widgets, 386 tests) in default order, with--order-by=reverse, with--order-by=random --random-order-seed=7, and on multisite: OK with this change.-c tests/phpunit/multisite.xml --order-by=random --random-order-seed=1717. The random order depends on the set of tests, so the seed gives a different order on current trunk; the config reproduces the failure without a seed.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.