WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 5 weeks ago

#48093 reopened defect (bug)

get_comment_count() should return an integer for all counts of all statuses

Reported by: johnbillion Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 2.0
Component: Comments Keywords: good-first-bug has-patch needs-testing has-unit-tests needs-dev-note
Focuses: Cc:
PR Number:

Description

get_comment_count() returns a mixture of integers and numeric strings depending on the comment status and count.

Any status with zero comments is represented by integer 0.
Any status with more than zero comments is represented by a numeric string.
The total_comments and all elements are always integers.

Example:

array(7) {
  ["approved"]            => string(1) "221"
  ["awaiting_moderation"] => int(0)
  ["spam"]                => string(1) "10"
  ["trash"]               => int(0)
  ["post-trashed"]        => int(0)
  ["total_comments"]      => int(221)
  ["all"]                 => int(211)
}

It should return integers for all statuses for consistency.

The tests in Tests_Get_Comment_Count() should be switched to using assertSame().

Attachments (2)

48093.patch (443 bytes) - added by progremzion 3 months ago.
48093.diff (8.3 KB) - added by m.usama.masood 2 months ago.

Download all attachments as: .zip

Change History (14)

#1 @johnbillion
3 months ago

In 46223:

Docs: Improve the docs for comment counting related functions.

See #47110, #48093

#2 @johnbillion
3 months ago

  • Keywords good-first-bug added

#3 @progremzion
3 months ago

  • Keywords has-patch added; needs-patch removed

Hi @johnbillion

I have fixed the issue. Can you please review? I am new to core contribution, so please do let me know if something is missing.

We don't need to update the Tests_Get_Comment_Count() class as by updating the get_comment_count function's return value will resolve that.

Thanks!

@progremzion
3 months ago

#4 @progremzion
3 months ago

  • Keywords needs-testing added

#5 @m.usama.masood
2 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed
  • Resolution set to worksforme
  • Status changed from new to closed

Hi @davidakennedy,

I have applied patch and update docs of functions. I also updated the Tests_Get_Comment_Count() class & Tests_Import_Import() class for phpunit test.

Thanks!

#6 @knutsp
2 months ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

A valid bug ticket is first closed after committed, then as "fixed".

This ticket was mentioned in Slack in #core by sergey. View the logs.


2 months ago

#8 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.4

This ticket was mentioned in Slack in #core by sergey. View the logs.


6 weeks ago

#10 @sncoker
5 weeks ago

At #WCUS Contributor Day. Patch still applies cleanly. Unit tests are passing.

#11 @yingling017
5 weeks ago

At #WCUSContributorDay patch applies cleanly and unit tests are passing.

#12 @desrosj
5 weeks ago

  • Keywords needs-dev-note added

This could be a good thing to call out in the Miscellaneos Developer Changes dev note just in case someone is performing strict comparisons.

Note: See TracTickets for help on using tickets.