// Test without errors displayed to users.
\Drupal::
service('plugin.manager.mail'
)->
mail('default', 'default', 'test@example.com', 'en',
['_error_message' => ''
]);
$this->
assertEmpty(\Drupal::
messenger()->
messagesByType(MessengerInterface::TYPE_ERROR
));
} /**
* Tests that message sending may be canceled.
*
* @see mail_cancel_test_mail_alter()
*/
public function testCancelMessage() { $language_interface = \Drupal::
languageManager()->
getCurrentLanguage();
// Reset the state variable that holds sent messages.
\Drupal::
state()->
set('system.test_mail_collector',
[]);
// Send a test message that mail_cancel_test_alter should cancel.
\Drupal::
service('plugin.manager.mail'
)->
mail('mail_cancel_test', 'cancel_test', 'cancel@example.com',
$language_interface->
getId());
// Retrieve sent message.
$captured_emails = \Drupal::
state()->
get('system.test_mail_collector'
);
$sent_message =
end($captured_emails);
// Assert that the message was not actually sent.