function UserPermissionsTest::testAccessModulePermission

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/UserPermissionsTest.php \Drupal\Tests\user\Functional\UserPermissionsTest::testAccessModulePermission()
  2. 10 core/modules/user/tests/src/Functional/UserPermissionsTest.php \Drupal\Tests\user\Functional\UserPermissionsTest::testAccessModulePermission()

Verify that module-specific pages have correct access.

File

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

Class

UserPermissionsTest
Verifies role permissions can be added and removed via the permissions page.

Namespace

Drupal\Tests\user\Functional

Code

public function testAccessModulePermission() : void {
    $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.