You are here

public function PaymentExecutionPaymentMethodManagerTest::testProcessDecoratedDefinitions in Payment 8.2

@covers ::processDecoratedDefinitions

File

tests/src/Unit/Plugin/Payment/Method/PaymentExecutionPaymentMethodManagerTest.php, line 66

Class

PaymentExecutionPaymentMethodManagerTest
@coversDefaultClass \Drupal\payment\Plugin\Payment\Method\PaymentExecutionPaymentMethodManager

Namespace

Drupal\Tests\payment\Unit\Plugin\Payment\Method

Code

public function testProcessDecoratedDefinitions() {
  $payment_method_id_a = $this
    ->randomMachineName();
  $payment_method_a = $this
    ->createMock(PaymentMethodInterface::class);
  $payment_method_a
    ->expects($this
    ->atLeastOnce())
    ->method('executePaymentAccess')
    ->with($this->account)
    ->willReturn(AccessResult::allowed());
  $payment_method_id_b = $this
    ->randomMachineName();
  $payment_method_b = $this
    ->createMock(PaymentMethodInterface::class);
  $payment_method_b
    ->expects($this
    ->atLeastOnce())
    ->method('executePaymentAccess')
    ->with($this->account)
    ->willReturn(AccessResult::forbidden());
  $payment_method_definitions = [
    $payment_method_id_a => [
      'id' => $payment_method_id_a,
    ],
    $payment_method_id_b => [
      'id' => $payment_method_id_b,
    ],
  ];
  $this->paymentMethodManager
    ->expects($this
    ->atLeastOnce())
    ->method('getDefinitions')
    ->willReturn($payment_method_definitions);
  $map = [
    [
      $payment_method_id_a,
      [],
      $payment_method_a,
    ],
    [
      $payment_method_id_b,
      [],
      $payment_method_b,
    ],
  ];
  $this->paymentMethodManager
    ->expects($this
    ->atLeast(count($map)))
    ->method('createInstance')
    ->willReturnMap($map);
  $filtered_plugin_definitions = $this->sut
    ->getDefinitions();
  $expected_filtered_plugin_definitions = [
    $payment_method_id_a => [
      'id' => $payment_method_id_a,
    ],
  ];
  $this
    ->assertSame($expected_filtered_plugin_definitions, $filtered_plugin_definitions);
}