View source
<?php
namespace Drupal\Tests\message_digest\Kernel;
use Drupal\message\Entity\Message;
class TokenTest extends DigestTestBase {
public static $modules = [
'token',
];
public function testTokenReplacement() {
$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);
$messages[$i]
->save();
$messages[$i]
->setOwner($actual_recipient);
$this->notifierSender
->send($messages[$i], [], 'message_digest:daily');
}
$this
->sendDigests();
$this
->assertMail('to', $actual_recipient
->getEmail());
$email = $this
->getMails();
$this
->assertTrue(strpos($email[0]['body'], $actual_recipient
->getDisplayName()) !== FALSE);
$this
->assertTrue(strpos($email[0]['body'], 'Dummy title') !== FALSE);
}
public function testTokenRemoveEmailSubject() {
\Drupal::state()
->set('message_digest_test_remove_view_mode', 'mail_subject');
$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);
$messages[$i]
->save();
$messages[$i]
->setOwner($actual_recipient);
$this->notifierSender
->send($messages[$i], [], 'message_digest:daily');
}
$this
->sendDigests();
$this
->assertMail('to', $actual_recipient
->getEmail());
$email = $this
->getMails();
$this
->assertTrue(strpos($email[0]['body'], $actual_recipient
->getDisplayName()) !== FALSE);
$this
->assertSame(FALSE, strpos($email[0]['body'], 'Dummy title'));
}
}