public function LicenseRoleTypeTest::testLicenseCreationFromPlugin in Commerce License 8.2
Tests a license receives field values from a configured plugin.
File
- tests/
src/ Kernel/ LicenseRoleTypeTest.php, line 116
Class
- LicenseRoleTypeTest
- Tests the role license type.
Namespace
Drupal\Tests\commerce_license\KernelCode
public function testLicenseCreationFromPlugin() {
$role = $this->roleStorage
->create([
'id' => 'licensed_role',
]);
$role
->save();
$license_owner = $this
->createUser();
// Create a license which doesn't have any type-specific field values set.
$license = $this->licenseStorage
->create([
'type' => 'role',
'state' => 'new',
'product_variation' => 1,
'uid' => $license_owner
->id(),
'expiration_type' => [
'target_plugin_id' => 'unlimited',
'target_plugin_configuration' => [],
],
]);
$license
->save();
// Create a configured role license plugin.
$plugin_configuration = [
'license_role' => $role
->id(),
];
$license_type_plugin = $this->licenseTypeManager
->createInstance('role', $plugin_configuration);
// Set the license's type-specific fields from the configured plugin.
$license
->setValuesFromPlugin($license_type_plugin);
$license
->save();
$license = $this
->reloadEntity($license);
$this
->assertEquals($role
->id(), $license->license_role->target_id, "The role field was set on the license.");
}