You are here

public function ShortcutLinksTest::testShortcutLinkChangePath 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::testShortcutLinkChangePath()
  2. 10 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testShortcutLinkChangePath()

Tests that changing the path of a shortcut link works.

File

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

Class

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

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testShortcutLinkChangePath() {
  $set = $this->set;

  // Tests changing a shortcut path.
  $new_link_path = '/admin/config';
  $shortcuts = $set
    ->getShortcuts();
  $shortcut = reset($shortcuts);
  $this
    ->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut
    ->id(), [
    'title[0][value]' => $shortcut
      ->getTitle(),
    'link[0][uri]' => $new_link_path,
  ], t('Save'));
  $saved_set = ShortcutSet::load($set
    ->id());
  $paths = $this
    ->getShortcutInformation($saved_set, 'link');
  $this
    ->assertContains('internal:' . $new_link_path, $paths, 'Shortcut path changed: ' . $new_link_path);
  $this
    ->assertLinkByHref($new_link_path, 0, 'Shortcut with new path appears on the page.');
  $this
    ->assertText(t('The shortcut @link has been updated.', [
    '@link' => $shortcut
      ->getTitle(),
  ]));
}