You are here

public function AjaxAddCartPopupTest::testAjaxPopup in Commerce Ajax Add to Cart 8

Tests whether the popup appears after product added to cart.

File

modules/dc_ajax_add_cart_popup/tests/src/FunctionalJavascript/AjaxAddCartPopupTest.php, line 29

Class

AjaxAddCartPopupTest
Ajax add cart popup tests.

Namespace

Drupal\Tests\dc_ajax_add_cart_popup\FunctionalJavascript

Code

public function testAjaxPopup() {
  $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 popup has appeared.
  $this
    ->assertSession()
    ->pageTextContains("The item has been added to your cart.", 'Popup not found.');
}