You are here

public function MailHandlerTest::testCustomEmail in Commerce Core 8.2

Tests sending an email with custom parameters.

File

tests/src/Kernel/MailHandlerTest.php, line 67

Class

MailHandlerTest
Tests the sending of customer emails.

Namespace

Drupal\Tests\commerce\Kernel

Code

public function testCustomEmail() {
  $body = [
    '#markup' => '<p>' . $this
      ->t('Custom Mail Handler Test') . '</p>',
  ];
  $params = [
    'id' => 'custom',
    'from' => 'me@example.com',
    'reply-to' => 'actually.me@example.com',
    'cc' => 'billing@example.com',
    'bcc' => 'other@example.com',
    'langcode' => 'fr',
    // Custom parameters are passed through.
    'foo' => 'bar',
  ];
  $result = $this->mailHandler
    ->sendMail('you@example.com', 'Hello', $body, $params);
  $this
    ->assertTrue($result);
  $emails = $this
    ->getMails();
  $email = end($emails);
  $this
    ->assertEquals('commerce_custom', $email['id']);
  $this
    ->assertEquals('you@example.com', $email['to']);
  $this
    ->assertEquals('billing@example.com', $email['headers']['Cc']);
  $this
    ->assertEquals('other@example.com', $email['headers']['Bcc']);
  $this
    ->assertEquals('actually.me@example.com', $email['headers']['Reply-to']);
  $this
    ->assertEquals('me@example.com', $email['from']);
  $this
    ->assertEquals('Hello', $email['subject']);
  $this
    ->assertStringContainsString('Custom Mail Handler Test', $email['body']);
  $this
    ->assertEquals('fr', $email['langcode']);
  $this
    ->assertEquals('bar', $email['params']['foo']);
}