function MailTest::testErrorMessageDisplay

Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testErrorMessageDisplay()
  2. 10 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testErrorMessageDisplay()
  3. 11.x 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 81

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.