You are here

public function EnqueueFormTest::testEnqueueForm in Warmer 8

Same name and namespace in other branches
  1. 2.x modules/warmer_entity/tests/src/Functional/EnqueueFormTest.php \Drupal\Tests\warmer_entity\Functional\EnqueueFormTest::testEnqueueForm()

Asserts the enqueue form functionality.

File

modules/warmer_entity/tests/src/Functional/EnqueueFormTest.php, line 39

Class

EnqueueFormTest
Functional test for the form enqueue functionality.

Namespace

Drupal\Tests\warmer_entity\Functional

Code

public function testEnqueueForm() {
  $this
    ->createTestContent();

  // Enable the warming of articles.
  $this
    ->config('warmer.settings')
    ->set('warmers', [
    'entity' => [
      'id' => 'entity',
      'frequency' => 1,
      'batchSize' => 1,
      'entity_types' => [
        'node:article' => 'node:article',
      ],
    ],
  ])
    ->save();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet(Url::fromRoute('warmer.enqueue'));
  $this
    ->submitForm([
    'warmers[entity]' => true,
  ], 'Warm Caches');

  // Check the number of items being reported as enqueued.
  $elements = $this
    ->cssSelect('div.messages');
  $element = reset($elements);
  $this
    ->assertEquals($element
    ->getText(), 'Status message 1 items enqueued for cache warming.');

  // Ensure there is one batch in the queue.
  $queue = \Drupal::service('queue')
    ->get('warmer');
  assert($queue instanceof QueueInterface);
  $this
    ->assertSame(1, $queue
    ->numberOfItems(), 'Correct number of batches in the queue.');
}