function UserPermissionsTest::testAccessBundlePermission

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

Verify that bundle-specific pages work properly.

File

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

Class

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

Namespace

Drupal\Tests\user\Functional

Code

public function testAccessBundlePermission() : void {
    $this->drupalLogin($this->adminUser);
    \Drupal::service('module_installer')->install([
        'contact',
        'taxonomy',
    ]);
    $this->grantPermissions(Role::load($this->rid), [
        'administer contact forms',
        'administer taxonomy',
    ]);
    // Bundles that do not have permissions have no permissions pages.
    $edit = [];
    $edit['label'] = 'Test contact type';
    $edit['id'] = 'test_contact_type';
    $edit['recipients'] = 'webmaster@example.com';
    $this->drupalGet('admin/structure/contact/add');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('Contact form ' . $edit['label'] . ' has been added.');
    $this->drupalGet('admin/structure/contact/manage/test_contact_type/permissions');
    $this->assertSession()
        ->statusCodeEquals(403);
    // Permissions can be changed using the bundle-specific pages.
    $edit = [];
    $edit['name'] = 'Test vocabulary';
    $edit['vid'] = 'test_vocabulary';
    $this->drupalGet('admin/structure/taxonomy/add');
    $this->submitForm($edit, 'Save');
    $this->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview/permissions');
    $this->assertSession()
        ->checkboxNotChecked('authenticated[create terms in test_vocabulary]');
    $this->assertSession()
        ->fieldExists('authenticated[create terms in test_vocabulary]')
        ->check();
    $this->getSession()
        ->getPage()
        ->pressButton('Save permissions');
    $this->assertSession()
        ->pageTextContains('The changes have been saved.');
    $this->assertSession()
        ->checkboxChecked('authenticated[create terms in test_vocabulary]');
    // Typos produce 404 response, not server errors.
    $this->drupalGet('admin/structure/taxonomy/manage/test_typo/overview/permissions');
    $this->assertSession()
        ->statusCodeEquals(404);
    // Anonymous users cannot access any of these pages.
    $this->drupalLogout();
    $this->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview/permissions');
    $this->assertSession()
        ->statusCodeEquals(403);
    $this->drupalGet('admin/structure/contact/manage/test_contact_type/permissions');
    $this->assertSession()
        ->statusCodeEquals(403);
}

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