You are here

public function CommerceCartTestCaseSimpleProduct::testCommerceCartChangeQty in Commerce Core 7

Test the quantity changes in the cart.

File

modules/cart/tests/commerce_cart.test, line 147
Functional tests for the commerce cart module.

Class

CommerceCartTestCaseSimpleProduct
Test cart features for a product display that only has one product attached.

Code

public function testCommerceCartChangeQty() {

  // Go to cart url.
  $this
    ->drupalGet($this
    ->getCommerceUrl('cart'));

  // Change quantity in the cart view form.
  // We search for the first quantity field in the html and change the
  //   amount there.
  $qty = $this
    ->xpath("//input[starts-with(@name, 'edit_quantity')]");
  $this
    ->drupalPost($this
    ->getCommerceUrl('cart'), array(
    (string) $qty[0]['name'] => 2,
  ), t('Update cart'));

  // Check if the amount has been really changed.
  $this
    ->assertFieldByXPath("//input[starts-with(@id, 'edit-edit-quantity')]", 2, t('Cart updated with new quantity'));
}