AjaxAddCartUpdateCartBlockTest.php in Commerce Ajax Add to Cart 8
File
tests/src/FunctionalJavascript/AjaxAddCartUpdateCartBlockTest.php
View source
<?php
namespace Drupal\Tests\dc_ajax_add_cart\FunctionalJavascript;
use Drupal\commerce_order\Entity\Order;
use Drupal\Tests\dc_ajax_add_cart\Functional\AjaxAddCartTestBase;
class AjaxAddCartUpdateCartBlockTest extends AjaxAddCartTestBase {
protected function setUp() {
parent::setUp();
$this
->placeBlock('commerce_cart');
}
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();
$this->cart = Order::load($this->cart
->id());
$order_items = $this->cart
->getItems();
$this
->assertOrderItemInOrder($this->variation, $order_items[0]);
$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.');
}
}