You are here

public function MailTest::testPluggableFramework in Zircon Profile 8.0

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

Assert that the pluggable mail system is functional.

File

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

Class

MailTest
Performs tests on the pluggable mailing framework.

Namespace

Drupal\system\Tests\Mail

Code

public function testPluggableFramework() {

  // Switch mail backends.
  $this
    ->config('system.mail')
    ->set('interface.default', 'test_php_mail_failure')
    ->save();

  // Get the default MailInterface class instance.
  $mail_backend = \Drupal::service('plugin.manager.mail')
    ->getInstance(array(
    'module' => 'default',
    'key' => 'default',
  ));

  // Assert whether the default mail backend is an instance of the expected
  // class.
  $this
    ->assertTrue($mail_backend instanceof TestPhpMailFailure, 'Default mail interface can be swapped.');

  // Add a module-specific mail backend.
  $this
    ->config('system.mail')
    ->set('interface.mymodule_testkey', 'test_mail_collector')
    ->save();

  // Get the added MailInterface class instance.
  $mail_backend = \Drupal::service('plugin.manager.mail')
    ->getInstance(array(
    'module' => 'mymodule',
    'key' => 'testkey',
  ));

  // Assert whether the added mail backend is an instance of the expected
  // class.
  $this
    ->assertTrue($mail_backend instanceof TestMailCollector, 'Additional mail interfaces can be added.');
}