You are here

public function UserNotificationEmailTest::testANotificationEmailIsSent in Private Message 8

Test that notification emails are sent when a private message is created.

File

tests/src/Kernel/UserNotificationEmailTest.php, line 69

Class

UserNotificationEmailTest
Tests notification emails when a new private message is created.

Namespace

Drupal\Tests\private_message\Kernel

Code

public function testANotificationEmailIsSent() {
  $settings = \Drupal::config('private_message.settings')
    ->getRawData();
  $this
    ->assertTrue($settings['enable_email_notifications']);
  $this
    ->assertTrue($settings['send_by_default']);
  $owner = $this
    ->createUser();
  $member1 = $this
    ->createUser([
    'mail' => 'member1@example.com',
  ]);
  \Drupal::currentUser()
    ->setAccount($owner);
  $message = $this
    ->createMessage([
    'owner' => $owner,
  ]);
  $this->threadManager
    ->saveThread($message, [
    $owner,
    $member1,
  ]);
  $mails = $this
    ->getMails();

  // There should only be one email sent, as the current user should not
  // receive an email.
  $this
    ->assertCount(1, $mails);

  // Assert that the correct email was sent, and to the right e-mail address.
  $this
    ->assertEquals('private_message_message_notification', $mails[0]['id']);
  $this
    ->assertEquals('member1@example.com', $mails[0]['to']);
}