You are here

public function DigestTest::testDeliverySavedOriginal in Message Digest 8

Test delivery with an unsaved message, but a saved original.

@covers ::deliver

File

tests/src/Unit/Plugin/Notifier/DigestTest.php, line 135

Class

DigestTest
Tests the Digest plugin.

Namespace

Drupal\Tests\message_digest\Unit\Plugin\Notifier

Code

public function testDeliverySavedOriginal() {

  // Setup a saved original.
  $original = $this
    ->prophesize(MessageInterface::class);
  $original
    ->id()
    ->willReturn(42);
  $message = $this
    ->prophesize(MessageInterface::class);
  $message
    ->getOwnerId()
    ->willReturn(4);
  $message
    ->getCreatedTime()
    ->willReturn(123);
  $message
    ->id()
    ->willReturn(NULL);
  $message = $message
    ->reveal();
  $message->original_message = $original
    ->reveal();

  // Mock up the insert.
  $expected_row = [
    'receiver' => 4,
    'entity_type' => '',
    'entity_id' => '',
    'notifier' => $this->pluginId,
    'timestamp' => 123,
    'mid' => 42,
  ];
  $insert = $this
    ->prophesize(Insert::class);
  $insert
    ->fields($expected_row)
    ->willReturn($insert
    ->reveal());
  $insert
    ->execute()
    ->shouldBeCalled();
  $connection = $this
    ->prophesize(Connection::class);
  $connection
    ->insert('message_digest')
    ->willReturn($insert
    ->reveal());
  $this->connection = $connection
    ->reveal();
  $notifier = $this
    ->getNotifier($message);
  $this
    ->assertTrue($notifier
    ->deliver([]));
}