function ToolbarAdminMenuTest::testExternalLink

Same name in other branches
  1. 9 core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testExternalLink()
  2. 8.9.x core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testExternalLink()
  3. 10 core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testExternalLink()

Tests that external links added to the menu appear in the toolbar.

File

core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php, line 428

Class

ToolbarAdminMenuTest
Tests the caching of the admin menu subtree items.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testExternalLink() : void {
    $edit = [
        'title[0][value]' => 'External URL',
        'link[0][uri]' => 'http://example.org',
        'menu_parent' => 'admin:system.admin',
        'description[0][value]' => 'External URL & escaped',
    ];
    $this->drupalGet('admin/structure/menu/manage/admin/add');
    $this->submitForm($edit, 'Save');
    // Assert that the new menu link is shown on the menu link listing.
    $this->drupalGet('admin/structure/menu/manage/admin');
    $this->assertSession()
        ->pageTextContains('External URL');
    // Assert that the new menu link is shown in the toolbar on a regular page.
    $this->drupalGet(Url::fromRoute('<front>'));
    $this->assertSession()
        ->pageTextContains('External URL');
    // Ensure the description is escaped as expected.
    $this->assertSession()
        ->responseContains('title="External URL &amp; escaped"');
}

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