Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#34059 closed task (blessed) (fixed)

Abstract functionality from wp-comments-post.php

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch has-unit-tests commit
Focuses: Cc:


wp-comments-post.php is a remnant of days gone past and a great example of technical debt. Everything going in is slashed, and every error condition results in an exit, except when it results in a redirect header followed by an exit.

There's not much we can do about this, but what we can do it abstract a bunch of the code into a function, in order to make the actual process of submitting a comment unit testable.

Attachments (5)

34059.diff (11.2 KB) - added by johnbillion 9 years ago.
34059.2.diff (19.9 KB) - added by johnbillion 9 years ago.
34059.3.diff (26.1 KB) - added by johnbillion 9 years ago.
34059.4.diff (26.1 KB) - added by johnbillion 9 years ago.
34059.5.diff (27.5 KB) - added by johnbillion 9 years ago.

Download all attachments as: .zip

Change History (14)

9 years ago

#1 @johnbillion
9 years ago

  • Keywords has-patch needs-unit-tests added

34059.diff introduces wp_handle_comment_post() which accepts an unslashed array of comment data and returns a WP_Comment or WP_Error object.

Unit tests are in progress.

9 years ago

#2 @johnbillion
9 years ago

  • Keywords has-unit-tests dev-feedback added; needs-unit-tests removed

34059.3.diff introduces tests for comment posting.

Anyone want to review this?

Last edited 9 years ago by johnbillion (previous) (diff)

9 years ago

9 years ago

#3 @johnbillion
9 years ago

34059.4.diff includes updated tests for multisite.

#4 @wonderboymusic
9 years ago

  • Owner set to johnbillion
  • Status changed from new to assigned

#5 @DrewAPicture
9 years ago

Only two things that jumped out at me:

  • If the ternaries are aligned like that because they started wrapping to new lines, we might as well just do if/else statements. Or initialize the nulls as null and 0s as 0s first, then do if statements to set values from the $comment_data array.
  • I think wp_handle_comment_post() might be a little too ambiguous and easily confused with post as in post type instead of post as in $_POST

9 years ago

#6 @johnbillion
9 years ago

  • Keywords commit added; dev-feedback removed

In 34059.5.diff:

  • Renames wp_handle_comment_post() to wp_handle_comment_submission().
  • Initialises the $comment_* variables to avoid the ternaries.
  • Adds a test for comment content that contains slashes.

I think this is good to go.

#7 @SergeyBiryukov
9 years ago

assertNotFalse() was throwing a fatal error on PHP 5.2, see [33526], [33846], and [34664] :)

Looks good otherwise.

#8 @SergeyBiryukov
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34799:

Abstract functionality from wp-comments-post.php into a function, wp_handle_comment_submission().

Add unit tests.

Props johnbillion.
Fixes #34059.

#9 @SergeyBiryukov
9 years ago

In 34801:

Add missing unit tests from [34799].

Props johnbillion.
See #34059.

Note: See TracTickets for help on using tickets.