public function PaymentOptionsBuilderTest::testBuildOptions in Commerce Core 8.2
Tests building options for all available gateways.
@covers ::buildOptions
File
- modules/
payment/ tests/ src/ Kernel/ PaymentOptionsBuilderTest.php, line 200
Class
- PaymentOptionsBuilderTest
- Tests the payment options builder.
Namespace
Drupal\Tests\commerce_payment\KernelCode
public function testBuildOptions() {
$options = $this->paymentOptionsBuilder
->buildOptions($this->order);
/** @var \Drupal\commerce_payment\PaymentOption[] $options */
$options = array_values($options);
$this
->assertCount(5, $options);
// Stored payment methods.
$this
->assertEquals('1', $options[0]
->getId());
$this
->assertEquals('Visa ending in 1111', $options[0]
->getLabel());
$this
->assertEquals('onsite', $options[0]
->getPaymentGatewayId());
$this
->assertEquals('1', $options[0]
->getPaymentMethodId());
$this
->assertNull($options[0]
->getPaymentMethodTypeId());
$this
->assertEquals([
'id' => '1',
'label' => 'Visa ending in 1111',
'payment_gateway_id' => 'onsite',
'payment_method_id' => '1',
'payment_method_type_id' => NULL,
], $options[0]
->toArray());
// Order payment method.
$this
->assertEquals('3', $options[1]
->getId());
$this
->assertEquals('Visa ending in 9999', $options[1]
->getLabel());
$this
->assertEquals('onsite', $options[1]
->getPaymentGatewayId());
$this
->assertEquals('3', $options[1]
->getPaymentMethodId());
$this
->assertNull($options[1]
->getPaymentMethodTypeId());
// Add new payment method.
$this
->assertEquals('new--credit_card--onsite', $options[2]
->getId());
$this
->assertEquals('Credit card', $options[2]
->getLabel());
$this
->assertEquals('onsite', $options[2]
->getPaymentGatewayId());
$this
->assertNull($options[2]
->getPaymentMethodId());
$this
->assertEquals('credit_card', $options[2]
->getPaymentMethodTypeId());
// Offsite gateways.
$this
->assertEquals('offsite', $options[3]
->getId());
$this
->assertEquals('Example', $options[3]
->getLabel());
$this
->assertEquals('offsite', $options[3]
->getPaymentGatewayId());
$this
->assertNull($options[3]
->getPaymentMethodId());
$this
->assertNull($options[3]
->getPaymentMethodTypeId());
// Manual gateways.
$this
->assertEquals('cash_on_delivery', $options[4]
->getId());
$this
->assertEquals('Cash on delivery', $options[4]
->getLabel());
$this
->assertEquals('cash_on_delivery', $options[4]
->getPaymentGatewayId());
$this
->assertNull($options[4]
->getPaymentMethodId());
$this
->assertNull($options[4]
->getPaymentMethodTypeId());
}