You are here

public function EmptyCartButtonTest::testEmptyCartButton in Commerce Core 8.2

Test the Empty Cart button.

File

modules/cart/tests/src/Functional/EmptyCartButtonTest.php, line 50

Class

EmptyCartButtonTest
Tests the cart page with the empty cart button enabled.

Namespace

Drupal\Tests\commerce_cart\Functional

Code

public function testEmptyCartButton() {
  $this
    ->drupalLogin($this->adminUser);

  // Need a second product to make sure all are removed.
  $second_variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => $this
      ->randomMachineName(),
    'price' => [
      'number' => 222,
      'currency_code' => 'USD',
    ],
  ]);
  $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => $this
      ->randomMachineName(),
    'stores' => [
      $this->store,
    ],
    'variations' => [
      $second_variation,
    ],
  ]);
  $this->cartManager
    ->addEntity($this->cart, $this->variation);
  $this->cartManager
    ->addEntity($this->cart, $second_variation);
  $this
    ->drupalGet('test-empty-cart-button-form/' . $this->cart
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('$999.00');
  $this
    ->assertSession()
    ->pageTextContains('$222.00');
  $this
    ->assertSession()
    ->buttonExists('Empty cart');
  $this
    ->submitForm([], t('Empty cart'));
  $this
    ->assertSession()
    ->pageTextContains(t('Your shopping cart is empty.'));
}