protected function OrderReceiptMailTest::setUp in Commerce Core 8.2
Overrides OrderKernelTestBase::setUp
File
- modules/
order/ tests/ src/ Kernel/ Mail/ OrderReceiptMailTest.php, line 41
Class
- OrderReceiptMailTest
- Tests the sending of order receipt emails.
Namespace
Drupal\Tests\commerce_order\Kernel\MailCode
protected function setUp() : void {
parent::setUp();
$user = $this
->createUser([
'mail' => 'customer@example.com',
'preferred_langcode' => 'en',
]);
// 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',
],
]);
$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_item1 = $order_item_storage
->createFromPurchasableEntity($variation1);
$order_item1
->save();
$order = Order::create([
'type' => 'default',
'mail' => $user
->getEmail(),
'uid' => $user
->id(),
'ip_address' => '127.0.0.1',
'order_number' => '2017/01',
'billing_profile' => $profile,
'store_id' => $this->store
->id(),
'order_items' => [
$order_item1,
],
'state' => 'completed',
]);
$order
->save();
$this->order = $this
->reloadEntity($order);
$this->orderReceiptMail = $this->container
->get('commerce_order.order_receipt_mail');
}