public function MessageNotifyTest::testPostSendMessageSave in Message Notify 8
Test Message save on delivery.
File
- tests/
src/ Kernel/ MessageNotifyTest.php, line 92
Class
- MessageNotifyTest
- Test the Message notifier plugins handling.
Namespace
Drupal\Tests\message_notify\KernelCode
public function testPostSendMessageSave() {
$account = User::create([
'name' => $this
->randomMachineName(),
]);
$account
->save();
$message = Message::create([
'template' => $this->messageTemplate
->id(),
'uid' => $account
->id(),
]);
$message->fail = FALSE;
$this->messageNotifier
->send($message, [], 'test');
$this
->assertTrue($message
->id(), 'Message saved after successful delivery.');
$message = Message::create([
'template' => $this->messageTemplate
->id(),
'uid' => $account
->id(),
]);
$message->fail = TRUE;
$this->messageNotifier
->send($message, [], 'test');
$this
->assertFalse($message
->id(), 'Message not saved after unsuccessful delivery.');
// Disable saving Message on delivery.
$options = [
'save on fail' => FALSE,
'save on success' => FALSE,
];
$message = Message::create([
'template' => $this->messageTemplate
->id(),
'uid' => $account
->id(),
]);
// @todo See above.
$message->fail = FALSE;
$this->messageNotifier
->send($message, $options, 'test');
$this
->assertTrue($message
->isNew(), 'Message not saved after successful delivery.');
$message = Message::create([
'template' => $this->messageTemplate
->id(),
'uid' => $account
->id(),
]);
$message->fail = TRUE;
$this->messageNotifier
->send($message, $options, 'test');
$this
->assertTrue($message
->isNew(), 'Message not saved after unsuccessful delivery.');
}