You are here

public function CartTest::testCartPage in Commerce Core 8.2

Test the basic functioning of the cart page.

File

modules/cart/tests/src/Functional/CartTest.php, line 105

Class

CartTest
Tests the cart page.

Namespace

Drupal\Tests\commerce_cart\Functional

Code

public function testCartPage() {
  $this
    ->drupalGet('cart');

  // Confirm the presence of the order total summary.
  $this
    ->assertSession()
    ->elementTextContains('css', '.order-total-line', 'Subtotal');
  $this
    ->assertSession()
    ->elementTextContains('css', '.order-total-line', 'Total');
  $this
    ->assertSession()
    ->pageTextContains('$999.00');
  $this
    ->assertSession()
    ->pageTextContains('$350.00');
  $this
    ->assertSession()
    ->pageTextContains('$500.00');

  // Confirm the presence and functioning of the Quantity field.
  $this
    ->assertSession()
    ->fieldValueEquals('edit-edit-quantity-0', 1);
  $this
    ->assertSession()
    ->fieldValueEquals('edit-edit-quantity-1', 1);
  $this
    ->assertSession()
    ->fieldValueEquals('edit-edit-quantity-2', 1);
  $this
    ->assertSession()
    ->buttonExists('Update cart');
  $values = [
    'edit_quantity[0]' => 2,
    'edit_quantity[1]' => 3,
    'edit_quantity[2]' => 3,
  ];
  $this
    ->submitForm($values, t('Update cart'));
  $this
    ->assertSession()
    ->pageTextContains(sprintf('%s is not available with a quantity of %s.', $this->variations[2]
    ->label(), 3));
  $this
    ->getSession()
    ->getPage()
    ->findButton('edit-remove-button-2')
    ->press();
  $values = [
    'edit_quantity[0]' => 2,
    'edit_quantity[1]' => 3,
  ];
  $this
    ->submitForm($values, t('Update cart'));
  $this
    ->assertSession()
    ->fieldValueEquals('edit-edit-quantity-0', 2);
  $this
    ->assertSession()
    ->fieldValueEquals('edit-edit-quantity-1', 3);
  $this
    ->assertSession()
    ->elementTextContains('css', '.order-total-line', 'Total');
  $this
    ->assertSession()
    ->pageTextContains('$3,048.00');

  // Confirm that setting the quantity to 0 removes an item.
  $values = [
    'edit_quantity[0]' => 0,
    'edit_quantity[1]' => 3,
  ];
  $this
    ->submitForm($values, t('Update cart'));
  $this
    ->assertSession()
    ->pageTextContains(t('Your shopping cart has been updated.'));
  $this
    ->assertSession()
    ->fieldExists('edit-edit-quantity-0');
  $this
    ->assertSession()
    ->fieldNotExists('edit-edit-quantity-1');
  $this
    ->assertSession()
    ->pageTextContains('$1,050.00');

  // Confirm the presence and functioning of the Remove button.
  $this
    ->assertSession()
    ->buttonExists('Remove');
  $this
    ->submitForm([], t('Remove'));
  $this
    ->assertSession()
    ->pageTextContains(t('Your shopping cart is empty.'));
}