You are here

public function ShippingOrderManagerTest::testGetProfile in Commerce Shipping 8.2

@covers ::getProfile

File

tests/src/Kernel/ShippingOrderManagerTest.php, line 142

Class

ShippingOrderManagerTest
Tests the shipping order manager.

Namespace

Drupal\Tests\commerce_shipping\Kernel

Code

public function testGetProfile() {
  $shipping_profile = Profile::create([
    'type' => 'customer',
    'address' => [
      'country_code' => 'FR',
    ],
  ]);
  $shipping_profile
    ->save();
  $shipping_profile = $this
    ->reloadEntity($shipping_profile);
  $shipment = Shipment::create([
    'type' => 'default',
    'order_id' => $this->shippableOrder
      ->id(),
    'title' => 'Shipment',
    'shipping_method' => $this->shippingMethod,
    'shipping_profile' => $shipping_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();
  $profile = $this->shippingOrderManager
    ->getProfile($this->nonShippableOrder);
  $this
    ->assertNull($profile);
  $this->shippableOrder
    ->set('shipments', [
    $shipment,
  ]);
  $this->shippableOrder
    ->save();
  $profile = $this->shippingOrderManager
    ->getProfile($this->shippableOrder);
  $this
    ->assertEquals($shipping_profile
    ->id(), $profile
    ->id());
}