public function MessageSubscribeEmailSubscribersTest::testWithDefaultNotifiers in Message Subscribe 8
Tests behavior with the default notifiers in place.
File
- message_subscribe_email/
tests/ src/ Kernel/ MessageSubscribeEmailSubscribersTest.php, line 70
Class
- MessageSubscribeEmailSubscribersTest
- Test getting email subscribes from context.
Namespace
Drupal\Tests\message_subscribe_email\KernelCode
public function testWithDefaultNotifiers() {
$this
->config('message_subscribe.settings')
->set('default_notifiers', [
'email',
])
->save();
$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 user 1 was sent an email.');
$this
->assertEquals('message_notify_' . $this->messageTemplate
->id(), $mails[0]['id']);
}