You are here

public function SermepaGatewayUiTest::testSermepaGatewayCreation in Commerce sermepa 8.2

Tests creating a Sermepa payment gateway.

File

tests/src/FunctionalJavascript/SermepaGatewayUiTest.php, line 35

Class

SermepaGatewayUiTest
Tests the payment gateway UI for 'Sermepa' case.

Namespace

Drupal\Tests\commerce_sermepa\FunctionalJavascript

Code

public function testSermepaGatewayCreation() {
  $this
    ->drupalGet('admin/commerce/config/payment-gateways/add');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/config/payment-gateways/add');
  $this
    ->assertSession()
    ->fieldExists('label')
    ->setValue('Sermepa');
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.edit-label-machine-name-suffix');
  $this
    ->assertSession()
    ->buttonExists('Edit')
    ->click();
  $this
    ->assertSession()
    ->fieldExists('id')
    ->setValue('sermepa');

  // Select the plugin and wait for the Sermepa fields.
  $this
    ->assertSession()
    ->fieldExists('plugin')
    ->setValue('commerce_sermepa');
  $this
    ->waitForAjaxToFinish();
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][mode]')
    ->setValue('test');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_name]')
    ->setValue('Merchant name');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_code]')
    ->setValue('000000001');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_group]')
    ->setValue('MG');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_password]')
    ->setValue('00000000000000000000000000000000');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_terminal]')
    ->setValue('001');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_paymethods][]')
    ->setValue([
    'D',
  ]);
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][merchant_consumer_language]')
    ->setValue('001');
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][currency]')
    ->setValue(840);
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][transaction_type]')
    ->setValue(0);
  $this
    ->assertSession()
    ->fieldExists('configuration[commerce_sermepa][instructions][value]')
    ->setValue('Instructions');
  $this
    ->assertSession()
    ->buttonExists('Save')
    ->click();

  // Wait for the payment gateways collection page.
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.commerce-payment-gateways');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/config/payment-gateways');
  $this
    ->assertSession()
    ->responseContains('Sermepa');
  $this
    ->assertSession()
    ->responseContains('Test');
  $payment_gateway = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_payment_gateway')
    ->load('sermepa');
  $this
    ->assertEquals('sermepa', $payment_gateway
    ->id());
  $this
    ->assertEquals('Sermepa', $payment_gateway
    ->label());
  $this
    ->assertEquals('commerce_sermepa', $payment_gateway
    ->getPluginId());
  $payment_gateway_plugin = $payment_gateway
    ->getPlugin();
  $this
    ->assertEquals('test', $payment_gateway_plugin
    ->getMode());
  $configuration = $payment_gateway_plugin
    ->getConfiguration();
  $this
    ->assertEquals('Merchant name', $configuration['merchant_name']);
  $this
    ->assertEquals('000000001', $configuration['merchant_code']);
  $this
    ->assertEquals('MG', $configuration['merchant_group']);
  $this
    ->assertEquals('00000000000000000000000000000000', $configuration['merchant_password']);
  $this
    ->assertEquals('001', $configuration['merchant_terminal']);
  $this
    ->assertEquals([
    'D' => 'D',
  ], $configuration['merchant_paymethods']);
  $this
    ->assertEquals('001', $configuration['merchant_consumer_language']);
  $this
    ->assertEquals(840, $configuration['currency']);
  $this
    ->assertEquals(0, $configuration['transaction_type']);
  $this
    ->assertEquals('Instructions', $configuration['instructions']['value']);
  $this
    ->assertEquals('plain_text', $configuration['instructions']['format']);
}