function ShortcutLinksTest::testAccessShortcutsPermission

Same name in other branches
  1. 9 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testAccessShortcutsPermission()
  2. 10 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testAccessShortcutsPermission()
  3. 11.x 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 340

Class

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

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testAccessShortcutsPermission() {
    // Change to a theme that displays shortcuts.
    \Drupal::service('theme_installer')->install([
        'seven',
    ]);
    $this->config('system.theme')
        ->set('default', 'seven')
        ->save();
    // Add cron to the default shortcut set.
    $this->drupalLogin($this->rootUser);
    $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', 0, 'Shortcut link found on page.');
    $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.