You are here

public function PaymentCheckoutTest::testPaymentInformation in Commerce Core 8.2

Tests the structure of the PaymentInformation checkout pane.

File

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

Class

PaymentCheckoutTest
Tests the integration between payments and checkout.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testPaymentInformation() {
  $this
    ->drupalGet($this->product
    ->toUrl()
    ->toString());
  $this
    ->submitForm([], 'Add to cart');

  // The order's payment method must always be available in the pane.
  $order = Order::load(1);
  $order->payment_method = $this->orderPaymentMethod;
  $order
    ->save();
  $this
    ->drupalGet('checkout/1');
  $this
    ->assertSession()
    ->pageTextContains('Payment information');
  $expected_options = [
    'Visa ending in 1111',
    'Visa ending in 9999',
    'Credit card',
    'Example',
  ];
  $page = $this
    ->getSession()
    ->getPage();
  foreach ($expected_options as $expected_option) {
    $radio_button = $page
      ->findField($expected_option);
    $this
      ->assertNotNull($radio_button);
  }
  $default_radio_button = $page
    ->findField('Visa ending in 9999');
  $this
    ->assertNotEmpty($default_radio_button
    ->getAttribute('checked'));

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create([
    'id' => 'onsite2',
    'label' => 'On-site 2',
    'plugin' => 'example_onsite',
  ]);
  $payment_gateway
    ->setPluginConfiguration([
    'api_key' => '2342fewfsfs',
    'payment_method_types' => [
      'credit_card',
    ],
  ]);
  $payment_gateway
    ->save();
  $first_onsite_gateway = PaymentGateway::load('onsite');
  $first_onsite_gateway
    ->setStatus(FALSE);
  $first_onsite_gateway
    ->save();
  $second_onsite_gateway = PaymentGateway::load('onsite2');
  $second_onsite_gateway
    ->setStatus(FALSE);
  $second_onsite_gateway
    ->save();
  $manual_gateway = PaymentGateway::load('manual');
  $manual_gateway
    ->setStatus(FALSE);
  $manual_gateway
    ->save();
  $stored_offsite_gateway = PaymentGateway::load('stored_offsite');
  $stored_offsite_gateway
    ->setStatus(FALSE);
  $stored_offsite_gateway
    ->save();

  // A single radio button should be selected and hidden.
  $this
    ->drupalGet('checkout/1');
  $radio_button = $page
    ->findField('Example');
  $this
    ->assertNull($radio_button);
  $this
    ->assertRenderedAddress($this->defaultAddress, 'payment_information[billing_information]');
}