function MailHandlerTest::testSendMailMessages

Same name in other branches
  1. 9 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testSendMailMessages()
  2. 10 core/modules/contact/tests/src/Unit/MailHandlerTest.php \Drupal\Tests\contact\Unit\MailHandlerTest::testSendMailMessages()
  3. 11.x 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 135

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);
}

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