You are here

public function MailTest::testCancelMessage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Mail/MailTest.php \Drupal\system\Tests\Mail\MailTest::testCancelMessage()

Test that message sending may be canceled.

See also

simpletest_mail_alter()

File

core/modules/system/src/Tests/Mail/MailTest.php, line 58
Contains \Drupal\system\Tests\Mail\MailTest.

Class

MailTest
Performs tests on the pluggable mailing framework.

Namespace

Drupal\system\Tests\Mail

Code

public function testCancelMessage() {
  $language_interface = \Drupal::languageManager()
    ->getCurrentLanguage();

  // Use the state system collector mail backend.
  $this
    ->config('system.mail')
    ->set('interface.default', 'test_mail_collector')
    ->save();

  // Reset the state variable that holds sent messages.
  \Drupal::state()
    ->set('system.test_mail_collector', array());

  // Send a test message that simpletest_mail_alter should cancel.
  \Drupal::service('plugin.manager.mail')
    ->mail('simpletest', '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.
  $this
    ->assertFalse($sent_message, 'Message was canceled.');
}