You are here

public function CouponRedemptionPaneTest::testCheckoutSubmit in Commerce Core 8.2

Tests that adding/removing coupons does not submit other panes.

File

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

Class

CouponRedemptionPaneTest
Tests the coupon redemption checkout pane.

Namespace

Drupal\Tests\commerce_promotion\FunctionalJavascript

Code

public function testCheckoutSubmit() {

  // Start checkout, and enter billing information.
  $this
    ->drupalGet(Url::fromRoute('commerce_checkout.form', [
    'commerce_order' => $this->cart
      ->id(),
  ]));
  $this
    ->getSession()
    ->getPage()
    ->findField('Example')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->submitForm([
    'payment_information[billing_information][address][0][address][given_name]' => 'Johnny',
    'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed',
    'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive',
    'payment_information[billing_information][address][0][address][locality]' => 'New York City',
    'payment_information[billing_information][address][0][address][administrative_area]' => 'NY',
    'payment_information[billing_information][address][0][address][postal_code]' => '10001',
  ], 'Continue to review');

  // Go back and edit the billing information, but don't submit it.
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Go back');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('billing_edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $address_prefix = 'payment_information[billing_information][address][0][address]';
  $this
    ->getSession()
    ->getPage()
    ->fillField($address_prefix . '[given_name]', 'John');
  $this
    ->getSession()
    ->getPage()
    ->fillField($address_prefix . '[family_name]', 'Smith');

  // Add a coupon.
  $coupons = $this->promotion
    ->getCoupons();
  $coupon = reset($coupons);
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->fillField('Coupon code', $coupon
    ->getCode());
  $page
    ->pressButton('Apply coupon');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains($coupon
    ->getCode());
  $this
    ->assertSession()
    ->fieldNotExists('Coupon code');
  $this
    ->assertSession()
    ->buttonNotExists('Apply coupon');

  // Refresh the page and ensure the billing information hasn't been modified.
  $this
    ->drupalGet(Url::fromRoute('commerce_checkout.form', [
    'commerce_order' => $this->cart
      ->id(),
    'step' => 'order_information',
  ]));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->assertStringContainsString('Johnny Appleseed', $page
    ->find('css', 'p.address')
    ->getText());
}