LicenseGrantSetFieldTest.php in Commerce License 8.2
File
tests/src/Kernel/LicenseGrantSetFieldTest.php
View source
<?php
namespace Drupal\Tests\commerce_license\Kernel;
use Drupal\Tests\commerce_order\Kernel\OrderKernelTestBase;
class LicenseGrantSetFieldTest extends OrderKernelTestBase {
public static $modules = [
'recurring_period',
'commerce_license',
'commerce_license_test',
'interval',
];
protected $licenseStorage;
protected $licenseTypeManager;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_license');
$this->container
->get('entity.bundle_plugin_installer')
->installBundles($this->container
->get('entity_type.manager')
->getDefinition('commerce_license'), [
'commerce_license_test',
]);
$this->licenseTypeManager = $this->container
->get('plugin.manager.commerce_license_type');
$this->licenseStorage = $this->container
->get('entity_type.manager')
->getStorage('commerce_license');
}
public function testLicensePluginSetField() {
$license_owner = $this
->createUser();
$license = $this->licenseStorage
->create([
'type' => 'with_field',
'state' => 'new',
'product_variation' => 1,
'uid' => $license_owner
->id(),
'expiration_type' => [
'target_plugin_id' => 'unlimited',
'target_plugin_configuration' => [],
],
]);
$license
->save();
$license = $this
->reloadEntity($license);
$this
->assertEqual('', $license->test_field->value, 'The plugin-controlled field is not set.');
$license->state = 'active';
$license
->save();
$license = $this
->reloadEntity($license);
$this
->assertEqual('granted', $license->test_field->value, 'The plugin-controlled field has been set by grantLicense().');
$license->state = 'expired';
$license
->save();
$license = $this
->reloadEntity($license);
$this
->assertEqual('revoked', $license->test_field->value, 'The plugin-controlled field has been set by revokeLicense().');
}
}