function MailHandlerTest::getAuthenticatedMockMessage

Same name in other branches
  1. 8.9.x core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::getAuthenticatedMockMessage()
  2. 10 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::getSendMailMessages in core/modules/contact/tests/src/Unit/MailHandlerTest.php
Data provider for ::testSendMailMessages.

File

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

Class

MailHandlerTest
@coversDefaultClass \Drupal\contact\MailHandler @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);
    $message->expects($this->any())
        ->method('getContactForm')
        ->willReturn($this->getMockContactForm('user2@drupal.org', FALSE));
    return $message;
}

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