protected function TaxTypePluginTest::setUp in Drupal Commerce Connector for AvaTax 8
Overrides OrderKernelTestBase::setUp
File
- tests/
src/ Kernel/ TaxTypePluginTest.php, line 59
Class
- TaxTypePluginTest
- Tests the tax type plugin.
Namespace
Drupal\Tests\commerce_avatax\KernelCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('profile');
$this
->installEntitySchema('commerce_order');
$this
->installEntitySchema('commerce_order_item');
$this
->installEntitySchema('commerce_product');
$this
->installEntitySchema('commerce_product_variation');
$this
->installConfig([
'commerce_product',
'commerce_order',
'commerce_avatax',
]);
$user = $this
->createUser([
'mail' => $this
->randomString() . '@example.com',
]);
// Turn off title generation to allow explicit values to be used.
$variation_type = ProductVariationType::load('default');
$variation_type
->setGenerateTitle(FALSE);
$variation_type
->save();
$product = Product::create([
'type' => 'default',
'title' => 'Default testing product',
]);
$product
->save();
$variation1 = ProductVariation::create([
'type' => 'default',
'sku' => 'TEST_' . strtolower($this
->randomMachineName()),
'title' => $this
->randomString(),
'status' => 1,
'price' => new Price('12.00', 'USD'),
]);
$variation1
->save();
$product
->addVariation($variation1)
->save();
$profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'US',
'postal_code' => '53177',
'locality' => 'Milwaukee',
'address_line1' => 'Pabst Blue Ribbon Dr',
'administrative_area' => 'WI',
'given_name' => 'Frederick',
'family_name' => 'Pabst',
],
'uid' => $user
->id(),
]);
$profile
->save();
$profile = $this
->reloadEntity($profile);
/** @var \Drupal\commerce_order\Entity\Order $order */
$order = Order::create([
'type' => 'default',
'state' => 'draft',
'mail' => $user
->getEmail(),
'uid' => $user
->id(),
'ip_address' => '127.0.0.1',
'order_number' => '6',
'billing_profile' => $profile,
'store_id' => $this->store
->id(),
]);
/** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
$order_item = OrderItem::create([
'type' => 'default',
'quantity' => 1,
'unit_price' => new Price('12.00', 'USD'),
'purchased_entity' => $variation1,
]);
$order_item
->save();
$order
->addItem($order_item);
$order
->setRefreshState(Order::REFRESH_SKIP);
$order
->save();
$this->order = $this
->reloadEntity($order);
$this->taxType = TaxType::load('avatax');
// This will ensure our config changes are taken into account.
$this->container
->set('commerce_avatax.avatax_lib', NULL);
}