You are here

public function ShipmentTest::testDefaults in Commerce Shipping 8.2

@covers ::preSave

File

tests/src/Kernel/Entity/ShipmentTest.php, line 322

Class

ShipmentTest
Tests the Shipment entity.

Namespace

Drupal\Tests\commerce_shipping\Kernel\Entity

Code

public function testDefaults() {

  /** @var \Drupal\commerce_shipping\Entity\ShippingMethodInterface $shipping_method */
  $shipping_method = ShippingMethod::create([
    'name' => $this
      ->randomString(),
    'plugin' => [
      'target_plugin_id' => 'flat_rate',
      'target_plugin_configuration' => [],
    ],
    'status' => 1,
  ]);
  $shipping_method
    ->save();

  // Saving a shipment with a shipping method but no package type should
  // populate the package type.
  $shipment = Shipment::create([
    'type' => 'default',
    'order_id' => 10,
    'shipping_method' => $shipping_method,
    'title' => 'Shipment',
    'items' => [
      new ShipmentItem([
        'order_item_id' => 10,
        'title' => 'T-shirt (red, large)',
        'quantity' => 1,
        'weight' => new Weight('10', 'kg'),
        'declared_value' => new Price('15', 'USD'),
      ]),
    ],
  ]);
  $shipment
    ->save();
  $this
    ->assertEquals('custom_box', $shipment
    ->getPackageType()
    ->getId());
}