You are here

public function MailHandlerTest::testInvalidRecipient in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testInvalidRecipient()

Tests the children() method with an invalid key.

@expectedException \Drupal\contact\MailHandlerException @expectedExceptionMessage Unable to determine message recipient

@covers ::sendMailMessages

File

core/modules/contact/tests/src/Unit/MailHandlerTest.php, line 107
Contains \Drupal\Tests\contact\Unit\MailHandlerTest.

Class

MailHandlerTest
@coversDefaultClass \Drupal\contact\MailHandler @group contact

Namespace

Drupal\Tests\contact\Unit

Code

public function testInvalidRecipient() {
  $message = $this
    ->getMock('\\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
    ->getMock('\\Drupal\\contact\\ContactFormInterface'));
  $sender = $this
    ->getMock('\\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->contactMailHandler
    ->sendMailMessages($message, $sender);
}