public function CartIntegrationTest::testEmptyCart in Commerce Shipping 8.2
Tests that emptying a cart removes its shipments.
File
- tests/
src/ Kernel/ CartIntegrationTest.php, line 78
Class
- CartIntegrationTest
- Tests integration with the Cart module.
Namespace
Drupal\Tests\commerce_shipping\KernelCode
public function testEmptyCart() {
$cart = $this->cartProvider
->createCart('default');
$this->cartManager
->addEntity($cart, $this->variations[0]);
$shipping_profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'US',
],
]);
$shipping_profile
->save();
$shipping_order_manager = $this->container
->get('commerce_shipping.order_manager');
$shipments = $shipping_order_manager
->pack($cart, $shipping_profile);
$cart
->set('shipments', $shipments);
$cart
->setRefreshState(OrderInterface::REFRESH_SKIP);
$cart
->save();
$this
->assertCount(1, $cart
->get('shipments')
->referencedEntities());
$this->cartManager
->emptyCart($cart);
$this
->assertCount(0, $cart
->get('shipments')
->referencedEntities());
$storage = $this->container
->get('entity_type.manager')
->getStorage('commerce_shipment');
$shipments = $storage
->loadMultiple();
$this
->assertEmpty($shipments);
}