You are here

public function PaymentCheckoutTest::testManualWithoutBilling in Commerce Core 8.2

Tests checkout with a manual gateway, without billing information.

File

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

Class

PaymentCheckoutTest
Tests the integration between payments and checkout.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testManualWithoutBilling() {
  $payment_gateway = PaymentGateway::load('manual');
  $payment_gateway
    ->setPluginConfiguration([
    'collect_billing_information' => FALSE,
    'display_label' => 'Cash on delivery',
    'instructions' => [
      'value' => 'You will pay for order #[commerce_order:order_id] in [commerce_payment:amount:currency_code].',
      'format' => 'plain_text',
    ],
  ]);
  $payment_gateway
    ->save();
  $this
    ->drupalGet($this->product
    ->toUrl()
    ->toString());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->drupalGet('checkout/1');
  $radio_button = $this
    ->getSession()
    ->getPage()
    ->findField('Cash on delivery');
  $radio_button
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextNotContains('Country');
  $this
    ->submitForm([], 'Continue to review');
  $this
    ->assertSession()
    ->pageTextContains('Payment information');
  $this
    ->assertSession()
    ->pageTextContains('Cash on delivery');
  $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.');

  // Confirm token replacement works.
  $this
    ->assertSession()
    ->pageTextContains('You will pay for order #1 in USD.');
  \Drupal::entityTypeManager()
    ->getStorage('commerce_order')
    ->resetCache([
    1,
  ]);
  $order = Order::load(1);
  $this
    ->assertEquals('manual', $order
    ->get('payment_gateway')->target_id);
  $this
    ->assertNull($order
    ->getBillingProfile());
  $this
    ->assertFalse($order
    ->isLocked());
}