You are here

public function ServiceTest::testStateConsistency in Purge 8.3

Tests ::reload, ::reload, ::commit and ::claim.

File

tests/src/Kernel/Queue/ServiceTest.php, line 120

Class

ServiceTest
Tests \Drupal\purge\Plugin\Purge\Queue\QueueService.

Namespace

Drupal\Tests\purge\Kernel\Queue

Code

public function testStateConsistency() : void {
  $this->service
    ->setPluginsEnabled([
    'database',
  ]);

  // Add eight objects to the queue. reload it, and verify they're the same.
  $invalidations = $this
    ->getInvalidations(8);
  foreach ($invalidations as $invalidation) {
    $invalidation
      ->setStateContext('purger2');
  }
  $invalidations[0]
    ->setState(InvalidationInterface::SUCCEEDED);
  $invalidations[1]
    ->setState(InvalidationInterface::NOT_SUPPORTED);
  $invalidations[1]
    ->setProperty('false', FALSE);
  $invalidations[2]
    ->setState(InvalidationInterface::SUCCEEDED);
  $invalidations[3]
    ->setState(InvalidationInterface::PROCESSING);
  $invalidations[3]
    ->setProperty('secret_key', 0.123);
  $invalidations[4]
    ->setState(InvalidationInterface::FAILED);
  $invalidations[5]
    ->setState(InvalidationInterface::PROCESSING);
  $invalidations[5]
    ->setProperty('some_null_value', NULL);
  $invalidations[6]
    ->setState(InvalidationInterface::FAILED);
  $invalidations[7]
    ->setState(InvalidationInterface::NOT_SUPPORTED);
  foreach ($invalidations as $invalidation) {
    $invalidation
      ->setStateContext(NULL);
  }
  $this->service
    ->add($this->queuer, $invalidations);

  // Now claim items and verify that we're getting exactly the same states.
  $claims = $this->service
    ->claim(8, 1);
  $this
    ->assertTrue($claims[0]
    ->getState() === InvalidationInterface::SUCCEEDED);
  $this
    ->assertTrue($claims[1]
    ->getState() === InvalidationInterface::NOT_SUPPORTED);
  $this
    ->assertTrue($claims[2]
    ->getState() === InvalidationInterface::SUCCEEDED);
  $this
    ->assertTrue($claims[3]
    ->getState() === InvalidationInterface::PROCESSING);
  $this
    ->assertTrue($claims[4]
    ->getState() === InvalidationInterface::FAILED);
  $this
    ->assertTrue($claims[5]
    ->getState() === InvalidationInterface::PROCESSING);
  $this
    ->assertTrue($claims[6]
    ->getState() === InvalidationInterface::FAILED);
  $this
    ->assertTrue($claims[7]
    ->getState() === InvalidationInterface::NOT_SUPPORTED);

  // Switch to the context that created the properties, then verify equality.
  foreach ($claims as $claim) {
    $claim
      ->setStateContext('purger2');
  }
  $this
    ->assertEquals($claims[0]
    ->getProperty('_imaginary'), NULL);
  $this
    ->assertEquals($claims[1]
    ->getProperty('false'), FALSE);
  $this
    ->assertEquals($claims[2]
    ->getProperty('_imaginary'), NULL);
  $this
    ->assertEquals($claims[3]
    ->getProperty('secret_key'), 0.123);
  $this
    ->assertEquals($claims[4]
    ->getProperty('_imaginary'), NULL);
  $this
    ->assertEquals($claims[5]
    ->getProperty('some_null_value'), NULL);
  $this
    ->assertEquals($claims[6]
    ->getProperty('_imaginary'), NULL);
  $this
    ->assertEquals($claims[7]
    ->getProperty('_imaginary'), NULL);
}