You are here

public function MailhandlerCommentTest::testMailhandlerCommentPluginAuthenticated in Mailhandler 8

Tests features of Mailhandler Comment plugin for authenticated users.

File

mailhandler_comment/tests/src/Kernel/MailhandlerCommentTest.php, line 139

Class

MailhandlerCommentTest
Tests the Comment handler plugin.

Namespace

Drupal\Tests\mailhandler_comment\Kernel

Code

public function testMailhandlerCommentPluginAuthenticated() {

  // Get a sample comment mail message.
  $raw_comment_mail = $this
    ->getFileContent('eml/Comment.eml');

  // Replace a node ID with an actual node ID.
  $raw_comment_mail = str_replace('[comment][#1]', '[comment][#' . $this->node
    ->id() . ']', $raw_comment_mail);

  // Enable "From" authentication since it is disabled by default.
  $sender_analyzer = AnalyzerConfig::load('sender');
  $sender_analyzer
    ->enable()
    ->save();

  // Trigger the processing.
  $this->processor
    ->process('test_key', $raw_comment_mail, $this->deliverer);
  $comments = Comment::loadMultiple();
  $this
    ->assertEquals(count($comments), 1, 'There is a new comment created.');

  /** @var \Drupal\comment\CommentInterface $comment */
  $comment = end($comments);
  $this
    ->assertEquals($this->user
    ->getDisplayName(), $comment
    ->getAuthorName());
  $this
    ->assertEquals($this->user
    ->id(), $comment
    ->getOwnerId());
  $this
    ->assertEquals(CommentInterface::PUBLISHED, $comment
    ->getStatus());
  $this
    ->assertEquals('Great article!', $comment
    ->getSubject());
}