function NavigationLinkBlockTest::testNavigationLinkBlock
Test output of the link navigation with regards to caching and contents.
File
-
core/
modules/ navigation/ tests/ src/ Functional/ NavigationLinkBlockTest.php, line 90
Class
- NavigationLinkBlockTest
- Tests for \Drupal\navigation\Plugin\Block\NavigationLinkBlockTest.
Namespace
Drupal\Tests\navigation\FunctionalCode
public function testNavigationLinkBlock() : void {
// Verify some basic cacheability metadata. Ensures that we're not doing
// anything so egregious as to upset expected caching behavior. In this
// case, as an anonymous user, we should have zero effect on the page.
$test_page_url = Url::fromRoute('test_page_test.test_page');
$this->verifyPageCache($test_page_url, 'MISS');
$this->verifyPageCache($test_page_url, 'HIT');
// Login as a limited access user, and verify that the dynamic page cache
// is working as expected.
$this->drupalLogin($this->normalUser);
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
// We should not see the admin page link in the page.
$link_selector = '.admin-toolbar__item .toolbar-button--icon--admin-link';
$this->assertSession()
->elementNotExists('css', $link_selector);
// Login as a different user, UI should update.
$this->drupalLogin($this->adminUser);
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->drupalGet(Url::fromRoute('navigation.settings'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->elementExists('css', $link_selector);
$this->assertSession()
->elementTextContains('css', $link_selector, 'Navigation Settings');
// The link should link to the admin page.
$link = $this->getSession()
->getPage()
->find('named', [
'link',
'Navigation Settings',
]);
$this->assertStringContainsString('/admin/config/user-interface/navigation/settings', $link->getAttribute('href'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.