Skip to content

Commit 880b3ff

Browse files
committed
Mock functionality removed from "comment_duplicate_trigger()" callback test.
1 parent 617a1db commit 880b3ff

File tree

2 files changed

+17
-52
lines changed

2 files changed

+17
-52
lines changed

connectors/class-connector-comments.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ public function callback_comment_duplicate_trigger( $comment_data ) {
615615
global $wpdb;
616616
unset( $comment_data );
617617

618+
if ( ! empty( $wpdb->last_result ) ) {
619+
return;
620+
}
621+
618622
$comment_id = $wpdb->last_result[0]->comment_ID;
619623
$comment = get_comment( $comment_id );
620624

tests/tests/connectors/test-class-connector-comments.php

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function test_callback_wp_insert_comment() {
9696
]
9797
);
9898

99-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_wp_insert_comment' ) );
99+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_wp_insert_comment' ) );
100100
}
101101

102102
public function test_callback_edit_comment() {
@@ -149,7 +149,7 @@ public function test_callback_edit_comment() {
149149
]
150150
);
151151

152-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_edit_comment' ) );
152+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_edit_comment' ) );
153153
}
154154

155155
public function test_callback_delete_comment() {
@@ -197,7 +197,7 @@ public function test_callback_delete_comment() {
197197
// Do stuff.
198198
wp_delete_comment( $comment_id, true );
199199

200-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_comment' ) );
200+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_delete_comment' ) );
201201
}
202202

203203
public function test_callback_trash_comment() {
@@ -245,7 +245,7 @@ public function test_callback_trash_comment() {
245245
// Do stuff.
246246
wp_trash_comment( $comment_id );
247247

248-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_trash_comment' ) );
248+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_trash_comment' ) );
249249
}
250250

251251
public function test_callback_untrash_comment() {
@@ -294,7 +294,7 @@ public function test_callback_untrash_comment() {
294294
// Do stuff.
295295
wp_untrash_comment( $comment_id );
296296

297-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_untrash_comment' ) );
297+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_untrash_comment' ) );
298298
}
299299

300300
public function test_callback_spam_comment() {
@@ -342,7 +342,7 @@ public function test_callback_spam_comment() {
342342
// Do stuff.
343343
wp_spam_comment( $comment_id );
344344

345-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_spam_comment' ) );
345+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_spam_comment' ) );
346346
}
347347

348348
public function test_callback_unspam_comment() {
@@ -391,7 +391,7 @@ public function test_callback_unspam_comment() {
391391
// Do stuff.
392392
wp_unspam_comment( $comment_id );
393393

394-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_unspam_comment' ) );
394+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_unspam_comment' ) );
395395
}
396396

397397
public function test_callback_transition_comment_status() {
@@ -441,7 +441,7 @@ public function test_callback_transition_comment_status() {
441441
// Do stuff.
442442
wp_transition_comment_status( 'hold', 'pending approval', get_comment( $comment_id ) );
443443

444-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_transition_comment_status' ) );
444+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_transition_comment_status' ) );
445445
}
446446

447447
public function test_callback_comment_duplicate_trigger() {
@@ -463,59 +463,20 @@ public function test_callback_comment_duplicate_trigger() {
463463
]
464464
);
465465

466-
$this->mock->expects( $this->atLeastOnce() )
467-
->method( 'log' )
468-
->with(
469-
$this->equalTo(
470-
_x(
471-
'Duplicate %3$s by %1$s prevented on %2$s',
472-
'1: Comment author, 2: Post title, 3: Comment type',
473-
'stream'
474-
)
475-
),
476-
$this->equalTo(
477-
[
478-
'user_name' => 'Jim Bean',
479-
'post_title' => '"Test post"',
480-
'comment_type' => 'comment',
481-
'post_id' => "$post_id",
482-
'user_id' => 0,
483-
]
484-
),
485-
$this->equalTo( $comment_id ),
486-
$this->equalTo( 'post' ),
487-
$this->equalTo( 'duplicate' )
488-
);
489-
490-
// Do stuff.
466+
// Create duplicate comment and trigger mock.
491467
wp_new_comment(
492-
[
468+
array(
493469
'comment_content' => 'Lorem ipsum dolor...',
494470
'comment_author' => 'Jim Bean',
495471
'comment_author_email' => 'jim_bean@example.com',
496472
'comment_author_url' => '',
497473
'comment_author_IP' => '::1',
498474
'comment_post_ID' => $post_id,
499-
],
475+
'comment_type' => 'post',
476+
),
500477
true
501478
);
502-
$comment_id = wp_new_comment( $commentdata );
503-
504-
// Manually execute SQL query for duplicate comment ID. "$wpdb->last_result[0]" Undefined index error.
505-
$dupe = $wpdb->prepare(
506-
"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",
507-
wp_unslash( $commentdata['comment_post_ID'] ),
508-
wp_unslash( $commentdata['comment_parent'] ),
509-
wp_unslash( $commentdata['comment_author'] ),
510-
wp_unslash( $commentdata['comment_author_email'] ),
511-
wp_unslash( $commentdata['comment_content'] )
512-
);
513-
$dupe_id = $wpdb->get_var( $dupe );
514-
$this->assertSame( $comment_id, absint( $dupe_id ) );
515-
516-
// Run trigger action.
517-
do_action( 'comment_duplicate_trigger', $commentdata );
518479

519-
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_comment_duplicate_trigger' ) );
480+
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_comment_duplicate_trigger' ) );
520481
}
521482
}

0 commit comments

Comments
 (0)