Skip to content

Add PHPUnit tests for wp_maybe_load_widgets function - #5831

Open
pbearne wants to merge 8 commits into
WordPress:trunkfrom
pbearne:60180-wp_maybe_load_widgets
Open

pbearne wants to merge 8 commits into
WordPress:trunkfrom
pbearne:60180-wp_maybe_load_widgets

Conversation

@pbearne

@pbearne pbearne commented Jan 3, 2024 •

Copy link
Copy Markdown

This commit introduces PHPUnit tests for the wp_maybe_load_widgets function. The tests are implemented in a new file, wpMaybeLoadWidgets.php, inside the tests/phpunit/tests/functions/ directory and cover different cases and scenarios to ensure proper functionality of the wp_maybe_load_widgets function.

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

This commit introduces PHPUnit tests for the wp_widgets_add_menu function. The tests are implemented in a new file, wpWidgetsAddMenu.php, inside the tests/phpunit/tests/functions/ directory and cover different cases and scenarios to ensure proper functionality of the wp_widgets_add_menu function.
@pbearne pbearne changed the title Add PHPUnit tests for wp_widgets_add_menu function Add PHPUnit tests for wp_maybe_load_widgets function Jan 3, 2024
@github-actions

github-actions Bot commented Jan 3, 2024

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

🟡 Changes recommended

The tests bypass parent lifecycle cleanup, leaving hook state changed, and rely on a bootstrap-registered callback that masks failures in action registration and filter short-circuiting.

3 open issues
What changed in this PR

Adds PHPUnit tests for WordPress’s wp_maybe_load_widgets() function, targeting Trac ticket #60180 without changing production code.

Changes:

  • Adds tests for the default behavior and when load_default_widgets returns false.
  • Adds setup and teardown methods to preserve the $submenu global.
File Description
tests/​phpunit/​tests/​functions/​wpMaybeLoadWidgets.php Introduces widget-loading tests and local state setup and cleanup.

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.

Please call the parent lifecycle methods and establish that the widget-menu callback is absent before exercising this function. Both current assertions can pass from bootstrap state; the disabled path returns without registering the callback. Assert the enabled/disabled outcomes separately. The submenu snapshot is unrelated and can be removed.

AI review · gpt-6

@github-actions

github-actions Bot commented Nov 3, 2026 •

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 pbearne, lancewillett.

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.

Paul Bearne and others added 3 commits November 2, 2026 19:06
- Update method names and signatures for better clarity.
- Add coverage for filtered short-circuiting behavior.

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 this test-only change covering widget-menu registration and filter-based short-circuiting.

1 open issue
2 resolved since last review

Review effort: Balanced

@pbearne
pbearne requested a review from lancewillett November 3, 2026 00:14

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

Thanks, this does what I asked: the precondition check runs first, and the enabled and disabled outcomes are separate tests. Each one catches a break the other doesn't. Ignoring load_default_widgets fails the disabled test, and dropping the add_action() fails the enabled test. It passes in randomized single-site and multisite runs, and PHPCS is clean.

One last thing: please remove tear_down(). It only calls parent::tear_down(), so it does nothing. I'll approve once that's gone.

AI review · claude-opus-5-5

Removed unnecessary tear_down method from test class.
@pbearne
pbearne requested review from lancewillett and a balanced review from Copilot November 26, 2026 19:58

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 reported for this test-only addition covering default widget registration and filter-based short-circuiting.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants