public function MultipleCartMultipleVariationTypesTest::testAddToCart in Commerce Core 8.2
Same name in this branch
- 8.2 modules/cart/tests/src/Functional/MultipleCartMultipleVariationTypesTest.php \Drupal\Tests\commerce_cart\Functional\MultipleCartMultipleVariationTypesTest::testAddToCart()
- 8.2 modules/cart/tests/src/FunctionalJavascript/MultipleCartMultipleVariationTypesTest.php \Drupal\Tests\commerce_cart\FunctionalJavascript\MultipleCartMultipleVariationTypesTest::testAddToCart()
Tests that add to cart does not throw an exception.
File
- modules/
cart/ tests/ src/ FunctionalJavascript/ MultipleCartMultipleVariationTypesTest.php, line 171
Class
- MultipleCartMultipleVariationTypesTest
- Tests multiple cart page with different variation types.
Namespace
Drupal\Tests\commerce_cart\FunctionalJavascriptCode
public function testAddToCart() {
$this
->drupalGet('/test-multiple-cart-forms');
/** @var \Behat\Mink\Element\NodeElement[] $forms */
$forms = $this
->getSession()
->getPage()
->findAll('css', '.commerce-order-item-add-to-cart-form');
$forms[1]
->selectFieldOption('Color', 'Green');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$forms[1]
->selectFieldOption('Size', 'Medium');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$forms[1]
->pressButton('Add to cart');
$this
->assertSession()
->pageTextContains('My Colors and Sizes FIRST - Green, Medium added to your cart.');
$this->container
->get('entity_type.manager')
->getStorage('commerce_order')
->resetCache([
$this->cart
->id(),
]);
$this->cart = Order::load($this->cart
->id());
$order_items = $this->cart
->getItems();
/** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation */
$variation = $order_items[0]
->getPurchasedEntity();
$this
->assertEquals($this->colorAttributes['green']
->id(), $variation
->getAttributeValueId('attribute_color'));
$this
->assertEquals($this->sizeAttributes['medium']
->id(), $variation
->getAttributeValueId('attribute_size'));
}