You are here

public function LoginCombineCartsTest::testCombineCarts in Commerce Combine Carts 8

Tests adding a product to the cart when there are multiple variations.

File

tests/src/FunctionalJavascript/LoginCombineCartsTest.php, line 26

Class

LoginCombineCartsTest
Tests the add to cart form.

Namespace

Drupal\Tests\commerce_combine_carts\FunctionalJavascript

Code

public function testCombineCarts() {

  // We are now logged in as $this->adminUser.
  $this
    ->drupalGet($this->variation
    ->getProduct()
    ->toUrl());

  // Add a product to the cart.
  $this
    ->getSession()
    ->getPage()
    ->find('css', '#edit-submit')
    ->click();

  // Log out and do the same.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($this->variation
    ->getProduct()
    ->toUrl());
  $this
    ->getSession()
    ->getPage()
    ->find('css', '#edit-submit')
    ->click();

  // Log in, and assume that we have now gotten those carts combined.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet($this->variation
    ->getProduct()
    ->toUrl());

  // This means we should have an order, with one order item, with 2 in
  // quantity.
  $orders = $this->container
    ->get('commerce_cart.cart_provider')
    ->getCarts($this->adminUser);

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = reset($orders);
  $items = $order
    ->getItems();
  $item = reset($items);
  $this
    ->assertEquals(2, $item
    ->getQuantity());
}