Skip to content

Tests: Fix two widget tests that depend on test order - #13863

Closed
lancewillett wants to merge 2 commits into
WordPress:trunkfrom
lancewillett:fix/65893-widgets-random-order
Closed

lancewillett wants to merge 2 commits into
WordPress:trunkfrom
lancewillett:fix/65893-widgets-random-order

Conversation

@lancewillett

Copy link
Copy Markdown
Member

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()
    • In Customizer mode, retrieve_widgets() works on the $sidebars_widgets global and only checks that the theme mod is an array.
    • The test set the theme mod but never the global. It passed only because the test before it in the file left matching widgets cached; run alone, it read the default install widgets.
    • The test now sets the global to the same widgets, as the sibling retrieve_widgets() tests do.
  • Tests_Widgets_wpWidgetMedia::test_constructor()
    • test_constructor_in_customize_preview() leaves $wp_customize set. The next WP_Widget_Media then thinks it is in a preview and adds a wp_enqueue_scripts hook the constructor test says should not be there.
    • The class now resets $wp_customize in clean_up_global_scope(), as Tests_Widgets_wpWidgetText already does.

No assertions changed.

Testing Instructions

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --filter '/^Tests_Widgets::test_retrieve_widgets_for_customizer( |$)/'. On trunk: fails ("Failed asserting that an array contains 'tag_cloud-1'"). On this branch: passes.
  3. Run npm run test:php -- --filter 'Tests_Widgets_wpWidgetMedia::' --order-by=reverse. On trunk: test_constructor fails. On this branch: 12 tests pass.
  4. Run npm run test:php -- --group widgets in default order and with --order-by=random --random-order-seed=1 and =2. On trunk, 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.

lancewillett and others added 2 commits September 30, 2026 11:07
…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>
@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. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props lancewillett.

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

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.

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_widgets in the Customizer test.
  • Resets $wp_customize after 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.

@lancewillett

lancewillett commented Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

wporg-sync pushed a commit that referenced this pull request Oct 1, 2026
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
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 1, 2026
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
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