Skip to content

Tests: Add unit tests for the Widget Group block rendering and the sidebar notes - #15627

Closed
hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66514-widget-group-tests
Closed

hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66514-widget-group-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for the functions in src/wp-includes/blocks/widget-group.php, which were not referenced by any test. No behavior is changed.

The new test class tests/phpunit/tests/blocks/renderWidgetGroup.php covers:

  • render_block_core_widget_group()
    • The title uses the default <h2 class="widget-title"> heading without a sidebar, or when the sidebar being rendered is not registered, and the before_title and after_title of the sidebar being rendered when it is registered.
    • The title is escaped, and no heading is rendered without a title (missing, empty or null).
    • The inner blocks are rendered in order inside the wp-widget-group__inner-blocks wrapper, and the $content that is passed is ignored.
  • note_sidebar_being_rendered()
    • Stores an ID, a name or an integer index, replaces the previous one, and is used by the dynamic_sidebar_before action.
  • register_block_core_widget_group()
    • Registers core/widget-group with render_block_core_widget_group as the render callback.
  • discard_sidebar_being_rendered() is only checked to be hooked to dynamic_sidebar_after. It calls unset() on a variable declared with global, which removes only the local reference and leaves $_sidebar_being_rendered set, so I did not assert that the global is cleared.

Testing:

  • vendor/bin/phpunit --filter Tests_Blocks_RenderWidgetGroup
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Blocks_RenderWidgetGroup
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderWidgetGroup.php

I also temporarily broke the functions (removing the escaping, the title check, the sidebar lookup, the rendering of the inner blocks, the noting of the sidebar, each of the two hooks and the render callback, and swapping the before and after title markup) and confirmed that a new test fails for each one.

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

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.

@github-actions

github-actions Bot commented Nov 6, 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 hmbashar.

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

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 leave two coverage gaps: the null-title input is normalized into a missing title, and direct registration does not verify the init hook.

2 open issues
What changed in this PR

Adds PHPUnit coverage for the Widget Group block’s server-side rendering and sidebar-tracking helpers, without changing production behavior.

Changes:

  • Tests title markup, escaping, missing titles, inner-block ordering, and ignored content.
  • Covers sidebar tracking, action hooks, and sidebar-specific rendering.
  • Checks block registration and its render callback.
File Description
tests/​phpunit/​tests/​blocks/​renderWidgetGroup.php Adds rendering, sidebar-tracking, and registration tests with setup and cleanup of sidebar globals.

Review effort: Balanced

@hmbashar hmbashar closed this Nov 7, 2026
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.

2 participants