@@ -48,6 +48,7 @@ class PaymentOptionsBuilderTest extends CommerceKernelTestBase {
4848 'commerce_order ' ,
4949 'commerce_payment ' ,
5050 'commerce_payment_example ' ,
51+ 'commerce_payment_test ' ,
5152 ];
5253
5354 /**
@@ -257,21 +258,42 @@ public function testBuildOptions() {
257258 }
258259
259260 /**
260- * Tests building options for a specific gateway.
261+ * Tests building options for two different on-site gateways.
262+ *
263+ * Confirms that the payment gateway list can be restricted, and that
264+ * multiple on-site gateways get unique "add" option labels.
261265 *
262266 * @covers ::buildOptions
263267 */
264- public function testBuildOptionsForSpecificGateway () {
265- $ payment_gateway = PaymentGateway::load ('cash_on_delivery ' );
266- $ options = $ this ->paymentOptionsBuilder ->buildOptions ($ this ->order , [$ payment_gateway ]);
267- $ this ->assertCount (1 , $ options );
268-
269- $ option = reset ($ options );
270- $ this ->assertEquals ('cash_on_delivery ' , $ option ->getId ());
271- $ this ->assertEquals ('Cash on delivery ' , $ option ->getLabel ());
272- $ this ->assertEquals ('cash_on_delivery ' , $ option ->getPaymentGatewayId ());
273- $ this ->assertNull ($ option ->getPaymentMethodId ());
274- $ this ->assertNull ($ option ->getPaymentMethodTypeId ());
268+ public function testBuildOptionsWithTwoOnsiteGateways () {
269+ $ first_payment_gateway = PaymentGateway::create ([
270+ 'id ' => 'first_onsite ' ,
271+ 'label ' => 'First (On-site) ' ,
272+ 'plugin ' => 'example_onsite ' ,
273+ ]);
274+ $ second_payment_gateway = PaymentGateway::create ([
275+ 'id ' => 'second_onsite ' ,
276+ 'label ' => 'Second (On-site) ' ,
277+ 'plugin ' => 'test_onsite ' ,
278+ ]);
279+ $ second_payment_gateway ->save ();
280+ $ payment_gateways = [$ first_payment_gateway , $ second_payment_gateway ];
281+ $ options = $ this ->paymentOptionsBuilder ->buildOptions ($ this ->order , $ payment_gateways );
282+ /** @var \Drupal\commerce_payment\PaymentOption[] $options */
283+ $ options = array_values ($ options );
284+ $ this ->assertCount (2 , $ options );
285+
286+ $ this ->assertEquals ('new--credit_card--first_onsite ' , $ options [0 ]->getId ());
287+ $ this ->assertEquals ('New credit card (Example) ' , $ options [0 ]->getLabel ());
288+ $ this ->assertEquals ('first_onsite ' , $ options [0 ]->getPaymentGatewayId ());
289+ $ this ->assertNull ($ options [0 ]->getPaymentMethodId ());
290+ $ this ->assertEquals ('credit_card ' , $ options [0 ]->getPaymentMethodTypeId ());
291+
292+ $ this ->assertEquals ('new--credit_card--second_onsite ' , $ options [1 ]->getId ());
293+ $ this ->assertEquals ('New credit card (Test) ' , $ options [1 ]->getLabel ());
294+ $ this ->assertEquals ('second_onsite ' , $ options [1 ]->getPaymentGatewayId ());
295+ $ this ->assertNull ($ options [1 ]->getPaymentMethodId ());
296+ $ this ->assertEquals ('credit_card ' , $ options [1 ]->getPaymentMethodTypeId ());
275297 }
276298
277299 /**
0 commit comments