Skip to content

Tests: Add unit coverage for get_comment_type() and comment_type() - #15253

Open
shail-mehta wants to merge 6 commits into
WordPress:trunkfrom
shail-mehta:tests/get-comment-type-65819
Open

shail-mehta wants to merge 6 commits into
WordPress:trunkfrom
shail-mehta:tests/get-comment-type-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for get_comment_type() and comment_type(), covering empty-type normalization, pingback/trackback types, comment objects, the global comment fallback, the filter, and output labels.

Test-only; no production code changes.

Why

These helpers had no direct @covers coverage. Small helper coverage fits the #65819 test cleanup track.

How

Add tests/phpunit/tests/comment/getCommentType.php with @covers for both functions.

Testing Instructions

  1. npm run test:php -- --filter Tests_Comment_GetCommentType
  2. npm run test:php -- --filter Tests_Comment_GetCommentType -c tests/phpunit/multisite.xml
  3. npm run test:php -- --filter Tests_Comment_GetCommentType --order-by=random
  4. npm run test:php -- --group comment

Use of AI Tools

  • Cursor

Add unit tests for type normalization, known types, filters, and output labels.

See #65819.

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 empty-type normalization untested because the factory normalizes it first, and they fail to clear the global comment fixture, risking stale objects in later tests.

2 open issues
What changed in this PR

Adds dedicated PHPUnit tests for WordPress’s get_comment_type() and comment_type() helpers as part of the test cleanup tracked in Trac #65819. No production code changes are included.

Changes:

  • Adds cases for comment types, comment objects, and the global comment fallback.
  • Tests filter overrides and default/custom output labels.
  • Adds direct @covers annotations for both helpers.
File Description
tests/​phpunit/​tests/​comment/​getCommentType.php Adds a dedicated test class for comment-type retrieval and output.

Review effort: Balanced

Clear the comment global in tear_down and force an empty type on the object so empty-type normalization is actually tested.

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 change adding coverage for the comment-type helpers.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 30, 2026 17:14
@github-actions

github-actions Bot commented Oct 30, 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 shailu25, 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 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.

@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 trim the repeated getter cases before landing. The standalone pingback, trackback, object-input, and global-input methods largely repeat the same unchanged field return. Keep the empty-type normalization check (the direct object mutation correctly addresses Copilot), the filter-result check, and the default/custom output-label checks; use the retained label tests to exercise the global lookup. That preserves the meaningful behavior with four methods instead of eight. This is a test-size request, not a runtime failure.

AI review · gpt-6

Keep empty-type normalization, filter override, and label output checks that also exercise the global comment fallback.

See #65819.

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.

🔵 Needs a closer look

Human assessment is needed because ordinary-comment output remains untested, allowing regressions in the default or custom comment label to pass all four tests.

No open issues 🎉

Review effort: Balanced

Exercise default and custom comment labels alongside pingback and trackback via data providers.

See #65819.

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 were identified in the test-only change adding coverage for the comment-type helpers.

No open issues 🎉

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