function ShortcutLinksTest::testNoShortcutLink

Same name and namespace in other branches
  1. 8.9.x 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()
  3. 11.x 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 316

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([
        'claro',
    ]);
    $this->config('system.theme')
        ->set('default', 'claro')
        ->save();
    $this->drupalGet('page-that-does-not-exist');
    // Test that add to shortcuts link is not shown on a page not found.
    $this->assertSession()
        ->elementNotExists('xpath', '//a[contains(@class, "shortcut-action--add")]');
    // The user does not have access to this path.
    $this->drupalGet('admin/modules');
    $this->assertSession()
        ->elementNotExists('xpath', '//a[contains(@class, "shortcut-action--add")]');
    // Verify that the testing mechanism works by verifying the shortcut link
    // appears on admin/content.
    $this->drupalGet('admin/content');
    $this->assertSession()
        ->elementExists('xpath', '//a[contains(@class, "shortcut-action--remove")]');
    // Verify that the shortcut link appears on routing only pages.
    $this->drupalGet('router_test/test2');
    $this->assertSession()
        ->elementExists('xpath', '//a[contains(@class, "shortcut-action--add")]');
}

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