Tests: Fix two widget tests that depend on test order - #13863
lancewillett wants to merge 2 commits into
Conversation
…idgets()` test. `retrieve_widgets()` reads the `$sidebars_widgets` global and only checks that the `sidebars_widgets` theme mod is an array. `test_retrieve_widgets_for_customizer()` never set that global, so it passed only when the previous test in the file left its results behind. Run alone, in reverse, or in random order, it read the default install widgets instead. The test now sets the global to the same widgets it stores in the theme mod. See #65893. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`test_constructor_in_customize_preview()` starts a Customizer preview and leaves the `$wp_customize` global set. When `test_constructor()` ran after it, the widget registered its preview scripts and the test failed. The test class now clears `$wp_customize` in `clean_up_global_scope()`, as `Tests_Widgets_wpWidgetText` already does. See #65893. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Both changes correctly eliminate the identified test-order dependencies using established test patterns.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes order-dependent widget tests by isolating their global state.
Changes:
- Initializes
$sidebars_widgetsin the Customizer test. - Resets
$wp_customizeafter media-widget tests.
| File | Description |
|---|---|
tests/phpunit/tests/widgets.php |
Initializes the sidebar global used by retrieve_widgets(). |
tests/phpunit/tests/widgets/wpWidgetMedia.php |
Cleans up the Customizer global between tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
PR #13863 landed in https://core.trac.wordpress.org/changeset/64038 |
Initialize the sidebar widgets global in the Customizer retrieval test and reset the Customizer global after media widget tests. Preserve the existing assertions while removing dependencies on earlier tests. Developed in: #13863 Props adrianmoldovanwp. See #65893. git-svn-id: https://develop.svn.wordpress.org/trunk@64038 602fd350-edb4-49c9-b593-d223f7449a82
Initialize the sidebar widgets global in the Customizer retrieval test and reset the Customizer global after media widget tests. Preserve the existing assertions while removing dependencies on earlier tests. Developed in: WordPress/wordpress-develop#13863 Props adrianmoldovanwp. See #65893. Built from https://develop.svn.wordpress.org/trunk@64038 git-svn-id: http://core.svn.wordpress.org/trunk@63197 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: core.trac.wordpress.org/ticket/65893
Two widget tests pass in default order and fail when run alone, in reverse or in random order. One commit each:
Tests_Widgets::test_retrieve_widgets_for_customizer()retrieve_widgets()works on the$sidebars_widgetsglobal and only checks that the theme mod is an array.retrieve_widgets()tests do.Tests_Widgets_wpWidgetMedia::test_constructor()test_constructor_in_customize_preview()leaves$wp_customizeset. The nextWP_Widget_Mediathen thinks it is in a preview and adds awp_enqueue_scriptshook the constructor test says should not be there.$wp_customizeinclean_up_global_scope(), asTests_Widgets_wpWidgetTextalready does.No assertions changed.
Testing Instructions
npm run env:start && npm run env:install.npm run test:php -- --filter '/^Tests_Widgets::test_retrieve_widgets_for_customizer( |$)/'. Ontrunk: fails ("Failed asserting that an array contains 'tag_cloud-1'"). On this branch: passes.npm run test:php -- --filter 'Tests_Widgets_wpWidgetMedia::' --order-by=reverse. Ontrunk:test_constructorfails. On this branch: 12 tests pass.npm run test:php -- --group widgetsin default order and with--order-by=random --random-order-seed=1and=2. Ontrunk, both tests fail at seeds 1 and 2. On this branch, neither does. Other REST widget tests in that group still fail at those seeds; Tests: Improve REST API test isolation #13185 addresses those.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code, Codex
Model(s): Claude Opus 5.5, gpt-6-astra (Codex review)
Used for: tracing both failures, making the changes, running the tests, and a second-model review
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.