protected function TrackCheckoutStepEventTest::setUp in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/TrackCheckoutStepEventTest.php \Drupal\Tests\commerce_google_tag_manager\Kernel\TrackCheckoutStepEventTest::setUp()
Overrides CommerceKernelTestBase::setUp
File
- tests/
src/ Kernel/ TrackCheckoutStepEventTest.php, line 44
Class
- TrackCheckoutStepEventTest
- @coversDefaultClass \Drupal\commerce_google_tag_manager\Event\TrackCheckoutStepEvent
Namespace
Drupal\Tests\commerce_google_tag_manager\KernelCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('profile');
$user = $this
->createUser([
'mail' => $this
->randomString() . '@example.com',
]);
$variation = ProductVariation::create([
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'title' => $this
->randomString(),
'price' => new Price('1.00', 'USD'),
'status' => TRUE,
]);
$product = Product::create([
'type' => 'default',
'title' => $this
->randomString(),
]);
$product
->save();
$product
->addVariation($variation)
->save();
$profile = Profile::create([
'type' => 'customer',
]);
$profile
->save();
$profile = $this
->reloadEntity($profile);
/** @var \Drupal\commerce_order\OrderItemStorageInterface $order_item_storage */
$order_item_storage = $this->container
->get('entity_type.manager')
->getStorage('commerce_order_item');
$order_item = $order_item_storage
->createFromPurchasableEntity($variation);
$order_item
->save();
$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(),
'order_items' => [
$order_item,
],
]);
$order
->save();
$this->order = $this
->reloadEntity($order);
}