function MailManagerTest::testGetInstance

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testGetInstance()
  2. 10 core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testGetInstance()
  3. 11.x core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php \Drupal\Tests\Core\Mail\MailManagerTest::testGetInstance()

Tests the getInstance method.

@covers ::getInstance

File

core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php, line 129

Class

MailManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Mail%21MailManager.php/class/MailManager/9" title="Provides a Mail plugin manager." class="local">\Drupal\Core\Mail\MailManager</a> @group Mail

Namespace

Drupal\Tests\Core\Mail

Code

public function testGetInstance() {
    $interface = [
        'default' => 'php_mail',
        'example_testkey' => 'test_mail_collector',
    ];
    $this->setUpMailManager($interface);
    // Test that an unmatched message_id returns the default plugin instance.
    $options = [
        'module' => 'foo',
        'key' => 'bar',
    ];
    $instance = $this->mailManager
        ->getInstance($options);
    $this->assertInstanceOf('Drupal\\Core\\Mail\\Plugin\\Mail\\PhpMail', $instance);
    // Test that a matching message_id returns the specified plugin instance.
    $options = [
        'module' => 'example',
        'key' => 'testkey',
    ];
    $instance = $this->mailManager
        ->getInstance($options);
    $this->assertInstanceOf('Drupal\\Core\\Mail\\Plugin\\Mail\\TestMailCollector', $instance);
}

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