Repository navigation
Conversation
…ets of the sidebars. Covers `is_active_sidebar()`, `is_dynamic_sidebar()`, `wp_find_widgets_sidebar()` and `wp_assign_widget_to_sidebar()`, which had no tests. See #66502.
|
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 identified for this test-only expansion of sidebar and widget coverage.
No open issues 🎉
What changed in this PR
Adds unit tests for four sidebar and widget functions in src/wp-includes/widgets.php, extending the coverage tracked in ticket #66502 and complementing #15613. No production behavior changes.
Changes:
- Covers sidebar activity checks, widget registration requirements, ID handling, and filters.
- Tests widget lookup, assignment, movement, removal, and persistence.
- Isolates test state by resetting sidebar/widget registries and clearing the sidebar-widget cache.
| File | Description |
|---|---|
tests/phpunit/tests/widgets/wpFindWidgetsSidebar.php |
Tests exact widget lookup, inactive widgets, duplicate assignments, and filtering. |
tests/phpunit/tests/widgets/wpAssignWidgetToSidebar.php |
Tests assignment, movement, removal, saved data, and subsequent reads. |
tests/phpunit/tests/widgets/isDynamicSidebar.php |
Tests dynamic sidebar detection based on registered sidebars and widgets. |
tests/phpunit/tests/widgets/isActiveSidebar.php |
Tests activity detection, ID normalization, assignment changes, and filters. |
Review effort: Balanced
Adds unit tests for four more functions in
src/wp-includes/widgets.phpthat were not referenced by any test. This is the second group of the work described in the ticket, and is independent from the first one (the functions that read the registered sidebars and widgets, in #15613). No behavior is changed.Functions covered, each in its own test class in
tests/phpunit/tests/widgets/:is_active_sidebar()sidebar-N), a string is sanitized like a title.is_active_sidebarfilter receives the result and the index, and its result is returned.is_dynamic_sidebar()wp_find_widgets_sidebar()sidebars_widgetsfilter is used.wp_assign_widget_to_sidebar()'',nullorfalse).Assigning a widget to the sidebar it already is in is not covered, because it currently adds the widget a second time and that behavior is not asserted.
The tests reset the registered sidebars, widgets and the cache of the sidebars of widgets, and restore them afterwards.
Testing:
vendor/bin/phpunit --filter 'Tests_Widgets_(IsActiveSidebar|IsDynamicSidebar|WpFindWidgetsSidebar|WpAssignWidgetToSidebar)'vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Widgets_(IsActiveSidebar|IsDynamicSidebar|WpFindWidgetsSidebar|WpAssignWidgetToSidebar)'vendor/bin/phpcs tests/phpunit/tests/widgets/I also temporarily broke these functions in
src/wp-includes/widgets.php(the prefix of numeric sidebars, the sanitizing of the ID, the filter, the check for the widgets, the registered widgets and sidebars inis_dynamic_sidebar(), stopping at the first widget, the strict comparison and the string cast inwp_find_widgets_sidebar(), its order, and inwp_assign_widget_to_sidebar()the removal of the old assignment, the loop over duplicates, adding to an empty sidebar and saving the result) and confirmed that a new test fails for each one. Removing the$sidebar_id !== $maybe_sidebar_idcondition ofwp_assign_widget_to_sidebar()is not caught on purpose, because it only changes the case that is not asserted.Trac ticket: https://core.trac.wordpress.org/ticket/66502
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.
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.