You are here

public function PaymentCheckoutTest::testCheckoutWithOffsiteRedirectGet in Commerce Core 8.2

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

File

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

Class

PaymentCheckoutTest
Tests the integration between payments and checkout.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testCheckoutWithOffsiteRedirectGet() {

  // Checkout must work when the off-site gateway is alone, and the
  // radio button hidden.
  $onsite_gateway = PaymentGateway::load('onsite');
  $onsite_gateway
    ->setStatus(FALSE);
  $onsite_gateway
    ->save();
  $manual_gateway = PaymentGateway::load('manual');
  $manual_gateway
    ->setStatus(FALSE);
  $manual_gateway
    ->save();
  $offiste_stored_gateway = PaymentGateway::load('stored_offsite');
  $offiste_stored_gateway
    ->setStatus(FALSE);
  $offiste_stored_gateway
    ->save();
  $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');
  $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
    ->assertEquals('offsite', $order
    ->get('payment_gateway')->target_id);
  $this
    ->assertFalse($order
    ->isLocked());

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