View source
<?php
namespace Drupal\Tests\commerce_license\Kernel;
use Drupal\Tests\commerce_order\Kernel\OrderKernelTestBase;
class LicenseStateChangeTest extends OrderKernelTestBase {
public static $modules = [
'recurring_period',
'commerce_license',
'commerce_license_test',
'interval',
];
protected $licenseStorage;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_license');
$this->licenseStorage = \Drupal::service('entity_type.manager')
->getStorage('commerce_license');
}
public function testLicenseStateChanges() {
$owner = $this
->createUser();
$license = $this->licenseStorage
->create([
'type' => 'state_change_test',
'state' => 'new',
'product_variation' => 1,
'uid' => $owner
->id(),
'expiration_type' => [
'target_plugin_id' => 'unlimited',
'target_plugin_configuration' => [],
],
]);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), NULL);
$transition = $license
->getState()
->getWorkflow()
->getTransition('activate');
$license
->getState()
->applyTransition($transition);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), NULL);
$transition = $license
->getState()
->getWorkflow()
->getTransition('confirm');
$license
->getState()
->applyTransition($transition);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), 'grantLicense');
\Drupal::state()
->set('commerce_license_state_change_test', NULL);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), NULL);
$transition = $license
->getState()
->getWorkflow()
->getTransition('suspend');
$license
->getState()
->applyTransition($transition);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), 'revokeLicense');
\Drupal::state()
->set('commerce_license_state_change_test', NULL);
$transition = $license
->getState()
->getWorkflow()
->getTransition('revoke');
$license
->getState()
->applyTransition($transition);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), NULL);
\Drupal::state()
->set('commerce_license_state_change_test', NULL);
$license = $this->licenseStorage
->create([
'type' => 'state_change_test',
'state' => 'active',
'product_variation' => 1,
'uid' => 1,
'expiration_type' => [
'target_plugin_id' => 'unlimited',
'target_plugin_configuration' => [],
],
]);
$license
->save();
$this
->assertEqual(\Drupal::state()
->get('commerce_license_state_change_test'), 'grantLicense');
}
}