You are here

public function MailHandlerTest::testSendMailMessages 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::testSendMailMessages()

Tests the sendMailMessages method.

@dataProvider getSendMailMessages

@covers ::sendMailMessages

File

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

Class

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

Namespace

Drupal\Tests\contact\Unit

Code

public function testSendMailMessages(MessageInterface $message, AccountInterface $sender, $results) {
  $this->logger
    ->expects($this
    ->once())
    ->method('notice');
  $this->mailManager
    ->expects($this
    ->any())
    ->method('mail')
    ->willReturnCallback(function ($module, $key, $to, $langcode, $params, $from) use (&$results) {
    $result = array_shift($results);
    $this
      ->assertEquals($module, $result['module']);
    $this
      ->assertEquals($key, $result['key']);
    $this
      ->assertEquals($to, $result['to']);
    $this
      ->assertEquals($langcode, $result['langcode']);
    $this
      ->assertArrayEquals($params, $result['params']);
    $this
      ->assertEquals($from, $result['from']);
  });
  $this->userStorage
    ->expects($this
    ->any())
    ->method('load')
    ->willReturn(clone $sender);
  $this->contactMailHandler
    ->sendMailMessages($message, $sender);
}