public function MessageDigestTest::testOrphanedMessage in Message Digest 8
Tests that a message is not sent if its owner has been deleted.
File
- tests/
src/ Kernel/ MessageDigestTest.php, line 548
Class
- MessageDigestTest
- Kernel tests for Message Digest.
Namespace
Drupal\Tests\message_digest\KernelCode
public function testOrphanedMessage() {
// Create a test user.
$user = $this
->createUser();
// Create a test message owned by the test user.
$template = $this
->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
$message = Message::create([
'template' => $template
->id(),
]);
/** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $digest_notifier */
$digest_notifier = $this->notifierManager
->createInstance('message_digest:daily', [], $message);
$message
->setOwner($user);
$message
->save();
// Delete the user.
$user
->delete();
// Deliver the message and send out the digests.
$this->notifierSender
->send($message, [], $digest_notifier
->getPluginId());
$this
->sendDigests();
// Check that no mails have been sent.
$this
->assertEmpty($this
->getMails());
}