public function PaymentCheckoutTest::testCheckoutWithOffsiteRedirectPostManual in Commerce Core 8.2
Tests checkout with an off-site gateway (POST redirect method, manual).
In this scenario the customer must click the submit button on the payment page in order to proceed to the gateway.
File
- modules/
payment/ tests/ src/ FunctionalJavascript/ PaymentCheckoutTest.php, line 528
Class
- PaymentCheckoutTest
- Tests the integration between payments and checkout.
Namespace
Drupal\Tests\commerce_payment\FunctionalJavascriptCode
public function testCheckoutWithOffsiteRedirectPostManual() {
$payment_gateway = PaymentGateway::load('offsite');
$payment_gateway
->setPluginConfiguration([
'redirect_method' => 'post_manual',
'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
->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()
->addressEquals('checkout/1/payment');
$order = Order::load(1);
$this
->assertTrue($order
->isLocked());
$this
->assertEquals('offsite', $order
->get('payment_gateway')->target_id);
$this
->submitForm([], 'Proceed to Example');
$this
->assertSession()
->pageTextContains('Your order number is 1. You can view your order on your account page when logged in.');
\Drupal::entityTypeManager()
->getStorage('commerce_order')
->resetCache([
'1',
]);
$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());
}