You are here

public function PaymentMethodConfigurationAccessControlHandlerTest::testCheckAccessDuplicate in Payment 8.2

@covers ::checkAccess

@dataProvider providerTestCheckAccessDuplicate

File

tests/src/Unit/Entity/PaymentMethodConfiguration/PaymentMethodConfigurationAccessControlHandlerTest.php, line 264

Class

PaymentMethodConfigurationAccessControlHandlerTest
@coversDefaultClass \Drupal\payment\Entity\PaymentMethodConfiguration\PaymentMethodConfigurationAccessControlHandler

Namespace

Drupal\Tests\payment\Unit\Entity\PaymentMethodConfiguration

Code

public function testCheckAccessDuplicate($expected, $has_create_permission, $has_view_permission) {
  $operation = 'duplicate';
  $bundle = $this
    ->randomMachineName();
  $account = $this
    ->createMock(AccountInterface::class);
  $map = [
    [
      'payment.payment_method_configuration.create.' . $bundle,
      $has_create_permission,
    ],
    [
      'payment.payment_method_configuration.view.any',
      $has_view_permission,
    ],
  ];
  $account
    ->expects($this
    ->any())
    ->method('hasPermission')
    ->willReturnMap($map);
  $language = $this
    ->createMock(LanguageInterface::class);
  $payment_method_configuration = $this
    ->getMockPaymentMethodConfiguration();
  $payment_method_configuration
    ->expects($this
    ->atLeastOnce())
    ->method('bundle')
    ->willReturn($bundle);
  $payment_method_configuration
    ->expects($this
    ->any())
    ->method('language')
    ->willReturn($language);
  $class = new \ReflectionClass($this->sut);
  $method = $class
    ->getMethod('checkAccess');
  $method
    ->setAccessible(TRUE);
  $this
    ->assertSame($expected, $method
    ->invokeArgs($this->sut, [
    $payment_method_configuration,
    $operation,
    $account,
  ])
    ->isAllowed());
}