You are here

public function LicenseCronExpiryTest::testGetLicenseIdsToExpireTomorrow in Commerce License 8.2

License hasn't expired.

Tests that getLicenseIdsToExpire doesn't return a license that hasn't expired yet.

File

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

Class

LicenseCronExpiryTest
Tests that cron expires a license.

Namespace

Drupal\Tests\commerce_license\Kernel\System

Code

public function testGetLicenseIdsToExpireTomorrow() {
  $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();

  // Test getLicensesToExpire() method.
  $cron = \Drupal::service('commerce_license.cron');
  $getLicenseIdsToExpire = self::getMethod('\\Drupal\\commerce_license\\Cron', 'getLicensesToExpire');
  $expire_ids = $getLicenseIdsToExpire
    ->invokeArgs($cron, [
    self::today(),
  ]);
  $this
    ->assertEquals([], $expire_ids, "The license ID is not returned by the expiration query.");
}