public function MailHandlerTest::getSendMailMessages in Drupal 10
Same name and namespace in other branches
- 8 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::getSendMailMessages()
- 9 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::getSendMailMessages()
Data provider for ::testSendMailMessages.
File
- core/
modules/ contact/ tests/ src/ Unit/ MailHandlerTest.php, line 159
Class
- MailHandlerTest
- @coversDefaultClass \Drupal\contact\MailHandler @group contact
Namespace
Drupal\Tests\contact\UnitCode
public function getSendMailMessages() {
$data = [];
$recipients = [
'admin@drupal.org',
'user@drupal.org',
];
$default_result = [
'module' => 'contact',
'key' => '',
'to' => implode(', ', $recipients),
'langcode' => 'en',
'params' => [],
'from' => 'anonymous@drupal.org',
];
$results = [];
$message = $this
->getAnonymousMockMessage($recipients, '');
$sender = $this
->getMockSender();
$result = [
'key' => 'page_mail',
'params' => [
'contact_message' => $message,
'sender' => $sender,
'contact_form' => $message
->getContactForm(),
],
];
$results[] = $result + $default_result;
$data[] = [
$message,
$sender,
$results,
];
$results = [];
$message = $this
->getAnonymousMockMessage($recipients, 'reply');
$sender = $this
->getMockSender();
$result = [
'key' => 'page_mail',
'params' => [
'contact_message' => $message,
'sender' => $sender,
'contact_form' => $message
->getContactForm(),
],
];
$results[] = $result + $default_result;
$result['key'] = 'page_autoreply';
$result['to'] = 'anonymous@drupal.org';
$result['from'] = NULL;
$results[] = $result + $default_result;
$data[] = [
$message,
$sender,
$results,
];
$results = [];
$message = $this
->getAnonymousMockMessage($recipients, '', TRUE);
$sender = $this
->getMockSender();
$result = [
'key' => 'page_mail',
'params' => [
'contact_message' => $message,
'sender' => $sender,
'contact_form' => $message
->getContactForm(),
],
];
$results[] = $result + $default_result;
$result['key'] = 'page_copy';
$result['to'] = 'anonymous@drupal.org';
$results[] = $result + $default_result;
$data[] = [
$message,
$sender,
$results,
];
$results = [];
$message = $this
->getAnonymousMockMessage($recipients, 'reply', TRUE);
$sender = $this
->getMockSender();
$result = [
'key' => 'page_mail',
'params' => [
'contact_message' => $message,
'sender' => $sender,
'contact_form' => $message
->getContactForm(),
],
];
$results[] = $result + $default_result;
$result['key'] = 'page_copy';
$result['to'] = 'anonymous@drupal.org';
$results[] = $result + $default_result;
$result['key'] = 'page_autoreply';
$result['from'] = NULL;
$results[] = $result + $default_result;
$data[] = [
$message,
$sender,
$results,
];
// For authenticated user.
$results = [];
$message = $this
->getAuthenticatedMockMessage();
$sender = $this
->getMockSender(FALSE, 'user@drupal.org');
$result = [
'module' => 'contact',
'key' => 'user_mail',
'to' => 'user2@drupal.org',
'langcode' => 'en',
'params' => [
'contact_message' => $message,
'sender' => $sender,
'recipient' => $message
->getPersonalRecipient(),
],
'from' => 'user@drupal.org',
];
$results[] = $result;
$data[] = [
$message,
$sender,
$results,
];
$results = [];
$message = $this
->getAuthenticatedMockMessage(TRUE);
$sender = $this
->getMockSender(FALSE, 'user@drupal.org');
$result = [
'module' => 'contact',
'key' => 'user_mail',
'to' => 'user2@drupal.org',
'langcode' => 'en',
'params' => [
'contact_message' => $message,
'sender' => $sender,
'recipient' => $message
->getPersonalRecipient(),
],
'from' => 'user@drupal.org',
];
$results[] = $result;
$result['key'] = 'user_copy';
$result['to'] = $result['from'];
$results[] = $result;
$data[] = [
$message,
$sender,
$results,
];
return $data;
}