public function LicenseCronExpiryTest::testGetLicenseIdsToExpireYesterday in Commerce License 8.2
License has expired.
Tests that getLicenseIdsToExpire doesn't return a license that hasn't expired yet.
File
- tests/
src/ Kernel/ LicenseCronExpiryTest.php, line 160
Class
- LicenseCronExpiryTest
- Tests that cron expires a license.
Namespace
Drupal\Tests\commerce_license\Kernel\SystemCode
public function testGetLicenseIdsToExpireYesterday() {
$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::yesterday();
$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([
$license
->id() => $license
->id(),
], $expire_ids, "The license ID is returned by the expiration query.");
}