function MailHandlerTest::testInvalidRecipient
Same name in other branches
- 9 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testInvalidRecipient()
- 8.9.x core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testInvalidRecipient()
- 11.x core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testInvalidRecipient()
Tests the children() method with an invalid key.
@covers ::sendMailMessages
File
-
core/
modules/ contact/ tests/ src/ Unit/ MailHandlerTest.php, line 102
Class
- MailHandlerTest
- @coversDefaultClass \Drupal\contact\MailHandler @group contact
Namespace
Drupal\Tests\contact\UnitCode
public function testInvalidRecipient() : void {
$message = $this->createMock('\\Drupal\\contact\\MessageInterface');
$message->expects($this->once())
->method('isPersonal')
->willReturn(TRUE);
$message->expects($this->once())
->method('getPersonalRecipient')
->willReturn(NULL);
$message->expects($this->once())
->method('getContactForm')
->willReturn($this->createMock('\\Drupal\\contact\\ContactFormInterface'));
$sender = $this->createMock('\\Drupal\\Core\\Session\\AccountInterface');
$this->userStorage
->expects($this->any())
->method('load')
->willReturn($sender);
// User IDs 1 and 0 have special implications, use 3 instead.
$sender->expects($this->any())
->method('id')
->willReturn(3);
$sender->expects($this->once())
->method('isAnonymous')
->willReturn(FALSE);
$this->expectException(MailHandlerException::class);
$this->expectExceptionMessage('Unable to determine message recipient');
$this->contactMailHandler
->sendMailMessages($message, $sender);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.