AjaxAddCartPopupTest.php in Commerce Ajax Add to Cart 8
File
modules/dc_ajax_add_cart_popup/tests/src/FunctionalJavascript/AjaxAddCartPopupTest.php
View source
<?php
namespace Drupal\Tests\dc_ajax_add_cart_popup\FunctionalJavascript;
use Drupal\commerce_order\Entity\Order;
use Drupal\Tests\dc_ajax_add_cart\Functional\AjaxAddCartTestBase;
class AjaxAddCartPopupTest extends AjaxAddCartTestBase {
public static $modules = [
'dc_ajax_add_cart_popup',
];
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();
$this->cart = Order::load($this->cart
->id());
$order_items = $this->cart
->getItems();
$this
->assertOrderItemInOrder($this->variation, $order_items[0]);
$this
->assertSession()
->pageTextContains("The item has been added to your cart.", 'Popup not found.');
}
public function testPopupIsAjaxified() {
$this
->drupalGet("product/{$this->variation->getProduct()->id()}");
$ajax_add_cart_button = $this
->getSession()
->getPage()
->findButton('Add to cart');
$ajax_add_cart_button
->click();
$this
->assertSession()
->pageTextNotContains("The item has been added to your cart.", 'Popup was found before AJAX finished.');
}
}