You are here

public function EventDispatcherCollectionTest::testExecutePaymentAccess in Payment 8.2

@covers ::executePaymentAccess

@dataProvider providerExecutePaymentAccess

Parameters

bool|null $expected_access: TRUE for allowed, NULL for neutral, FALSE for forbidden.

\Drupal\Core\Access\AccessResult $event_dispatcher_access_a:

\Drupal\Core\Access\AccessResult $event_dispatcher_access_b:

File

tests/src/Unit/EventDispatcherCollectionTest.php, line 129

Class

EventDispatcherCollectionTest
@coversDefaultClass \Drupal\payment\EventDispatcherCollection

Namespace

Drupal\Tests\payment\Unit

Code

public function testExecutePaymentAccess($expected_access, AccessResult $event_dispatcher_access_a, AccessResult $event_dispatcher_access_b) {
  $payment = $this
    ->createMock(PaymentInterface::class);
  $payment_method = $this
    ->createMock(PaymentMethodInterface::class);
  $account = $this
    ->createMock(AccountInterface::class);
  $event_dispatcher_a = $this
    ->createMock(EventDispatcherInterface::class);
  $event_dispatcher_a
    ->expects($this
    ->atLeastOnce())
    ->method('executePaymentAccess')
    ->with($payment, $payment_method, $account)
    ->willReturn($event_dispatcher_access_a);
  $event_dispatcher_b = $this
    ->createMock(EventDispatcherInterface::class);
  $event_dispatcher_b
    ->expects($this
    ->atLeastOnce())
    ->method('executePaymentAccess')
    ->with($payment, $payment_method, $account)
    ->willReturn($event_dispatcher_access_b);
  $this->sut
    ->addEventDispatcher($event_dispatcher_a);
  $this->sut
    ->addEventDispatcher($event_dispatcher_b);
  $access = $this->sut
    ->executePaymentAccess($payment, $payment_method, $account);
  $this
    ->assertInstanceOf(AccessResultInterface::class, $access);
  if ($expected_access === TRUE) {
    $this
      ->assertTrue($access
      ->isAllowed());
  }
  elseif ($expected_access === FALSE) {
    $this
      ->assertTrue($access
      ->isForbidden());
  }
  elseif ($expected_access === NULL) {
    $this
      ->assertTrue($access
      ->isNeutral());
  }
}