LicenseSetExpiryTest.php in Commerce License 8.2
File
tests/src/Kernel/LicenseSetExpiryTest.php
View source
<?php
namespace Drupal\Tests\commerce_license\Kernel;
use Drupal\Tests\commerce_order\Kernel\OrderKernelTestBase;
class LicenseSetExpiryTest extends OrderKernelTestBase {
public static $modules = [
'commerce_license',
'commerce_license_test',
'commerce_license_set_expiry_test',
'interval',
'recurring_period',
];
protected $licenseStorage;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_license');
$this->licenseStorage = \Drupal::service('entity_type.manager')
->getStorage('commerce_license');
}
public function testLicenseSetExpiry() {
$owner = $this
->createUser();
$license = $this->licenseStorage
->create([
'type' => 'simple',
'state' => 'new',
'product_variation' => 1,
'uid' => $owner
->id(),
'expiration_type' => [
'target_plugin_id' => 'commerce_license_set_expiry_test',
'target_plugin_configuration' => [],
],
]);
$license
->save();
$transition = $license
->getState()
->getWorkflow()
->getTransition('activate');
$license
->getState()
->applyTransition($transition);
$license
->save();
$this
->assertEqual($license->expires->value, 0);
$transition = $license
->getState()
->getWorkflow()
->getTransition('confirm');
$license
->getState()
->applyTransition($transition);
$license
->save();
$this
->assertEqual($license->expires->value, 12345);
}
}