You are here

public function CouponRedemptionPaneTest::testCheckout in Commerce Core 8.2

Tests checkout with a redeemed coupon.

File

modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionPaneTest.php, line 263

Class

CouponRedemptionPaneTest
Tests the coupon redemption checkout pane.

Namespace

Drupal\Tests\commerce_promotion\FunctionalJavascript

Code

public function testCheckout() {
  $coupons = $this->promotion
    ->getCoupons();
  $coupon = reset($coupons);
  $this
    ->drupalGet(Url::fromRoute('commerce_checkout.form', [
    'commerce_order' => $this->cart
      ->id(),
  ]));
  $this
    ->getSession()
    ->getPage()
    ->fillField('Coupon code', $coupon
    ->getCode());
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Apply coupon');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains($coupon
    ->getCode());
  $this
    ->assertSession()
    ->pageTextContains('-$99.90');
  $this
    ->assertSession()
    ->pageTextContains('$899.10');

  // Ensure that the payment method ajax works with the coupon ajax.
  $radio_button = $this
    ->getSession()
    ->getPage()
    ->findField('Visa ending in 9999');
  $radio_button
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->submitForm([], 'Continue to review');
  $this
    ->assertSession()
    ->pageTextContains('Visa ending in 9999');
  $this
    ->assertSession()
    ->pageTextContains($coupon
    ->getCode());
  $this
    ->assertSession()
    ->pageTextContains('-$99.90');
  $this
    ->assertSession()
    ->pageTextContains('$899.10');
  $this
    ->submitForm([], 'Pay and complete purchase');
  $this
    ->assertSession()
    ->pageTextContains('Your order number is 1. You can view your order on your account page when logged in.');
  $order_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_order');
  $order_storage
    ->resetCache([
    $this->cart
      ->id(),
  ]);
  $this->cart = $order_storage
    ->load($this->cart
    ->id());
  $this
    ->assertEquals(new Price('899.10', 'USD'), $this->cart
    ->getTotalPrice());
}