public function PaymentMethodAccessTest::testAccess in Commerce Core 8.2
@covers ::checkAccess
File
- modules/
payment/ tests/ src/ Kernel/ PaymentMethodAccessTest.php, line 53
Class
- PaymentMethodAccessTest
- Tests the payment method access control.
Namespace
Drupal\Tests\commerce_payment\KernelCode
public function testAccess() {
$payment_gateway = PaymentGateway::create([
'id' => 'onsite',
'label' => 'On-site',
'plugin' => 'example_onsite',
]);
$payment_gateway
->save();
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = PaymentMethod::create([
'type' => 'credit_card',
'payment_gateway' => $payment_gateway
->id(),
]);
$payment_method
->save();
$account = $this
->createUser([], [
'access administration pages',
]);
$this
->assertFalse($payment_method
->access('view', $account));
$this
->assertFalse($payment_method
->access('update', $account));
$this
->assertFalse($payment_method
->access('delete', $account));
$account = $this
->createUser([], [
'administer commerce_payment_method',
]);
$this
->assertTrue($payment_method
->access('view', $account));
$this
->assertTrue($payment_method
->access('update', $account));
$this
->assertTrue($payment_method
->access('delete', $account));
$account = $this
->createUser([], [
'view any commerce_payment_method',
]);
$this
->assertTrue($payment_method
->access('view', $account));
$this
->assertFalse($payment_method
->access('update', $account));
$this
->assertFalse($payment_method
->access('delete', $account));
$account = $this
->createUser([], [
'update any commerce_payment_method',
]);
$this
->assertFalse($payment_method
->access('view', $account));
$this
->assertTrue($payment_method
->access('update', $account));
$this
->assertFalse($payment_method
->access('delete', $account));
$account = $this
->createUser([], [
'delete any commerce_payment_method',
]);
$this
->assertFalse($payment_method
->access('view', $account));
$this
->assertFalse($payment_method
->access('update', $account));
$this
->assertTrue($payment_method
->access('delete', $account));
$first_account = $this
->createUser([], [
'manage own commerce_payment_method',
]);
$second_account = $this
->createUser([], [
'manage own commerce_payment_method',
]);
$payment_method
->setOwner($first_account);
$payment_method
->save();
$this
->assertTrue($payment_method
->access('view', $first_account));
$this
->assertTrue($payment_method
->access('update', $first_account));
$this
->assertTrue($payment_method
->access('delete', $first_account));
$this
->assertFalse($payment_method
->access('view', $second_account));
$this
->assertFalse($payment_method
->access('update', $second_account));
$this
->assertFalse($payment_method
->access('delete', $second_account));
}