Skip to content

Tests: Add coverage for WP_Widget_Recent_Comments. - #14273

Closed
rvpatel wants to merge 1 commit into
WordPress:trunkfrom
rvpatel:65819-widget-recent-comments-tests
Closed

rvpatel wants to merge 1 commit into
WordPress:trunkfrom
rvpatel:65819-widget-recent-comments-tests

Conversation

@rvpatel

@rvpatel rvpatel commented Oct 14, 2026

Copy link
Copy Markdown

Adds unit test coverage for WP_Widget_Recent_Comments, which currently has none, following the same approach as the recent WP_Widget_Pages, WP_Widget_Categories and WP_Widget_Tag_Cloud tests.

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

What's covered

  • __construct(): widget settings, and that the wp_head style callback is only hooked when the widget is in an active sidebar.
  • recent_comments_style(): the default styles, no output without theme support for widgets, and the show_recent_comments_widget_style filter.
  • widget(): the five most recent comments, newest first; only approved comments on published posts; the markup of a listed comment; the number setting; the widget_comments_args and widget_title filters; the title fallback; an empty list; the list ID used after the first instance; the HTML5 navigation wrapper and its aria-label.
  • update(): sanitization and keeping other settings.
  • form(): fields with saved and default values.
  • flush_widget_cache(): the deprecation notice.

Notes

  • The <ul id="recentcomments"> used by the first widget on a page is tracked in a static variable for the whole request, so only the IDs used after it are tested.
  • remove_theme_support() doesn't remove the internal widgets registration, so _remove_theme_support() is used. Theme features are restored in tear_down().

Testing

  • npm run test:php -- --filter Tests_Widgets_wpWidgetRecentComments: OK (38 tests, 60 assertions)
  • npm run test:php -- --group widgets and --group comment pass.
  • Temporarily changing the comment query to allow unapproved comments or unpublished posts, or removing absint() from update(), makes the tests fail.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Writing the tests and this description. I reviewed the tests, ran them locally, and take responsibility for them.


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.

Cover the constructor settings and conditional style hook, the default styles, the listed comments and their markup, the number setting, title and comments filters, navigation markup, settings sanitization, form fields, and the deprecated cache flush method.

See #65819.
@github-actions

github-actions Bot commented Oct 14, 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. 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 ravipatel, 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.

🟢 Approval recommended

The test-only changes match existing behavior and conventions, with no blocking issues identified.

0 open findings

What changed in this PR

Adds unit coverage for WP_Widget_Recent_Comments, following existing widget test patterns without changing production code.

Changes:

  • Tests rendering, comment selection, filters, styles, and navigation markup.
  • Covers settings sanitization, form defaults, and cache-method deprecation.
File Description
tests/​phpunit/​tests/​widgets/​wpWidgetRecentComments.php Adds fixtures and tests for Recent Comments widget behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

No blockers found in the code review or scoped unit-tests audit. The focused randomized run passed with 38 tests and 60 assertions; the widgets group passed on single-site and multisite with 286 tests and 1,256 assertions each. PHPCS and CI passed.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

Optional follow-up: in test_widget_omits_navigation_wrapper_in_xhtml(), also assert that the comment list remains present. That would prevent an empty response from satisfying the negative navigation assertion. This is not a landing blocker.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 15, 2026
Cover comment ordering and visibility, widget filters and markup, styles, settings sanitization, form fields, and the deprecated cache method.

Developed in: #14273

Props ravipatel.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64357 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 15, 2026
Cover comment ordering and visibility, widget filters and markup, styles, settings sanitization, form fields, and the deprecated cache method.

Developed in: WordPress/wordpress-develop#14273

Props ravipatel.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64357


git-svn-id: http://core.svn.wordpress.org/trunk@63507 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@rvpatel
rvpatel deleted the 65819-widget-recent-comments-tests branch October 19, 2026 15:40
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