You are here

public function LicenseCronExpiryTest::testLicenseCronExpiryCurrent in Commerce License 8.2

Tests that a cron run won't expire a current license.

File

tests/src/Kernel/LicenseCronExpiryTest.php, line 194

Class

LicenseCronExpiryTest
Tests that cron expires a license.

Namespace

Drupal\Tests\commerce_license\Kernel\System

Code

public function testLicenseCronExpiryCurrent() {
  $license_storage = $this->entityTypeManager
    ->getStorage('commerce_license');
  $license_owner = $this
    ->createUser();

  // Create a license in the 'active' state.
  $license = $license_storage
    ->create([
    'type' => 'simple',
    'state' => 'active',
    'product' => 1,
    'uid' => $license_owner
      ->id(),
    // Use the unlimited expiry plugin as it's simple.
    'expiration_type' => [
      'target_plugin_id' => 'unlimited',
      'target_plugin_configuration' => [],
    ],
  ]);
  $license
    ->save();

  // Force the expiration timestamp.
  // As the state is not being changed, the expiration plugin won't be called.
  $license->expires = self::tomorrow();
  $license
    ->save();
  $this->cron
    ->run();

  // Check the license has not been changed.
  $this
    ->assertEquals('active', $license
    ->getState()
    ->getId(), "The license has not been changed and is still active.");
  $queue = $this->container
    ->get('queue')
    ->get('commerce_license_expire');
  $this
    ->assertEquals(0, $queue
    ->numberOfItems(), 'The license item was not added to the queue.');
}