You are here

public function MimeMailFormatHelperTest::testHeaders in Mime Mail 8

Tests the regular expression for extracting the mail address.

@covers ::mimeMailHeaders

File

tests/src/Kernel/MimeMailFormatHelperTest.php, line 436

Class

MimeMailFormatHelperTest
Tests that Mime Mail utility functions work properly.

Namespace

Drupal\Tests\mimemail\Kernel

Code

public function testHeaders() {
  $chars = [
    '-',
    '.',
    '+',
    '_',
  ];
  $name = $this
    ->randomString();
  $local = $this
    ->randomMachineName() . $chars[array_rand($chars)] . $this
    ->randomMachineName();
  $domain = $this
    ->randomMachineName() . '-' . $this
    ->randomMachineName() . '.' . $this
    ->randomMachineName(rand(2, 4));
  $headers = MimeMailFormatHelper::mimeMailHeaders([], "{$name} <{$local}@{$domain}>");
  $result = $headers['Return-Path'];
  $expected = "<{$local}@{$domain}>";
  $this
    ->assertSame($result, $expected, 'Return-Path header field correctly set.');
}