function ShortcutLinksTest::testShortcutLinkOrder

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

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->assertEquals('Add content', $shortcuts[0]->getText());
    $this->assertEquals('All content', $shortcuts[1]->getText());
    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->assertEquals('All content', $shortcuts[0]->getText());
    $this->assertEquals('Add content', $shortcuts[1]->getText());
}

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