Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listeners for comment approval and unapproval actions #6899

Merged
merged 4 commits into from Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions sync/class.jetpack-sync-module-comments.php
Expand Up @@ -22,6 +22,8 @@ public function init_listeners( $callable ) {
add_action( 'spammed_comment', $callable );
add_action( 'trashed_post_comments', $callable, 10, 2 );
add_action( 'untrash_post_comments', $callable );
add_action( 'comment_approved_to_unapproved', $callable );
add_action( 'comment_unapproved_to_approved', $callable );

// even though it's messy, we implement these hooks because
// the edit_comment hook doesn't include the data
Expand Down
48 changes: 48 additions & 0 deletions tests/php/sync/test_class.jetpack-sync-comments.php
Expand Up @@ -47,6 +47,47 @@ public function test_update_comment() {
$this->assertEquals( "foo bar baz", $remote_comment->comment_content );
}

public function test_unapprove_comment() {

$this->assertEquals( 1, $this->server_replica_storage->comment_count( 'approve' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to use space to group the different tests that are happening here a bit better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


$this->comment->comment_approved = 0;

wp_update_comment( (array) $this->comment );

$this->sender->do_sync();

$this->assertEquals( 0, $this->server_replica_storage->comment_count( 'approve' ) );

$remote_comment = $this->server_replica_storage->get_comment( $this->comment->comment_ID );

$this->assertEquals( 0, $remote_comment->comment_approved );

$comment_unapproved_event = $this->server_event_storage->get_most_recent_event( 'comment_unapproved_' );

$this->assertTrue( (bool) $comment_unapproved_event );

$comment_approved_to_unapproved_event = $this->server_event_storage->get_most_recent_event( 'comment_approved_to_unapproved' );

$this->assertTrue( (bool) $comment_approved_to_unapproved_event );

//Make sure we don't get the same event about the comment changing state

$this->server_event_storage->reset();

wp_update_comment( (array) $this->comment );

$this->sender->do_sync();

$comment_unapproved_event = $this->server_event_storage->get_most_recent_event( 'comment_unapproved_' );

$this->assertTrue( (bool) $comment_unapproved_event );

$comment_approved_to_unapproved_event = $this->server_event_storage->get_most_recent_event( 'comment_approved_to_unapproved' );

$this->assertFalse( (bool) $comment_approved_to_unapproved_event );
}

public function test_trash_comment_trashes_data() {
$this->assertEquals( 1, $this->server_replica_storage->comment_count( 'approve' ) );
wp_delete_comment( $this->comment->comment_ID );
Expand Down Expand Up @@ -75,6 +116,13 @@ public function test_wp_trash_comment() {

$this->assertEquals( 0, $this->server_replica_storage->comment_count( 'approve' ) );
$this->assertEquals( 1, $this->server_replica_storage->comment_count( 'trash' ) );

//Test that you don't get an event back when you try to trash the same comment again
$this->server_event_storage->reset();
wp_trash_comment( $this->comment->comment_ID );
$this->sender->do_sync();
$event = $this->server_event_storage->get_most_recent_event( 'trashed_comment' );
$this->assertFalse( $event );
}

public function test_wp_untrash_comment() {
Expand Down