You are here

public function PaymentGatewayFormTest::testPaymentGatewayEditing in Commerce Core 8.2

Tests using the payment gateway add form.

File

modules/payment/tests/src/FunctionalJavascript/PaymentGatewayFormTest.php, line 86

Class

PaymentGatewayFormTest
Tests the payment gateway form.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testPaymentGatewayEditing() {
  $values = [
    'id' => 'onsite',
    'label' => 'On-site',
    'plugin' => 'example_onsite',
    'configuration' => [
      'api_key' => 'MyAPIkey',
      'payment_method_types' => [
        'credit_card',
      ],
      'mode' => 'test',
    ],
  ];

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create($values);
  $payment_gateway
    ->save();
  $this
    ->drupalGet(Url::fromRoute('entity.commerce_payment_gateway.edit_form', [
    'commerce_payment_gateway' => 'onsite',
  ])
    ->toString());
  $page = $this
    ->getSession()
    ->getPage();
  $default_radio_button = $page
    ->findField('Example (On-site)');
  $this
    ->assertNotEmpty($default_radio_button
    ->getAttribute('checked'));
  $this
    ->assertEquals('disabled', $default_radio_button
    ->getAttribute('disabled'));
  $this
    ->assertSession()
    ->fieldNotExists('Redirect via POST (automatic)');
  $default_radio_button = $page
    ->findField('Test');
  $this
    ->assertNotEmpty($default_radio_button
    ->getAttribute('checked'));
  $this
    ->assertSession()
    ->fieldValueEquals('Name', $values['label']);
  $this
    ->assertSession()
    ->fieldValueEquals('configuration[example_onsite][api_key]', $values['configuration']['api_key']);
  $edit = [
    'label' => 'Edited onsite name',
    'configuration[example_onsite][api_key]' => 'Edited MyAPIkey',
    'configuration[example_onsite][mode]' => 'live',
  ];
  $this
    ->submitForm($edit, 'Save');
  $entity_type_manager = $this->container
    ->get('entity_type.manager');

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $onsite_payment_gateway */
  $onsite_payment_gateway = $entity_type_manager
    ->getStorage('commerce_payment_gateway')
    ->load('onsite');
  $this
    ->assertEquals($edit['configuration[example_onsite][api_key]'], $onsite_payment_gateway
    ->getPluginConfiguration()['api_key']);
  $this
    ->assertEquals($edit['label'], $onsite_payment_gateway
    ->label());
  $this
    ->assertEquals($edit['configuration[example_onsite][mode]'], $onsite_payment_gateway
    ->getPlugin()
    ->getMode());
}