protected function ShipmentManagerTest::setUp in Commerce Shipping 8.2
Overrides ShippingKernelTestBase::setUp
File
- tests/
src/ Kernel/ ShipmentManagerTest.php, line 64
Class
- ShipmentManagerTest
- Tests the shipment manager.
Namespace
Drupal\Tests\commerce_shipping\KernelCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_promotion');
$this
->installEntitySchema('commerce_promotion_coupon');
$this
->installSchema('commerce_promotion', [
'commerce_promotion_usage',
]);
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this->container
->get('content_translation.manager')
->setEnabled('commerce_shipping_method', 'commerce_shipping_method', TRUE);
$this->shipmentManager = $this->container
->get('commerce_shipping.shipment_manager');
$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',
'order_number' => '6',
'store_id' => $this->store
->id(),
'state' => 'completed',
'order_items' => [
$order_item,
],
]);
$order
->save();
$this->order = $order;
$shipping_method = ShippingMethod::create([
'stores' => $this->store
->id(),
'name' => 'Example',
'plugin' => [
'target_plugin_id' => 'flat_rate',
'target_plugin_configuration' => [
'rate_label' => 'Standard shipping',
'rate_amount' => [
'number' => '5',
'currency_code' => 'USD',
],
],
],
'status' => TRUE,
'weight' => 1,
]);
$shipping_method
->save();
$this->shippingMethods[] = $shipping_method;
$another_shipping_method = ShippingMethod::create([
'stores' => $this->store
->id(),
'name' => 'Another shipping method',
'plugin' => [
'target_plugin_id' => 'flat_rate',
'target_plugin_configuration' => [
'rate_label' => 'Overnight shipping',
'rate_amount' => [
'number' => '20',
'currency_code' => 'USD',
],
],
],
'status' => TRUE,
'weight' => 0,
]);
$another_shipping_method
->addTranslation('fr', [
'name' => 'Another shipping method (FR)',
'plugin' => [
'target_plugin_id' => 'flat_rate',
'target_plugin_configuration' => [
'rate_label' => 'Le overnight shipping',
'rate_amount' => [
'number' => '22',
'currency_code' => 'USD',
],
],
],
]);
$another_shipping_method
->save();
$this->shippingMethods[] = $another_shipping_method;
$bad_shipping_method = ShippingMethod::create([
'stores' => $this->store
->id(),
'name' => $this
->randomString(),
'status' => TRUE,
'plugin' => [
'target_plugin_id' => 'exception_thrower',
'target_plugin_configuration' => [],
],
]);
$bad_shipping_method
->save();
$shipment = Shipment::create([
'type' => 'default',
'order_id' => $order
->id(),
'title' => 'Shipment',
'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);
}