public function AjaxAddCartUpdateCartBlockTest::testUpdateCartBlock in Commerce Ajax Add to Cart 8
Tests whether the cart block is updated after product added to cart.
File
- tests/
src/ FunctionalJavascript/ AjaxAddCartUpdateCartBlockTest.php, line 33
Class
- AjaxAddCartUpdateCartBlockTest
- Ajax add cart update cart block tests.
Namespace
Drupal\Tests\dc_ajax_add_cart\FunctionalJavascriptCode
public function testUpdateCartBlock() {
$this
->drupalGet("product/{$this->variation->getProduct()->id()}");
$ajax_add_cart_button = $this
->getSession()
->getPage()
->findButton('Add to cart');
$ajax_add_cart_button
->click();
$this
->waitForAjaxToFinish();
/*
* Confirm that the initial add to cart submit works.
*/
$this->cart = Order::load($this->cart
->id());
$order_items = $this->cart
->getItems();
$this
->assertOrderItemInOrder($this->variation, $order_items[0]);
// Confirm that the cart block has been updated.
$cart_block_contents = $this
->xpath('//div[contains(@class, :class)]//tr', [
':class' => 'view-commerce-cart-block',
]);
$this
->assertEquals(1, count($cart_block_contents), 'Cart block not updated.');
}