You are here

public function PaymentMethodTest::testPaymentMethodCreateWithMultipleGateways in Commerce Core 8.2

Tests the payment method add form in case of multiple gateways.

File

modules/payment/tests/src/FunctionalJavascript/PaymentMethodTest.php, line 69

Class

PaymentMethodTest
Tests the payment method UI.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testPaymentMethodCreateWithMultipleGateways() {
  $this
    ->createEntity('commerce_payment_gateway', [
    'id' => 'onsite_2',
    'label' => 'Onsite Example 2',
    'plugin' => 'test_onsite',
  ]);
  $default_address = [
    'country_code' => 'US',
    'administrative_area' => 'SC',
    'locality' => 'Greenville',
    'postal_code' => '29616',
    'address_line1' => '9 Drupal Ave',
    'given_name' => 'Bryan',
    'family_name' => 'Centarro',
  ];
  $this
    ->createEntity('profile', [
    'type' => 'customer',
    'uid' => $this->user
      ->id(),
    'address' => $default_address,
  ]);
  $this
    ->drupalGet($this->collectionUrl . '/add');
  $this
    ->assertSession()
    ->fieldExists('payment_method');
  $this
    ->assertSession()
    ->elementExists('css', '[value="new--credit_card--example"]');
  $this
    ->assertSession()
    ->elementExists('css', '[value="new--credit_card--onsite_2"]');
  $radio_button = $this
    ->getSession()
    ->getPage()
    ->findField('Credit card (Test)');
  $radio_button
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $form_values = [
    'add_payment_method[payment_details][number]' => '4111111111111111',
    'add_payment_method[payment_details][expiration][month]' => '01',
    'add_payment_method[payment_details][expiration][year]' => date('Y') + 1,
    'add_payment_method[payment_details][security_code]' => '111',
  ];
  $this
    ->submitForm($form_values, 'Save');
  $this
    ->assertSession()
    ->addressEquals($this->collectionUrl);
  $this
    ->assertSession()
    ->pageTextContains('Visa ending in 1111 saved to your payment methods.');
  $payment_method = PaymentMethod::load(1);
  $this
    ->assertEquals($payment_method
    ->getPaymentGateway()
    ->getPluginId(), 'test_onsite');
  $this
    ->assertEquals($payment_method
    ->getPaymentGateway()
    ->id(), 'onsite_2');
}