You are here

public function MailTest::testErrorMessageDisplay in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testErrorMessageDisplay()
  2. 9 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testErrorMessageDisplay()

Assert that the pluggable mail system is functional.

File

core/modules/system/tests/src/Kernel/Mail/MailTest.php, line 75

Class

MailTest
Performs tests on the pluggable mailing framework.

Namespace

Drupal\Tests\system\Kernel\Mail

Code

public function testErrorMessageDisplay() {

  // Switch mail backends.
  $this
    ->configureDefaultMailInterface('test_php_mail_failure');

  // Test with errors displayed to users.
  \Drupal::service('plugin.manager.mail')
    ->mail('default', 'default', 'test@example.com', 'en');
  $messages = \Drupal::messenger()
    ->messagesByType(MessengerInterface::TYPE_ERROR);
  $this
    ->assertEquals('Unable to send email. Contact the site administrator if the problem persists.', $messages[0]);
  \Drupal::messenger()
    ->deleteAll();

  // 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));
}