You are here

public function ShortcutLinksTest::testNoShortcutLink in Drupal 8

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

Tests that the add shortcut link is not displayed for 404/403 errors.

Tests that the "Add to shortcuts" link is not displayed on a page not found or a page the user does not have access to.

File

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

Class

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

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testNoShortcutLink() {

  // Change to a theme that displays shortcuts.
  \Drupal::service('theme_installer')
    ->install([
    'seven',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'seven')
    ->save();
  $this
    ->drupalGet('page-that-does-not-exist');
  $result = $this
    ->xpath('//a[contains(@class, "shortcut-action--add")]');
  $this
    ->assertTrue(empty($result), 'Add to shortcuts link was not shown on a page not found.');

  // The user does not have access to this path.
  $this
    ->drupalGet('admin/modules');
  $result = $this
    ->xpath('//a[contains(@class, "shortcut-action--add")]');
  $this
    ->assertTrue(empty($result), 'Add to shortcuts link was not shown on a page the user does not have access to.');

  // Verify that the testing mechanism works by verifying the shortcut link
  // appears on admin/content.
  $this
    ->drupalGet('admin/content');
  $result = $this
    ->xpath('//a[contains(@class, "shortcut-action--remove")]');
  $this
    ->assertTrue(!empty($result), 'Remove from shortcuts link was shown on a page the user does have access to.');

  // Verify that the shortcut link appears on routing only pages.
  $this
    ->drupalGet('router_test/test2');
  $result = $this
    ->xpath('//a[contains(@class, "shortcut-action--add")]');
  $this
    ->assertTrue(!empty($result), 'Add to shortcuts link was shown on a page the user does have access to.');
}