You are here

public function AddToCartFormTest::testProductAddToCartForm in Commerce Core 8.2

Test adding a product to the cart.

File

modules/cart/tests/src/Functional/AddToCartFormTest.php, line 31

Class

AddToCartFormTest
Tests the add to cart form.

Namespace

Drupal\Tests\commerce_cart\Functional

Code

public function testProductAddToCartForm() {

  // Confirm that the initial add to cart submit works.
  $this
    ->postAddToCart($this->variation
    ->getProduct());
  $this->cart = Order::load($this->cart
    ->id());
  $order_items = $this->cart
    ->getItems();
  $this
    ->assertOrderItemInOrder($this->variation, $order_items[0]);

  // Confirm that the second add to cart submit increments the quantity
  // of the first order item..
  $this
    ->postAddToCart($this->variation
    ->getProduct());
  \Drupal::entityTypeManager()
    ->getStorage('commerce_order')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('commerce_order_item')
    ->resetCache();
  $this->cart = Order::load($this->cart
    ->id());
  $order_items = $this->cart
    ->getItems();
  $this
    ->assertNotEmpty(count($order_items) == 1, 'No additional order items were created');
  $this
    ->assertOrderItemInOrder($this->variation, $order_items[0], 2);
}