You are here

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

Tests the shortcuts are correctly ordered by weight in the toolbar.

File

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

Class

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

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testShortcutLinkOrder() {

  // Ensure to give permissions to access the shortcuts.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access toolbar',
    'access shortcuts',
    'access content overview',
    'administer content types',
  ]));
  $this
    ->drupalGet(Url::fromRoute('<front>'));
  $shortcuts = $this
    ->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
  $this
    ->assertEqual($shortcuts[0]
    ->getText(), 'Add content');
  $this
    ->assertEqual($shortcuts[1]
    ->getText(), 'All content');
  foreach ($this->set
    ->getShortcuts() as $shortcut) {
    $shortcut
      ->setWeight($shortcut
      ->getWeight() * -1)
      ->save();
  }
  $this
    ->drupalGet(Url::fromRoute('<front>'));
  $shortcuts = $this
    ->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
  $this
    ->assertEqual($shortcuts[0]
    ->getText(), 'All content');
  $this
    ->assertEqual($shortcuts[1]
    ->getText(), 'Add content');
}