function MailTest::testCancelMessage
Same name in other branches
- 9 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testCancelMessage()
- 8.9.x core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testCancelMessage()
- 11.x 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 106
Class
- MailTest
- Performs tests on the pluggable mailing framework.
Namespace
Drupal\Tests\system\Kernel\MailCode
public function testCancelMessage() : void {
$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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.