public function PaymentMethodAccessTest::testDeletedGateway in Commerce Core 8.2
@covers ::checkAccess
File
- modules/
payment/ tests/ src/ Kernel/ PaymentMethodAccessTest.php, line 110
Class
- PaymentMethodAccessTest
- Tests the payment method access control.
Namespace
Drupal\Tests\commerce_payment\KernelCode
public function testDeletedGateway() {
$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();
$payment_gateway
->delete();
$payment_method = $this
->reloadEntity($payment_method);
// Confirm that not even the administrator can update the payment
// method if its gateway has been deleted.
$account = $this
->createUser([], [
'administer commerce_payment_method',
]);
$this
->assertTrue($payment_method
->access('view', $account));
$this
->assertFalse($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
->assertFalse($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));
}