function MailTest::testPluggableFramework
Same name in other branches
- 9 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testPluggableFramework()
- 8.9.x core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testPluggableFramework()
- 10 core/modules/system/tests/src/Kernel/Mail/MailTest.php \Drupal\Tests\system\Kernel\Mail\MailTest::testPluggableFramework()
Assert that the pluggable mail system is functional.
File
-
core/
modules/ system/ tests/ src/ Kernel/ Mail/ MailTest.php, line 59
Class
- MailTest
- Performs tests on the pluggable mailing framework.
Namespace
Drupal\Tests\system\Kernel\MailCode
public function testPluggableFramework() : void {
// Switch mail backends.
$this->configureDefaultMailInterface('test_php_mail_failure');
// Get the default MailInterface class instance.
$mail_backend = \Drupal::service('plugin.manager.mail')->getInstance([
'module' => 'default',
'key' => 'default',
]);
// Assert whether the default mail backend is an instance of the expected
// class.
// Default mail interface can be swapped.
$this->assertInstanceOf(TestPhpMailFailure::class, $mail_backend);
// Add a module-specific mail backend.
$this->config('system.mail')
->set('interface.my_module_test_key', 'test_mail_collector')
->save();
// Get the added MailInterface class instance.
$mail_backend = \Drupal::service('plugin.manager.mail')->getInstance([
'module' => 'my_module',
'key' => 'test_key',
]);
// Assert whether the added mail backend is an instance of the expected
// class.
// Additional mail interfaces can be added.
$this->assertInstanceOf(TestMailCollector::class, $mail_backend);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.