You are here

protected function MassContactFormTest::verifyAndProcessSendMessageQueue in Mass Contact 8

Verifies the number of items in the mass_contact_send_message queue.

Also processes the queue and verifies the number of emails generated.

Parameters

\Drupal\Core\Queue\QueueWorkerInterface $queue_worker: The queue worker for the mass_contact_send_message queue.

int $expected_queue_items: Number of items expected in the mass_contact_send_message queue.

int $expected_mails: Number of emails expected to be sent.

1 call to MassContactFormTest::verifyAndProcessSendMessageQueue()
MassContactFormTest::testNormalAccess in tests/src/Functional/Form/MassContactFormTest.php
Tests basic form operation on an unprivileged user.

File

tests/src/Functional/Form/MassContactFormTest.php, line 388

Class

MassContactFormTest
Tests for the Mass Contact form.

Namespace

Drupal\Tests\mass_contact\Functional\Form

Code

protected function verifyAndProcessSendMessageQueue(QueueWorkerInterface $queue_worker, $expected_queue_items, $expected_mails) {
  $queue = \Drupal::queue('mass_contact_send_message');

  // Number of items in the send_messages queue should be equal to
  // $expected_queue_items.
  $this
    ->assertEquals($expected_queue_items, $queue
    ->numberOfItems());

  // Process the queue.
  while ($item = $queue
    ->claimItem()) {
    $queue_worker
      ->processItem($item->data);
    $queue
      ->deleteItem($item);
  }

  // Number of emails should be equal to $expected_mails.
  $emails = $this
    ->getMails();
  $this
    ->assertEquals($expected_mails, count($emails));
}