function MailHandlerTest::testSendMailMessages
Same name in other branches
- 9 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testSendMailMessages()
- 8.9.x core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testSendMailMessages()
- 10 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testSendMailMessages()
Tests the sendMailMessages method.
@dataProvider getSendMailMessages
@covers ::sendMailMessages
File
-
core/
modules/ contact/ tests/ src/ Unit/ MailHandlerTest.php, line 136
Class
- MailHandlerTest
- @coversDefaultClass \Drupal\contact\MailHandler @group contact
Namespace
Drupal\Tests\contact\UnitCode
public function testSendMailMessages(bool $anonymous, ?bool $auto_reply, bool $copy_sender, array $results) : void {
if ($anonymous) {
$message = $this->getAnonymousMockMessage(explode(', ', $results[0]['to']), $auto_reply, $copy_sender);
$sender = $this->getMockSender();
}
else {
$message = $this->getAuthenticatedMockMessage($copy_sender);
$sender = $this->getMockSender(FALSE, 'user@drupal.org');
}
$expected_params['contact_message'] = $message;
$expected_params['sender'] = $sender;
if ($anonymous) {
$expected_params['contact_form'] = $message->getContactForm();
}
else {
$expected_params['recipient'] = $message->getPersonalRecipient();
}
$this->logger
->expects($this->once())
->method('info');
$this->mailManager
->expects($this->any())
->method('mail')
->willReturnCallback(function ($module, $key, $to, $langcode, $params, $from) use (&$results, $expected_params) {
$result = array_shift($results);
$this->assertEquals($module, $result['module']);
$this->assertEquals($key, $result['key']);
$this->assertEquals($to, $result['to']);
$this->assertEquals($langcode, $result['langcode']);
$this->assertEquals($params, $expected_params);
$this->assertEquals($from, $result['from']);
});
$this->userStorage
->expects($this->any())
->method('load')
->willReturn(clone $sender);
$this->contactMailHandler
->sendMailMessages($message, $sender);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.