protected function CommerceOrderSyncTest::setUp in Commerce License 8.2
Overrides CartKernelTestBase::setUp
File
- tests/
src/ Kernel/ CommerceOrderSyncTest.php, line 76
Class
- CommerceOrderSyncTest
- Tests changes to an order are synchronized to the license.
Namespace
Drupal\Tests\commerce_license\KernelCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_license');
$this
->createUser();
$this->licenseStorage = $this->container
->get('entity_type.manager')
->getStorage('commerce_license');
// Create an order type for licenses which uses the fulfillment workflow.
$this->orderType = $this
->createEntity('commerce_order_type', [
'id' => 'license_order_type',
'label' => $this
->randomMachineName(),
'workflow' => 'order_default',
]);
// Create an order item type that uses that order type.
$order_item_type = $this
->createEntity('commerce_order_item_type', [
'id' => 'license_order_item_type',
'label' => $this
->randomMachineName(),
'purchasableEntityType' => 'commerce_product_variation',
'orderType' => 'license_order_type',
'traits' => [
'commerce_license_order_item_type',
],
]);
$trait_manager = \Drupal::service('plugin.manager.commerce_entity_trait');
$trait = $trait_manager
->createInstance('commerce_license_order_item_type');
$trait_manager
->installTrait($trait, 'commerce_order_item', $order_item_type
->id());
// Create a product variation type with the license trait, using our order
// item type.
$this->variationType = $this
->createEntity('commerce_product_variation_type', [
'id' => 'license_pv_type',
'label' => $this
->randomMachineName(),
'orderItemType' => 'license_order_item_type',
'traits' => [
'commerce_license',
],
]);
$trait = $trait_manager
->createInstance('commerce_license');
$trait_manager
->installTrait($trait, 'commerce_product_variation', $this->variationType
->id());
// Create a product variation which grants a license.
$this->variation = $this
->createEntity('commerce_product_variation', [
'type' => 'license_pv_type',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
'license_type' => [
'target_plugin_id' => 'simple',
'target_plugin_configuration' => [],
],
// Use the unlimited expiry plugin as it's simple.
'license_expiration' => [
'target_plugin_id' => 'unlimited',
'target_plugin_configuration' => [],
],
]);
// We need a product too otherwise tests complain about the missing
// backreference.
$this
->createEntity('commerce_product', [
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$this->variation,
],
]);
$this
->reloadEntity($this->variation);
$this->variation
->save();
// Create a user to use for orders.
$this->user = $this
->createUser();
}