You are here

public function PaymentCheckoutTest::testCheckoutWithOffsiteRedirectPost in Commerce Core 8.2

Tests checkout with an off-site gateway (POST redirect method).

File

modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php, line 493

Class

PaymentCheckoutTest
Tests the integration between payments and checkout.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testCheckoutWithOffsiteRedirectPost() {
  $this
    ->drupalGet($this->product
    ->toUrl()
    ->toString());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->drupalGet('checkout/1');
  $radio_button = $this
    ->getSession()
    ->getPage()
    ->findField('Example');
  $radio_button
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertRenderedAddress($this->defaultAddress, 'payment_information[billing_information]');
  $this
    ->submitForm([], 'Continue to review');
  $this
    ->assertSession()
    ->pageTextContains('Payment information');
  $this
    ->assertSession()
    ->pageTextContains('Example');
  $this
    ->assertSession()
    ->pageTextContains('Bryan Centarro');
  $this
    ->assertSession()
    ->pageTextContains('9 Drupal Ave');
  $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 = Order::load(1);
  $this
    ->assertFalse($order
    ->isLocked());
  $this
    ->assertEquals('offsite', $order
    ->get('payment_gateway')->target_id);

  /** @var \Drupal\profile\Entity\ProfileInterface $billing_profile */
  $billing_profile = $order
    ->getBillingProfile();
  $this
    ->assertEquals('9 Drupal Ave', $billing_profile
    ->get('address')->address_line1);

  // Verify that a payment was created.
  $payment = Payment::load(1);
  $this
    ->assertNotNull($payment);
  $this
    ->assertEquals($payment
    ->getAmount(), $order
    ->getTotalPrice());
}