3 namespace Drupal\Tests\system\Functional\Menu;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests the route access checks on menu links.
13 class MenuAccessTest extends BrowserTestBase {
20 public static $modules = ['block', 'menu_test'];
25 protected function setUp() {
28 $this->drupalPlaceBlock('local_tasks_block');
32 * Tests menu link for route with access check.
34 * @see \Drupal\menu_test\Access\AccessCheck::access()
36 public function testMenuBlockLinksAccessCheck() {
37 $this->drupalPlaceBlock('system_menu_block:account');
38 // Test that there's link rendered on the route.
39 $this->drupalGet('menu_test_access_check_session');
40 $this->assertLink('Test custom route access check');
41 // Page still accessible but thre should not be menu link.
42 $this->drupalGet('menu_test_access_check_session');
43 $this->assertResponse(200);
44 $this->assertNoLink('Test custom route access check');
45 // Test that page is no more accessible.
46 $this->drupalGet('menu_test_access_check_session');
47 $this->assertResponse(403);
49 // Check for access to a restricted local task from a default local task.
50 $this->drupalGet('foo/asdf');
51 $this->assertResponse(200);
52 $this->assertLinkByHref('foo/asdf');
53 $this->assertLinkByHref('foo/asdf/b');
54 $this->assertNoLinkByHref('foo/asdf/c');
56 // Attempt to access a restricted local task.
57 $this->drupalGet('foo/asdf/c');
58 $this->assertResponse(403);
59 $elements = $this->xpath('//ul[@class=:class]/li/a[@href=:href]', [
60 ':class' => 'tabs primary',
61 ':href' => Url::fromRoute('menu_test.router_test1', ['bar' => 'asdf'])->toString(),
63 $this->assertTrue(empty($elements), 'No tab linking to foo/asdf found');
64 $this->assertNoLinkByHref('foo/asdf/b');
65 $this->assertNoLinkByHref('foo/asdf/c');