You are here

public function EmailTest::testSend in Message Notify 8

Test the send method.

@covers ::send @covers ::setMessage

File

tests/src/Unit/Plugin/Notifier/EmailTest.php, line 93

Class

EmailTest
Unit tests for the Email notifier.

Namespace

Drupal\Tests\message_notify\Unit\Plugin\Notifier

Code

public function testSend() {

  // Mock a message object.
  $message = $this
    ->prophesize(MessageInterface::class);
  $account = $this
    ->prophesize(UserInterface::class);
  $account
    ->id()
    ->willReturn(42);
  $account
    ->getEmail()
    ->willReturn('foo@foo.com');
  $account
    ->getPreferredLangcode()
    ->willReturn(Language::LANGCODE_DEFAULT);
  $message
    ->getOwner()
    ->willReturn($account
    ->reveal());
  $message
    ->getOwnerId()
    ->willReturn(42);
  $template = $this
    ->prophesize(MessageTemplateInterface::class)
    ->reveal();
  $message
    ->getTemplate()
    ->willReturn($template);
  $message
    ->save()
    ->willReturn(1);

  // Mock view builder.
  $view_builder = $this
    ->prophesize(EntityViewBuilderInterface::class)
    ->reveal();
  $entity_type_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $entity_type_manager
    ->getViewBuilder('message')
    ->willReturn($view_builder);
  $this->entityTypeManager = $entity_type_manager
    ->reveal();
  $notifier = $this
    ->getNotifier();
  $notifier
    ->setMessage($message
    ->reveal());
  $this
    ->assertNull($notifier
    ->send());
}