function MailHandlerTest::getAuthenticatedMockMessage

Same name and namespace in other branches
  1. 9 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::getAuthenticatedMockMessage()
  2. 8.9.x core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::getAuthenticatedMockMessage()
  3. 11.x core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::getAuthenticatedMockMessage()

Builds a mock message from authenticated user.

Parameters

bool $copy_sender: TRUE if a copy should be sent, FALSE if not.

Return value

\Drupal\contact\MessageInterface|\PHPUnit\Framework\MockObject\MockObject Mock message for testing.

1 call to MailHandlerTest::getAuthenticatedMockMessage()
MailHandlerTest::testSendMailMessages in core/modules/contact/tests/src/Unit/MailHandlerTest.php
Tests the sendMailMessages method.

File

core/modules/contact/tests/src/Unit/MailHandlerTest.php, line 299

Class

MailHandlerTest
@coversDefaultClass \Drupal\contact\MailHandler[[api-linebreak]] @group contact

Namespace

Drupal\Tests\contact\Unit

Code

protected function getAuthenticatedMockMessage($copy_sender = FALSE) {
  $message = $this->createMock('\\Drupal\\contact\\MessageInterface');
  $message->expects($this->any())
    ->method('isPersonal')
    ->willReturn(TRUE);
  $message->expects($this->once())
    ->method('copySender')
    ->willReturn($copy_sender);
  $recipient = $this->createMock('\\Drupal\\user\\UserInterface');
  $recipient->expects($this->once())
    ->method('getEmail')
    ->willReturn('user2@drupal.org');
  $recipient->expects($this->any())
    ->method('getDisplayName')
    ->willReturn('user2');
  $recipient->expects($this->once())
    ->method('getPreferredLangcode')
    ->willReturn('en');
  $message->expects($this->any())
    ->method('getPersonalRecipient')
    ->willReturn($recipient);
  return $message;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.