From be6d801186e3115b21bdbc31b832d3ae3509467d Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 8 Jul 2020 19:21:35 -0400 Subject: [PATCH 1/7] Comment connector test created. --- .../test-class-connector-comments.php | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/tests/connectors/test-class-connector-comments.php diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php new file mode 100644 index 000000000..91d24898f --- /dev/null +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -0,0 +1,113 @@ +date = '2007-07-04 12:30:00'; + $this->date_gmt = get_gmt_from_date( $this->date ); + + // Make partial of Connector_ACF class, with mocked "log" function. + $this->mock = $this->getMockBuilder( Connector_Comments::class ) + ->setMethods( [ 'log' ] ) + ->getMock(); + + // Register connector. + $this->mock->register(); + } + + public function test_callback_wp_insert_comment() { + $user_id = self::factory()->user->create( + [ + 'user_login' => 'johndoe', + 'role' => 'editor', + ] + ); + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->withConsecutive( + [ + $this->equalTo( + _x( + 'New %4$s by %1$s on %2$s %3$s', + '1: Comment author, 2: Post title 3: Comment status, 4: Comment type', + 'stream' + ) + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_status' => 'pending approval', + 'comment_type' => 'comment', + 'post_id' => $post_id, + 'is_spam' => false, + ] + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'created' ), + $this->equalTo( 0 ) + ], + [ + $this->equalTo( + _x( + 'Reply to %1$s\'s %5$s by %2$s on %3$s %4$s', + "1: Parent comment's author, 2: Comment author, 3: Post title, 4: Comment status, 5: Comment type", + 'stream' + ) + ), + $this->equalTo( + [ + 'parent_user_name' => 'Jim Bean', + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_status' => 'pending approval', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + ] + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'replied' ), + $this->equalTo( 0 ) + ], + ); + + // Do stuff. + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + 'comment_parent' => $comment_id, + ] + ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_wp_insert_comment' ) ); + } + +} From e421ebd7ccb00a80b488572f29288d8b944e5662 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 8 Jul 2020 20:32:52 -0400 Subject: [PATCH 2/7] Comment connector test updated. --- .../test-class-connector-comments.php | 413 +++++++++++++++++- 1 file changed, 402 insertions(+), 11 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index 91d24898f..4021e25e2 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -2,15 +2,10 @@ namespace WP_Stream; class Test_WP_Stream_Connector_Comments extends WP_StreamTestCase { - private $date; - private $date_gmt; public function setUp() { parent::setUp(); - $this->date = '2007-07-04 12:30:00'; - $this->date_gmt = get_gmt_from_date( $this->date ); - // Make partial of Connector_ACF class, with mocked "log" function. $this->mock = $this->getMockBuilder( Connector_Comments::class ) ->setMethods( [ 'log' ] ) @@ -21,12 +16,6 @@ public function setUp() { } public function test_callback_wp_insert_comment() { - $user_id = self::factory()->user->create( - [ - 'user_login' => 'johndoe', - 'role' => 'editor', - ] - ); $post_id = wp_insert_post( [ 'post_title' => 'Test post', @@ -110,4 +99,406 @@ public function test_callback_wp_insert_comment() { $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_wp_insert_comment' ) ); } + public function test_callback_edit_comment() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s on %2$s edited', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ) + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'edited' ) + ); + + // Do stuff. + wp_update_comment( + [ + 'comment_ID' => $comment_id, + 'comment_content' => 'Lorem ipsum dolor... 2', + ] + ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_edit_comment' ) ); + } + + public function test_callback_delete_comment() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s on %2$s deleted permanently', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ) + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'deleted' ) + ); + + // Do stuff. + wp_delete_comment( $comment_id, true ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_comment' ) ); + } + + public function test_callback_trash_comment() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s on %2$s trashed', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ) + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'trashed' ) + ); + + // Do stuff. + wp_trash_comment( $comment_id ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_trash_comment' ) ); + } + + public function test_callback_untrash_comment() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + wp_trash_comment( $comment_id ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s on %2$s restored', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ), + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'untrashed' ) + ); + + // Do stuff. + wp_untrash_comment( $comment_id ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_untrash_comment' ) ); + } + + public function test_callback_spam_comment() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s on %2$s marked as spam', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ), + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'spammed' ) + ); + + // Do stuff. + wp_spam_comment( $comment_id ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_spam_comment' ) ); + } + + public function test_callback_unspam_comment() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + wp_spam_comment( $comment_id ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s on %2$s unmarked as spam', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ), + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'unspammed' ) + ); + + // Do stuff. + wp_unspam_comment( $comment_id ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_unspam_comment' ) ); + } + + public function test_callback_transition_comment_status() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '%1$s\'s %3$s %2$s', + 'Comment status transition. 1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ) + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'new_status' => 'unapproved', + 'comment_type' => 'comment', + 'old_status' => 'pending approval', + 'post_title' => '"Test post"', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'unapproved' ) + ); + + // Do stuff. + wp_transition_comment_status( 'hold', 'pending approval', get_comment( $comment_id ) ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_transition_comment_status' ) ); + } + + public function test_callback_comment_duplicate_trigger() { + $post_id = wp_insert_post( + [ + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ] + ); + $comment_id = wp_insert_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ] + ); + + $this->mock->expects( $this->atLeastOnce() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + 'Duplicate %3$s by %1$s prevented on %2$s', + '1: Comment author, 2: Post title, 3: Comment type', + 'stream' + ), + ), + $this->equalTo( + [ + 'user_name' => 'Jim Bean', + 'post_title' => '"Test post"', + 'comment_type' => 'comment', + 'post_id' => "$post_id", + 'user_id' => 0, + ] + ), + $this->equalTo( $comment_id ), + $this->equalTo( 'post' ), + $this->equalTo( 'duplicate' ) + ); + + // Do stuff. + wp_new_comment( + [ + 'comment_content' => 'Lorem ipsum dolor...', + 'comment_author' => 'Jim Bean', + 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_url' => '', + 'comment_author_IP' => '::1', + 'comment_post_ID' => $post_id, + ], + true + ); + + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_comment_duplicate_trigger' ) ); + } } From 25507e3f3833cb0a574274b6a3fbe81342c90916 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Thu, 9 Jul 2020 09:12:10 -0400 Subject: [PATCH 3/7] Syntax error fixed --- tests/tests/connectors/test-class-connector-comments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index 4021e25e2..e59afc743 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -72,7 +72,7 @@ public function test_callback_wp_insert_comment() { $this->equalTo( 'post' ), $this->equalTo( 'replied' ), $this->equalTo( 0 ) - ], + ] ); // Do stuff. From 77d3d9cf9efb4bc8dedfc9425e612896e976b797 Mon Sep 17 00:00:00 2001 From: Geoffrey K Taylor Date: Thu, 9 Jul 2020 10:10:15 -0400 Subject: [PATCH 4/7] Syntax error fixed --- tests/tests/connectors/test-class-connector-comments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index e59afc743..ff5b211eb 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -275,7 +275,7 @@ public function test_callback_untrash_comment() { '%1$s\'s %3$s on %2$s restored', '1: Comment author, 2: Post title, 3: Comment type', 'stream' - ), + ) ), $this->equalTo( [ From ab29de52bedb100af72c28d656ada32ca01c3cef Mon Sep 17 00:00:00 2001 From: Geoffrey K Taylor Date: Thu, 9 Jul 2020 10:38:50 -0400 Subject: [PATCH 5/7] All syntax errors fixed --- tests/tests/connectors/test-class-connector-comments.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index ff5b211eb..50b0dfcf7 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -323,7 +323,7 @@ public function test_callback_spam_comment() { '%1$s\'s %3$s on %2$s marked as spam', '1: Comment author, 2: Post title, 3: Comment type', 'stream' - ), + ) ), $this->equalTo( [ @@ -372,7 +372,7 @@ public function test_callback_unspam_comment() { '%1$s\'s %3$s on %2$s unmarked as spam', '1: Comment author, 2: Post title, 3: Comment type', 'stream' - ), + ) ), $this->equalTo( [ @@ -470,7 +470,7 @@ public function test_callback_comment_duplicate_trigger() { 'Duplicate %3$s by %1$s prevented on %2$s', '1: Comment author, 2: Post title, 3: Comment type', 'stream' - ), + ) ), $this->equalTo( [ From 617a1db4cde25ab62244c351a0dcaa6f2363bdbb Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 24 Jul 2020 11:15:54 -0400 Subject: [PATCH 6/7] Comment connector test updated. --- .../test-class-connector-comments.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index 50b0dfcf7..11fdb8463 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -457,6 +457,7 @@ public function test_callback_comment_duplicate_trigger() { 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_url' => '', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, ] @@ -498,6 +499,22 @@ public function test_callback_comment_duplicate_trigger() { ], true ); + $comment_id = wp_new_comment( $commentdata ); + + // Manually execute SQL query for duplicate comment ID. "$wpdb->last_result[0]" Undefined index error. + $dupe = $wpdb->prepare( + "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s AND comment_author_email = %s ) AND comment_content = %s LIMIT 1", + wp_unslash( $commentdata['comment_post_ID'] ), + wp_unslash( $commentdata['comment_parent'] ), + wp_unslash( $commentdata['comment_author'] ), + wp_unslash( $commentdata['comment_author_email'] ), + wp_unslash( $commentdata['comment_content'] ) + ); + $dupe_id = $wpdb->get_var( $dupe ); + $this->assertSame( $comment_id, absint( $dupe_id ) ); + + // Run trigger action. + do_action( 'comment_duplicate_trigger', $commentdata ); $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_comment_duplicate_trigger' ) ); } From 880b3ff7426893601d104f7e6470283c24dd789f Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 11 Dec 2020 18:08:40 -0500 Subject: [PATCH 7/7] Mock functionality removed from "comment_duplicate_trigger()" callback test. --- connectors/class-connector-comments.php | 4 ++ .../test-class-connector-comments.php | 65 ++++--------------- 2 files changed, 17 insertions(+), 52 deletions(-) diff --git a/connectors/class-connector-comments.php b/connectors/class-connector-comments.php index 81c4dd0af..ac3274b3a 100644 --- a/connectors/class-connector-comments.php +++ b/connectors/class-connector-comments.php @@ -615,6 +615,10 @@ public function callback_comment_duplicate_trigger( $comment_data ) { global $wpdb; unset( $comment_data ); + if ( ! empty( $wpdb->last_result ) ) { + return; + } + $comment_id = $wpdb->last_result[0]->comment_ID; $comment = get_comment( $comment_id ); diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index 11fdb8463..ec8dae33a 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -96,7 +96,7 @@ public function test_callback_wp_insert_comment() { ] ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_wp_insert_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_wp_insert_comment' ) ); } public function test_callback_edit_comment() { @@ -149,7 +149,7 @@ public function test_callback_edit_comment() { ] ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_edit_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_edit_comment' ) ); } public function test_callback_delete_comment() { @@ -197,7 +197,7 @@ public function test_callback_delete_comment() { // Do stuff. wp_delete_comment( $comment_id, true ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_delete_comment' ) ); } public function test_callback_trash_comment() { @@ -245,7 +245,7 @@ public function test_callback_trash_comment() { // Do stuff. wp_trash_comment( $comment_id ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_trash_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_trash_comment' ) ); } public function test_callback_untrash_comment() { @@ -294,7 +294,7 @@ public function test_callback_untrash_comment() { // Do stuff. wp_untrash_comment( $comment_id ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_untrash_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_untrash_comment' ) ); } public function test_callback_spam_comment() { @@ -342,7 +342,7 @@ public function test_callback_spam_comment() { // Do stuff. wp_spam_comment( $comment_id ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_spam_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_spam_comment' ) ); } public function test_callback_unspam_comment() { @@ -391,7 +391,7 @@ public function test_callback_unspam_comment() { // Do stuff. wp_unspam_comment( $comment_id ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_unspam_comment' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_unspam_comment' ) ); } public function test_callback_transition_comment_status() { @@ -441,7 +441,7 @@ public function test_callback_transition_comment_status() { // Do stuff. wp_transition_comment_status( 'hold', 'pending approval', get_comment( $comment_id ) ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_transition_comment_status' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_transition_comment_status' ) ); } public function test_callback_comment_duplicate_trigger() { @@ -463,59 +463,20 @@ public function test_callback_comment_duplicate_trigger() { ] ); - $this->mock->expects( $this->atLeastOnce() ) - ->method( 'log' ) - ->with( - $this->equalTo( - _x( - 'Duplicate %3$s by %1$s prevented on %2$s', - '1: Comment author, 2: Post title, 3: Comment type', - 'stream' - ) - ), - $this->equalTo( - [ - 'user_name' => 'Jim Bean', - 'post_title' => '"Test post"', - 'comment_type' => 'comment', - 'post_id' => "$post_id", - 'user_id' => 0, - ] - ), - $this->equalTo( $comment_id ), - $this->equalTo( 'post' ), - $this->equalTo( 'duplicate' ) - ); - - // Do stuff. + // Create duplicate comment and trigger mock. wp_new_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_url' => '', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ], + 'comment_type' => 'post', + ), true ); - $comment_id = wp_new_comment( $commentdata ); - - // Manually execute SQL query for duplicate comment ID. "$wpdb->last_result[0]" Undefined index error. - $dupe = $wpdb->prepare( - "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s AND comment_author_email = %s ) AND comment_content = %s LIMIT 1", - wp_unslash( $commentdata['comment_post_ID'] ), - wp_unslash( $commentdata['comment_parent'] ), - wp_unslash( $commentdata['comment_author'] ), - wp_unslash( $commentdata['comment_author_email'] ), - wp_unslash( $commentdata['comment_content'] ) - ); - $dupe_id = $wpdb->get_var( $dupe ); - $this->assertSame( $comment_id, absint( $dupe_id ) ); - - // Run trigger action. - do_action( 'comment_duplicate_trigger', $commentdata ); - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_comment_duplicate_trigger' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_comment_duplicate_trigger' ) ); } }