You are here

public function PaymentOptionsBuilderTest::testBuildOptionsWithTwoOnsiteGateways in Commerce Core 8.2

Tests building options for two different on-site gateways.

Confirms that the payment gateway list can be restricted, and that multiple on-site gateways get unique "add" option labels.

@covers ::buildOptions

File

modules/payment/tests/src/Kernel/PaymentOptionsBuilderTest.php, line 257

Class

PaymentOptionsBuilderTest
Tests the payment options builder.

Namespace

Drupal\Tests\commerce_payment\Kernel

Code

public function testBuildOptionsWithTwoOnsiteGateways() {
  $first_payment_gateway = PaymentGateway::create([
    'id' => 'first_onsite',
    'label' => 'First (On-site)',
    'plugin' => 'example_onsite',
  ]);
  $second_payment_gateway = PaymentGateway::create([
    'id' => 'second_onsite',
    'label' => 'Second (On-site)',
    'plugin' => 'test_onsite',
  ]);
  $second_payment_gateway
    ->save();
  $payment_gateways = [
    $first_payment_gateway,
    $second_payment_gateway,
  ];
  $options = $this->paymentOptionsBuilder
    ->buildOptions($this->order, $payment_gateways);

  /** @var \Drupal\commerce_payment\PaymentOption[] $options */
  $options = array_values($options);
  $this
    ->assertCount(2, $options);
  $this
    ->assertEquals('new--credit_card--first_onsite', $options[0]
    ->getId());
  $this
    ->assertEquals('Credit card (Example)', $options[0]
    ->getLabel());
  $this
    ->assertEquals('first_onsite', $options[0]
    ->getPaymentGatewayId());
  $this
    ->assertNull($options[0]
    ->getPaymentMethodId());
  $this
    ->assertEquals('credit_card', $options[0]
    ->getPaymentMethodTypeId());
  $this
    ->assertEquals('new--credit_card--second_onsite', $options[1]
    ->getId());
  $this
    ->assertEquals('Credit card (Test)', $options[1]
    ->getLabel());
  $this
    ->assertEquals('second_onsite', $options[1]
    ->getPaymentGatewayId());
  $this
    ->assertNull($options[1]
    ->getPaymentMethodId());
  $this
    ->assertEquals('credit_card', $options[1]
    ->getPaymentMethodTypeId());
}