You are here

public function CartSettingsTest::testMinimumSubtotal in Ubercart 8.4

Tests minimum subtotal for checkout.

File

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

Class

CartSettingsTest
Tests the cart settings page.

Namespace

Drupal\Tests\uc_cart\Functional

Code

public function testMinimumSubtotal() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/store/config/cart');

  // Check that minimum order subtotal field exists.
  $assert
    ->fieldExists('uc_minimum_subtotal');
  $minimum_subtotal = mt_rand(2, 9999);
  $this
    ->submitForm([
    'uc_minimum_subtotal' => $minimum_subtotal,
  ], 'Save configuration');

  // Create two products, one below the minimum price and one above.
  $product_below_limit = $this
    ->createProduct([
    'price' => $minimum_subtotal - 1,
  ]);
  $product_above_limit = $this
    ->createProduct([
    'price' => $minimum_subtotal + 1,
  ]);
  $this
    ->drupalLogout();

  // Checks if the lower-priced product triggers the minimum price logic.
  $this
    ->drupalGet('node/' . $product_below_limit
    ->id());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->drupalGet('cart');
  $this
    ->submitForm([], 'Checkout');

  // Checks that checkout below the minimum order total was prevented.
  $assert
    ->responseContains('The minimum order subtotal for checkout is');

  // Add another product to the cart and verify that we end up on the
  // checkout page.
  $this
    ->drupalGet('node/' . $product_above_limit
    ->id());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->drupalGet('cart');
  $this
    ->submitForm([], 'Checkout');
  $assert
    ->pageTextContains('Enter your billing address and information here.');
}