protected function OrderShipmentSummaryTest::setUp in Commerce Shipping 8.2
Overrides ShippingKernelTestBase::setUp
File
- tests/
src/ Kernel/ OrderShipmentSummaryTest.php, line 48
Class
- OrderShipmentSummaryTest
- Tests the order shipment summary.
Namespace
Drupal\Tests\commerce_shipping\KernelCode
protected function setUp() : void {
parent::setUp();
$this->orderShipmentSummary = $this->container
->get('commerce_shipping.order_shipment_summary');
$user = $this
->createUser([
'mail' => $this
->randomString() . '@example.com',
]);
$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',
'uid' => $user
->id(),
'address' => [
'country_code' => 'US',
'administrative_area' => 'CA',
'locality' => 'Mountain View',
'postal_code' => '94043',
'address_line1' => '1098 Alta Ave',
'organization' => 'Google Inc.',
'given_name' => 'John',
'family_name' => 'Smith',
],
]);
$profile
->save();
$profile = $this
->reloadEntity($profile);
$order_item = OrderItem::create([
'type' => 'test',
'quantity' => 1,
'unit_price' => new Price('12.00', 'USD'),
]);
$order_item
->save();
/** @var \Drupal\commerce_order\Entity\Order $order */
$order = Order::create([
'type' => 'default',
'mail' => $user
->getEmail(),
'uid' => $user
->id(),
'ip_address' => '127.0.0.1',
'order_number' => '6',
'billing_profile' => $profile,
'store_id' => $this->store
->id(),
'state' => 'completed',
'order_items' => [
$order_item,
],
]);
$order
->save();
$this->order = $this
->reloadEntity($order);
$shipping_method = ShippingMethod::create([
'stores' => $this->store
->id(),
'name' => 'Example',
'plugin' => [
'target_plugin_id' => 'flat_rate',
'target_plugin_configuration' => [
'rate_label' => 'Flat rate',
'rate_amount' => new Price('1', 'USD'),
],
],
'status' => TRUE,
'weight' => 1,
]);
$shipping_method
->save();
$shipment = Shipment::create([
'type' => 'default',
'order_id' => $this->order
->id(),
'title' => 'Shipment',
'shipping_method' => $shipping_method,
'shipping_profile' => $profile,
'tracking_code' => 'ABC123',
'items' => [
new ShipmentItem([
'order_item_id' => 1,
'title' => 'T-shirt (red, large)',
'quantity' => 2,
'weight' => new Weight('40', 'kg'),
'declared_value' => new Price('30', 'USD'),
]),
],
'amount' => new Price('5', 'USD'),
'state' => 'draft',
]);
$shipment
->save();
$this->shipment = $this
->reloadEntity($shipment);
$this->order
->set('shipments', [
$shipment,
]);
$this->order
->save();
}