You are here

public function UserPermissionsTest::testAccessModulePermission in Drupal 10

Verify that module-specific pages have correct access.

File

core/modules/user/tests/src/Functional/UserPermissionsTest.php, line 219

Class

UserPermissionsTest
Verify that role permissions can be added and removed via the permissions pages.

Namespace

Drupal\Tests\user\Functional

Code

public function testAccessModulePermission() {
  $this
    ->drupalLogin($this->adminUser);

  // When Node is not installed, the node-permissions page is not available.
  $this
    ->drupalGet('admin/people/permissions/module/node');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Modules that do not create permissions have no permissions pages.
  \Drupal::service('module_installer')
    ->install([
    'automated_cron',
  ]);
  $this
    ->drupalGet('admin/people/permissions/module/automated_cron');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet('admin/people/permissions/module/node,automated_cron');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // When Node is installed, the node-permissions page is available.
  \Drupal::service('module_installer')
    ->install([
    'node',
  ]);
  $this
    ->drupalGet('admin/people/permissions/module/node');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet('admin/people/permissions/module/node,automated_cron');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Anonymous users cannot access any of these pages.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('admin/people/permissions/module/node');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet('admin/people/permissions/module/automated_cron');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet('admin/people/permissions/module/node,automated_cron');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}