You are here

public function PaymentGatewayTest::testAdd in Commerce Core 8.2

Tests adding a payment gateway.

File

modules/payment/tests/src/Functional/PaymentGatewayTest.php, line 34

Class

PaymentGatewayTest
Tests the payment gateway UI.

Namespace

Drupal\Tests\commerce_payment\Functional

Code

public function testAdd() {
  $this
    ->drupalGet('admin/commerce/config/payment-gateways');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add payment gateway');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/config/payment-gateways/add');
  $edit = [
    'label' => 'Example',
    'plugin' => 'example_stored_offsite_redirect',
    'configuration[example_stored_offsite_redirect][redirect_method]' => 'post',
    'configuration[example_stored_offsite_redirect][mode]' => 'test',
    'status' => '1',
    // Setting the 'id' can fail if focus switches to another field.
    // This is a bug in the machine name JS that can be reproduced manually.
    'id' => 'example',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Saved the Example payment gateway.');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/config/payment-gateways');
  $payment_gateway = PaymentGateway::load('example');
  $this
    ->assertEquals('example', $payment_gateway
    ->id());
  $this
    ->assertEquals('Example', $payment_gateway
    ->label());
  $this
    ->assertEquals('example_stored_offsite_redirect', $payment_gateway
    ->getPluginId());
  $this
    ->assertEmpty($payment_gateway
    ->getConditions());
  $this
    ->assertEquals('AND', $payment_gateway
    ->getConditionOperator());
  $this
    ->assertEquals(TRUE, $payment_gateway
    ->status());
  $payment_gateway_plugin = $payment_gateway
    ->getPlugin();
  $this
    ->assertEquals('test', $payment_gateway_plugin
    ->getMode());
  $configuration = $payment_gateway_plugin
    ->getConfiguration();
  $this
    ->assertEquals('post', $configuration['redirect_method']);
}