public function MimeMailFormatHelperTest::testAddressUserObject in Mime Mail 8
Tests MimeMailFormatHelper::mimeMailAddress() with user objects.
Tests addresses provided as fully loaded objects implementing \Drupal\user\UserInterface. This can't be done in a data provider function because the User module will not be set up at the time the data provider is executed.
@covers ::mimeMailAddress
File
- tests/
src/ Kernel/ MimeMailFormatHelperTest.php, line 233
Class
- MimeMailFormatHelperTest
- Tests that Mime Mail utility functions work properly.
Namespace
Drupal\Tests\mimemail\KernelCode
public function testAddressUserObject() {
// Format of each element is:
// - address: Instance of a User object containing an email field.
// - result: Expected return value from
// MimeMailFormatHelper::mimeMailAddress($address, $simplify = FALSE).
// - simplified_result: Expected return value from
// MimeMailFormatHelper::mimeMailAddress($address, $simplify = TRUE).
$addresses = [
'User name with spaces' => [
$this->adminUser,
'username with spaces <admin@test.example.com>',
'admin@test.example.com',
],
'User name with capital letters' => [
$this->userA,
'CapitaL <namea@example.com>',
'namea@example.com',
],
'Random user name' => [
$this->userB,
$this->userB
->getAccountName() . ' <nameb@example.com>',
'nameb@example.com',
],
];
foreach ($addresses as $address) {
// Test not simplified.
$formatted = MimeMailFormatHelper::mimeMailAddress($address[0], $simplify = FALSE);
$this
->assertSame($address[1], $formatted);
// Test simplified.
$formatted = MimeMailFormatHelper::mimeMailAddress($address[0], $simplify = TRUE);
$this
->assertSame($address[2], $formatted);
}
}