You are here

public function PaymentGatewayTest::testDuplicate in Commerce Core 8.2

Tests duplicating a payment gateway.

File

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

Class

PaymentGatewayTest
Tests the payment gateway UI.

Namespace

Drupal\Tests\commerce_payment\Functional

Code

public function testDuplicate() {
  $values = [
    'id' => 'foo',
    'label' => 'Foo',
    'plugin' => 'example_offsite_redirect',
    'configuration' => [
      'redirect_method' => 'get',
      'mode' => 'live',
    ],
    'status' => 0,
  ];
  $payment_gateway = $this
    ->createEntity('commerce_payment_gateway', $values);
  $this
    ->drupalGet($payment_gateway
    ->toUrl('duplicate-form'));
  $this
    ->assertSession()
    ->fieldValueEquals('label', 'Foo');
  $this
    ->assertSession()
    ->fieldValueEquals('plugin', 'example_offsite_redirect');
  $this
    ->assertSession()
    ->fieldValueEquals('configuration[example_offsite_redirect][redirect_method]', 'get');
  $this
    ->assertSession()
    ->fieldValueEquals('configuration[example_offsite_redirect][mode]', 'live');
  $edit = [
    'id' => 'foo2',
    'label' => 'Foo2',
    'status' => 1,
    'configuration[example_offsite_redirect][mode]' => 'test',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Saved the Foo2 payment gateway.');

  // Confirm that the original payment gateway is unchanged.

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = $this
    ->reloadEntity($payment_gateway);
  $this
    ->assertNotEmpty($payment_gateway);
  $this
    ->assertEquals('Foo', $payment_gateway
    ->label());
  $this
    ->assertEquals('live', $payment_gateway
    ->getPlugin()
    ->getMode());
  $this
    ->assertFalse($payment_gateway
    ->status());

  // Confirm that the new payment gateway has the expected data.

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::load('foo2');
  $this
    ->assertNotEmpty($payment_gateway);
  $this
    ->assertEquals('Foo2', $payment_gateway
    ->label());
  $this
    ->assertEquals('test', $payment_gateway
    ->getPlugin()
    ->getMode());
  $this
    ->assertTrue($payment_gateway
    ->status());
}