You are here

public function CouponRedemptionPaneTest::testMultipleCouponRedemption in Commerce Core 8.2

Tests redeeming coupon on the cart form, with multiple coupons allowed.

File

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

Class

CouponRedemptionPaneTest
Tests the coupon redemption checkout pane.

Namespace

Drupal\Tests\commerce_promotion\FunctionalJavascript

Code

public function testMultipleCouponRedemption() {
  $config = \Drupal::configFactory()
    ->getEditable('commerce_checkout.commerce_checkout_flow.default');
  $config
    ->set('configuration.panes.coupon_redemption.allow_multiple', TRUE);
  $config
    ->save();
  $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()
    ->fieldExists('Coupon code');
  $this
    ->assertSession()
    ->pageTextContains('-$99.90');
  $this
    ->assertSession()
    ->pageTextContains('$899.10');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Remove coupon');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('$999.00');
}