You are here

public function CartSettingsTest::testEmptyCart in Ubercart 8.4

Tests that "Empty cart" button on the cart page works.

File

uc_cart/tests/src/Functional/CartSettingsTest.php, line 100

Class

CartSettingsTest
Tests the cart settings page.

Namespace

Drupal\Tests\uc_cart\Functional

Code

public function testEmptyCart() {

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

  // Test that the feature is not enabled by default.
  $this
    ->drupalGet('node/' . $this->product
    ->id());
  $this
    ->submitForm([], 'Add to cart');
  $assert
    ->responseNotContains('Empty cart');

  // Test the admin settings itself.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/store/config/cart');

  // Check that empty cart button checkbox found.
  $assert
    ->fieldExists('uc_cart_empty_button');
  $this
    ->submitForm([
    'uc_cart_empty_button' => TRUE,
  ], 'Save configuration');

  // Test the feature itself.
  $this
    ->drupalGet('cart');
  $this
    ->submitForm([], 'Empty cart');
  $assert
    ->pageTextContains('Are you sure you want to empty your shopping cart?');
  $this
    ->submitForm([], 'Confirm');
  $assert
    ->pageTextContains('There are no products in your shopping cart.');
}