You are here

public function PaymentMethodBaseTest::testExecutePaymentAccess in Payment 8.2

@covers ::executePaymentAccess

@dataProvider providerTestExecutePaymentAccess

File

tests/src/Unit/Plugin/Payment/Method/PaymentMethodBaseTest.php, line 235

Class

PaymentMethodBaseTest
@coversDefaultClass \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase

Namespace

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

Code

public function testExecutePaymentAccess($expected, $active, AccessResultInterface $currency_supported, AccessResultInterface $events_access_result, AccessResultInterface $do) {
  $payment = $this
    ->getMockPayment();
  $account = $this
    ->createMock(AccountInterface::class);
  $this->pluginDefinition['active'] = $active;

  /** @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase|\PHPUnit\Framework\MockObject\MockObject $payment_method */
  $payment_method = $this
    ->getMockBuilder(PaymentMethodBase::class)
    ->setConstructorArgs([
    [],
    '',
    $this->pluginDefinition,
    $this->moduleHandler,
    $this->eventDispatcher,
    $this->token,
    $this->paymentStatusManager,
  ])
    ->setMethods([
    'executePaymentAccessCurrency',
    'executePaymentAccessEvent',
    'doExecutePaymentAccess',
  ])
    ->getMockForAbstractClass();
  $payment_method
    ->expects($this
    ->any())
    ->method('executePaymentAccessCurrency')
    ->with($account)
    ->willReturn($currency_supported);
  $payment_method
    ->expects($this
    ->any())
    ->method('doExecutePaymentAccess')
    ->with($account)
    ->willReturn($do);
  $payment_method
    ->setPayment($payment);
  $this->eventDispatcher
    ->expects($this
    ->any())
    ->method('executePaymentAccess')
    ->with($payment, $payment_method, $account)
    ->willReturn($events_access_result);
  $access = $payment_method
    ->executePaymentAccess($account);
  $this
    ->assertInstanceOf(AccessResultInterface::class, $access);
  $this
    ->assertSame($expected, $access
    ->isAllowed());
}