You are here

public function PaymentMethodTest::testUserAccess in Commerce Core 8.2

Tests accessing the payment method pages.

File

modules/payment/tests/src/Functional/PaymentMethodTest.php, line 74

Class

PaymentMethodTest
Tests the payment method UI.

Namespace

Drupal\Tests\commerce_payment\Functional

Code

public function testUserAccess() {
  $this
    ->drupalGet('user/' . $this->adminUser
    ->id() . '/payment-methods');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet('user/' . $this->adminUser
    ->id() . '/payment-methods/add');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalLogout();

  // Ensure anonymous users don't have access to the manage payment methods
  // page, even if either the "manage own payment methods" permission or
  // the "administer commerce_payment_method" is granted.
  $role = Role::load(AccountInterface::ANONYMOUS_ROLE);
  $role
    ->grantPermission('manage own commerce_payment_method');
  $role
    ->grantPermission('administer commerce_payment_method');
  $role
    ->trustData()
    ->save();
  $this
    ->drupalGet('user/0/payment-methods');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet('user/0/payment-methods/add');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}