You are here

public function MessageSubscribeEmailSubscribersTest::testGetSubscribers in Message Subscribe 8

Test getting the subscribers list.

File

message_subscribe_email/tests/src/Kernel/MessageSubscribeEmailSubscribersTest.php, line 39

Class

MessageSubscribeEmailSubscribersTest
Test getting email subscribes from context.

Namespace

Drupal\Tests\message_subscribe_email\Kernel

Code

public function testGetSubscribers() {
  $message = Message::create([
    'template' => $this->messageTemplate
      ->id(),
  ]);
  $node = $this->nodes[1];
  $user1 = $this->users[1];
  $user2 = $this->users[2];
  $uids = $this->messageSubscribers
    ->getSubscribers($node, $message);

  // Assert subscribers data.
  $expected_uids = [
    $user1
      ->id() => new DeliveryCandidate([
      'subscribe_node',
    ], [
      'email',
    ], $user1
      ->id()),
    $user2
      ->id() => new DeliveryCandidate([
      'subscribe_node',
    ], [], $user2
      ->id()),
  ];
  $this
    ->assertEquals($expected_uids, $uids, 'All expected subscribers were fetched.');
  $subscribe_options = [
    'uids' => $uids,
  ];
  $this->messageSubscribers
    ->sendMessage($node, $message, [], $subscribe_options);

  // Assert sent emails.
  $mails = $this
    ->getMails();
  $this
    ->assertEquals(1, count($mails), 'Only one user was sent an email.');
  $this
    ->assertEquals('message_notify_' . $this->messageTemplate
    ->id(), $mails[0]['id']);
}