You are here

protected function QueueTest::queueTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Queue/QueueTest.php \Drupal\system\Tests\Queue\QueueTest::queueTest()

Queues and dequeues a set of items to check the basic queue functionality.

Parameters

\Drupal\Core\Queue\QueueInterface $queue1: An instantiated queue object.

\Drupal\Core\Queue\QueueInterface $queue2: An instantiated queue object.

2 calls to QueueTest::queueTest()
QueueTest::testMemoryQueue in core/modules/system/src/Tests/Queue/QueueTest.php
Tests the Memory queue.
QueueTest::testSystemQueue in core/modules/system/src/Tests/Queue/QueueTest.php
Tests the System queue.

File

core/modules/system/src/Tests/Queue/QueueTest.php, line 64
Contains \Drupal\system\Tests\Queue\QueueTest.

Class

QueueTest
Queues and dequeues a set of items to check the basic queue functionality.

Namespace

Drupal\system\Tests\Queue

Code

protected function queueTest($queue1, $queue2) {

  // Create four items.
  $data = array();
  for ($i = 0; $i < 4; $i++) {
    $data[] = array(
      $this
        ->randomMachineName() => $this
        ->randomMachineName(),
    );
  }

  // Queue items 1 and 2 in the queue1.
  $queue1
    ->createItem($data[0]);
  $queue1
    ->createItem($data[1]);

  // Retrieve two items from queue1.
  $items = array();
  $new_items = array();
  $items[] = $item = $queue1
    ->claimItem();
  $new_items[] = $item->data;
  $items[] = $item = $queue1
    ->claimItem();
  $new_items[] = $item->data;

  // First two dequeued items should match the first two items we queued.
  $this
    ->assertEqual($this
    ->queueScore($data, $new_items), 2, 'Two items matched');

  // Add two more items.
  $queue1
    ->createItem($data[2]);
  $queue1
    ->createItem($data[3]);
  $this
    ->assertTrue($queue1
    ->numberOfItems(), 'Queue 1 is not empty after adding items.');
  $this
    ->assertFalse($queue2
    ->numberOfItems(), 'Queue 2 is empty while Queue 1 has items');
  $items[] = $item = $queue1
    ->claimItem();
  $new_items[] = $item->data;
  $items[] = $item = $queue1
    ->claimItem();
  $new_items[] = $item->data;

  // All dequeued items should match the items we queued exactly once,
  // therefore the score must be exactly 4.
  $this
    ->assertEqual($this
    ->queueScore($data, $new_items), 4, 'Four items matched');

  // There should be no duplicate items.
  $this
    ->assertEqual($this
    ->queueScore($new_items, $new_items), 4, 'Four items matched');

  // Delete all items from queue1.
  foreach ($items as $item) {
    $queue1
      ->deleteItem($item);
  }

  // Check that both queues are empty.
  $this
    ->assertFalse($queue1
    ->numberOfItems(), 'Queue 1 is empty');
  $this
    ->assertFalse($queue2
    ->numberOfItems(), 'Queue 2 is empty');
}