public function MailTest::testCancelMessage in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testCancelMessage()
Tests that message sending may be canceled.
See also
File
- core/
modules/ system/ tests/ src/ Kernel/ Mail/ MailTest.php, line 95
Class
- MailTest
- Performs tests on the pluggable mailing framework.
Namespace
Drupal\Tests\system\Kernel\MailCode
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.
// Message was canceled.
$this
->assertFalse($sent_message);
}