You are here

public function CourierManagerTest::testSkipQueueOn in Courier 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/CourierManagerTest.php \Drupal\Tests\courier\Kernel\CourierManagerTest::testSkipQueueOn()

Test skip queue is on.

File

tests/src/Kernel/CourierManagerTest.php, line 72

Class

CourierManagerTest
Tests Courier manager.

Namespace

Drupal\Tests\courier\Kernel

Code

public function testSkipQueueOn() {
  $this
    ->config('courier.settings')
    ->set('skip_queue', TRUE)
    ->set('channel_preferences', [
    'user' => [
      'courier_test_message',
    ],
  ])
    ->save();
  $template_collection = TemplateCollection::create();
  $this->courierManager
    ->addTemplates($template_collection);
  $template_collection
    ->save();
  $message = $this
    ->randomString();
  $template_collection
    ->getTemplate('courier_test_message')
    ->setMessage($message)
    ->save();
  $identity = User::create([
    'uid' => 1,
    'name' => $this
      ->randomMachineName(),
    'mail' => 'user@email.tld',
  ]);
  $identity
    ->save();
  $this->courierManager
    ->sendMessage($template_collection, $identity);
  $this
    ->assertEquals(0, count(MessageQueueItem::loadMultiple()));
  $this
    ->assertEquals(1, count(\Drupal::state()
    ->get('courier_test_message.messages', [])));
}