public function MailTest::testErrorMessageDisplay in Drupal 8
Same name and namespace in other branches
- 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 76
Class
- MailTest
- Performs tests on the pluggable mailing framework.
Namespace
Drupal\Tests\system\Kernel\MailCode
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));
}