function UserPermissionsTest::testAccessBundlePermission

Same name and namespace in other branches
  1. 10 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 255

Class

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

Namespace

Drupal\Tests\user\Functional

Code

public function testAccessBundlePermission() {
    $this->drupalLogin($this->adminUser);
    \Drupal::service('module_installer')->install([
        'block_content',
        'taxonomy',
    ]);
    $this->grantPermissions(Role::load($this->rid), [
        'administer blocks',
        'administer taxonomy',
    ]);
    // Bundles that do not have permissions have no permissions pages.
    $edit = [];
    $edit['label'] = 'Test block type';
    $edit['id'] = 'test_block_type';
    $this->drupalGet('admin/structure/block/block-content/types/add');
    $this->submitForm($edit, 'Save');
    $this->drupalGet('admin/structure/block/block-content/manage/test_block_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/block/block-content/manage/test_block_type/permissions');
    $this->assertSession()
        ->statusCodeEquals(403);
}

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