You are here

public function ShortcutLinksTest::testAccessShortcutsPermission in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testAccessShortcutsPermission()
  2. 9 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([
    'claro',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'claro')
    ->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();
}