Skip to content

Commit

Permalink
CommentNotification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Feb 20, 2017
1 parent 0904cfd commit ca89083
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions tests/phpunit/tests/CommentNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

namespace Required\Digest\Tests;

use \WP_UnitTestCase;
use \Required\Digest\Message\CommentNotification as CommentNotificationMessage;

class CommentNotification extends WP_UnitTestCase {
public function test_no_entries() {
$message = new CommentNotificationMessage( array() );

$this->assertContains( 'There were 0 new comments', $message->get_message() );
$this->assertNotContains( 'already moderated.', $message->get_message() );
}

public function test_invalid_entry() {
$message = new CommentNotificationMessage( array(
'123' => time(),
) );

$this->assertContains( 'There was 1 new comment', $message->get_message() );
$this->assertContains( '1 comment was already moderated.', $message->get_message() );
}

public function test_already_processed_entry() {
$comment_id = self::factory()->comment->create();

$message = new CommentNotificationMessage( array(
$comment_id => time(),
) );

$this->assertContains( 'There was 1 new comment', $message->get_message() );
}

public function test_comment_action_links() {
$comment_id = self::factory()->comment->create( array(
'comment_approved' => 0,
) );

$user = self::factory()->user->create_and_get( array(
'role' => 'administrator',
'email' => '[email protected]',
) );

$message = new CommentNotificationMessage( array(
$comment_id => time(),
), $user );

$this->assertNotContains( 'Approve', $message->get_message() );
$this->assertContains( 'Trash', $message->get_message() );
$this->assertContains( 'Spam', $message->get_message() );
}

public function test_comment_action_links_no_capabilities() {
$comment_id = self::factory()->comment->create( array(
'comment_approved' => 0,
) );

$user = self::factory()->user->create_and_get( array(
'role' => 'subscriber',
'email' => '[email protected]',
) );

$message = new CommentNotificationMessage( array(
$comment_id => time(),
), $user );

$this->assertNotContains( 'Trash', $message->get_message() );
$this->assertNotContains( 'Spam', $message->get_message() );
}

public function test_pingback() {
$comment_id = self::factory()->comment->create( array(
'comment_approved' => 0,
'comment_type' => 'pingback',
) );

$message = new CommentNotificationMessage( array(
$comment_id => time(),
) );

$this->assertContains( 'Pingback on ', $message->get_message() );
}

public function test_trackback() {
$comment_id = self::factory()->comment->create( array(
'comment_approved' => 0,
'comment_type' => 'trackback',
) );

$message = new CommentNotificationMessage( array(
$comment_id => time(),
) );

$this->assertContains( 'Trackback on ', $message->get_message() );
}

public function test_comment_author_url() {
$comment_id = self::factory()->comment->create( array(
'comment_approved' => 0,
'comment_author_url' => 'http://example.com'
) );

$message = new CommentNotificationMessage( array(
$comment_id => time(),
) );

$this->assertContains( 'http://example.com', $message->get_message() );
}

public function test_comment_author_email() {
$comment_id = self::factory()->comment->create( array(
'comment_approved' => 0,
'comment_author_email' => '[email protected]'
) );

$message = new CommentNotificationMessage( array(
$comment_id => time(),
) );

$this->assertContains( '[email protected]', $message->get_message() );
}
}

0 comments on commit ca89083

Please sign in to comment.