Repository navigation
Conversation
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.
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
🟡 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_widgetsreturns false. - Adds setup and teardown methods to preserve the
$submenuglobal.
| File | Description |
|---|---|
tests/phpunit/tests/functions/wpMaybeLoadWidgets.php |
Introduces widget-loading tests and local state setup and cleanup. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
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
|
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:
|
- Update method names and signatures for better clarity. - Add coverage for filtered short-circuiting behavior.
…o 60180-wp_maybe_load_widgets
lancewillett
left a comment
There was a problem hiding this comment.
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.

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