You are here

public function PaymentCheckoutTest::testFailedCheckoutWithOffsiteRedirectGet in Commerce Core 8.2

Tests checkout with an off-site gateway (GET redirect method) that fails.

The off-site form throws an exception, simulating an API fail.

File

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

Class

PaymentCheckoutTest
Tests the integration between payments and checkout.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testFailedCheckoutWithOffsiteRedirectGet() {
  $payment_gateway = PaymentGateway::load('offsite');
  $payment_gateway
    ->setPluginConfiguration([
    'redirect_method' => 'get',
    'payment_method_types' => [
      'credit_card',
    ],
  ]);
  $payment_gateway
    ->save();
  $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
    ->getSession()
    ->getPage()
    ->pressButton('billing_edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->submitForm([
    'payment_information[billing_information][address][0][address][family_name]' => 'FAIL',
  ], 'Continue to review');
  $this
    ->assertSession()
    ->pageTextContains('Payment information');
  $this
    ->assertSession()
    ->pageTextContains('Example');
  $this
    ->assertSession()
    ->pageTextContains('Bryan FAIL');
  $this
    ->assertSession()
    ->pageTextContains('9 Drupal Ave');
  $this
    ->submitForm([], 'Pay and complete purchase');
  $this
    ->assertSession()
    ->pageTextNotContains('Your order number is 1. You can view your order on your account page when logged in.');
  $this
    ->assertSession()
    ->pageTextContains('We encountered an unexpected error processing your payment. Please try again later.');
  $this
    ->assertSession()
    ->addressEquals('checkout/1/order_information');
  $order = Order::load(1);
  $this
    ->assertFalse($order
    ->isLocked());

  // Verify a payment was not created.
  $payment = Payment::load(1);
  $this
    ->assertNull($payment);
}