WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#34059 closed task (blessed) (fixed)

Abstract functionality from wp-comments-post.php

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

Description

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 4 years ago.
34059.2.diff (19.9 KB) - added by johnbillion 4 years ago.
34059.3.diff (26.1 KB) - added by johnbillion 4 years ago.
34059.4.diff (26.1 KB) - added by johnbillion 4 years ago.
34059.5.diff (27.5 KB) - added by johnbillion 4 years ago.

Download all attachments as: .zip

Change History (14)

@johnbillion
4 years ago

#1 @johnbillion
4 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.

@johnbillion
4 years ago

#2 @johnbillion
4 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 4 years ago by johnbillion (previous) (diff)

@johnbillion
4 years ago

@johnbillion
4 years ago

#3 @johnbillion
4 years ago

34059.4.diff includes updated tests for multisite.

#4 @wonderboymusic
4 years ago

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

#5 @DrewAPicture
4 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

@johnbillion
4 years ago

#6 @johnbillion
4 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
4 years ago

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

Looks good otherwise.

#8 @SergeyBiryukov
4 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
4 years ago

In 34801:

Add missing unit tests from [34799].

Props johnbillion.
See #34059.

Note: See TracTickets for help on using tickets.