You are here

public function QueueMailFunctionalTest::testFailMessage in Queue Mail 8

Test that message sending may be failed.

File

tests/src/Functional/QueueMailFunctionalTest.php, line 224

Class

QueueMailFunctionalTest
Tests queue mail functionality.

Namespace

Drupal\Tests\queue_mail\Functional

Code

public function testFailMessage() {
  $this
    ->setAllEmailsToBeQueued();
  $queue = _queue_mail_get_queue();
  $queue_count_init = $queue
    ->numberOfItems();
  $params = $this
    ->getMessageParams();

  // Send message that won't be send and will be re-queued.
  $this
    ->sendQueueMailTest('fail_message', 'fail@example.com', $params);
  $this
    ->cronRun();
  $queue_count_after_adding = $queue
    ->numberOfItems();

  // Ensures that "fail_message" hasn't been sent.
  $this
    ->assertEquals(1, $queue_count_after_adding - $queue_count_init, 'Mail sending has been failed. Message is in the queue.');

  // Send normal message.
  $this
    ->sendQueueMailTest('send_message', 'send@example.com', $params);
  $queue_count_after_adding = $queue
    ->numberOfItems();

  // Ensures that there are two messages in the queue - "fail_message" and
  // "send_message".
  $this
    ->assertEquals(2, $queue_count_after_adding - $queue_count_init, 'Mail sending has been failed. Message is in the queue.');
  $this
    ->cronRun();

  // Ensures that one mail has been processed and one is still in the queue.
  $queue_count_after_adding = $queue
    ->numberOfItems();
  $this
    ->assertEquals(1, $queue_count_after_adding - $queue_count_init, 'One message has been processed.');
}