You are here

public function ShortcutLinksTest::testAccessShortcutsPermission in Drupal 9

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

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();
}