public function TokenTest::testTokenReplacement in Message Digest 8
Tests token replacement when rendering digests.
File
- tests/
src/ Kernel/ TokenTest.php, line 24
Class
- TokenTest
- Tests basic token integration for formmatted message digests.
Namespace
Drupal\Tests\message_digest\KernelCode
public function testTokenReplacement() {
// Send several messages.
$template = $this
->createMessageTemplate('foo', 'Foo', 'Foo, foo', [
'Dummy title',
'Hello [message:author:display-name]!',
]);
$original_message_author = $this
->createUser();
$actual_recipient = $this
->createUser();
$messages = [];
foreach (range(1, 3) as $i) {
$messages[$i] = Message::create([
'template' => $template
->id(),
]);
$messages[$i]
->setOwner($original_message_author);
// Message is saved with the original author, but sent to a new recipient.
$messages[$i]
->save();
$messages[$i]
->setOwner($actual_recipient);
$this->notifierSender
->send($messages[$i], [], 'message_digest:daily');
}
// Send the digest.
$this
->sendDigests();
$this
->assertMail('to', $actual_recipient
->getEmail());
// Verify that the token in the template is the proper user.
$email = $this
->getMails();
$this
->assertTrue(strpos($email[0]['body'], $actual_recipient
->getDisplayName()) !== FALSE);
$this
->assertTrue(strpos($email[0]['body'], 'Dummy title') !== FALSE);
}