function ShortcutLinksTest::testAccessShortcutsPermission

Same name and namespace in other branches
  1. 9 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testAccessShortcutsPermission()
  2. 8.9.x core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testAccessShortcutsPermission()
  3. 10 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testAccessShortcutsPermission()

Tests that the 'access shortcuts' permissions works properly.

File

core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php, line 370

Class

ShortcutLinksTest
Create, view, edit, delete, and change shortcut links.

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testAccessShortcutsPermission() : void {
    // Change to a theme that displays shortcuts.
    \Drupal::service('theme_installer')->install([
        'claro',
    ]);
    $this->config('system.theme')
        ->set('default', 'claro')
        ->save();
    // Add cron to the default shortcut set.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/config/system/cron');
    $this->clickLink('Add to Default shortcuts');
    // Verify that users without the 'access shortcuts' permission can't see the
    // shortcuts.
    $this->drupalLogin($this->drupalCreateUser([
        'access toolbar',
    ]));
    $this->assertSession()
        ->linkNotExists('Shortcuts', 'Shortcut link not found on page.');
    // Verify that users without the 'administer site configuration' permission
    // can't see the cron shortcuts but can see shortcuts.
    $this->drupalLogin($this->drupalCreateUser([
        'access toolbar',
        'access shortcuts',
    ]));
    $this->assertSession()
        ->linkExists('Shortcuts');
    $this->assertSession()
        ->linkNotExists('Cron', 'Cron shortcut link not found on page.');
    // Verify that users with the 'access shortcuts' permission can see the
    // shortcuts.
    $this->drupalLogin($this->drupalCreateUser([
        'access toolbar',
        'access shortcuts',
        'administer site configuration',
    ]));
    $this->clickLink('Shortcuts');
    $this->assertSession()
        ->linkExists('Cron', 0, 'Cron shortcut link found on page.');
    $this->verifyAccessShortcutsPermissionForEditPages();
}

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