You are here

public function CartCheckoutTest::testCartMerge in Ubercart 8.4

Tests that anonymous cart is merged into authenticated cart upon login.

File

uc_cart/tests/src/Functional/CartCheckoutTest.php, line 203

Class

CartCheckoutTest
Tests the cart and checkout functionality.

Namespace

Drupal\Tests\uc_cart\Functional

Code

public function testCartMerge() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();

  // Add an item to the cart as an anonymous user.
  $this
    ->drupalLogin($this->customer);
  $this
    ->addToCart($this->product);
  $assert
    ->pageTextContains($this->product
    ->label() . ' added to your shopping cart.');
  $this
    ->drupalLogout();

  // Add an item to the cart as an anonymous user.
  $this
    ->addToCart($this->product);
  $assert
    ->pageTextContains($this->product
    ->label() . ' added to your shopping cart.');

  // Log in and check the items are merged.
  $this
    ->drupalLogin($this->customer);
  $this
    ->drupalGet('cart');
  $assert
    ->pageTextContains($this->product
    ->label(), 'The product remains in the cart after logging in.');

  // Verify the product quantity is 2.
  $assert
    ->fieldValueEquals('items[0][qty]', 2);
}