public function MailHandlerTest::testInvalidRecipient in Drupal 8
Same name and namespace in other branches
- 9 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 101
Class
- MailHandlerTest
- @coversDefaultClass \Drupal\contact\MailHandler @group contact
Namespace
Drupal\Tests\contact\UnitCode
public function testInvalidRecipient() {
$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);
}