You are here

public function MultipleCartFormsTest::testMultipleRenderedFields in Commerce Core 8.2

Tests that a page with multiple add to cart forms works properly.

File

modules/cart/tests/src/FunctionalJavascript/MultipleCartFormsTest.php, line 238

Class

MultipleCartFormsTest
Tests pages with multiple products rendered with add to cart forms.

Namespace

Drupal\Tests\commerce_cart\FunctionalJavascript

Code

public function testMultipleRenderedFields() {

  // View of fields, one of which is the variations field
  // rendered via the "commerce_add_to_cart" formatter.
  $this
    ->drupalGet('/test-multiple-cart-forms-fields');

  /** @var \Behat\Mink\Element\NodeElement[] $forms */
  $forms = $this
    ->getSession()
    ->getPage()
    ->findAll('css', '.commerce-order-item-add-to-cart-form');
  $current_form = $forms[3];
  $current_form
    ->fillField('Quantity', '10');
  $current_form
    ->selectFieldOption('Size', 'Large');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $current_form
    ->selectFieldOption('Color', 'Blue');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $current_form
    ->pressButton('Add to cart');
  \Drupal::entityTypeManager()
    ->getStorage('commerce_order')
    ->resetCache();
  $this->cart = Order::load($this->cart
    ->id());
  $order_items = $this->cart
    ->getItems();
  $this
    ->assertEquals(10, $order_items[0]
    ->getQuantity());

  /** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation */
  $variation = $order_items[0]
    ->getPurchasedEntity();
  $this
    ->assertEquals($this->sizeAttributes['large']
    ->id(), $variation
    ->getAttributeValueId('attribute_size'));
  $this
    ->assertEquals($this->colorAttributes['blue']
    ->id(), $variation
    ->getAttributeValueId('attribute_color'));
}