MenuAccessTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/Menu/MenuAccessTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Menu;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class MenuAccessTest extends BrowserTestBase {
protected static $modules = [
'block',
'menu_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
}
public function testMenuBlockLinksAccessCheck() {
$this
->drupalPlaceBlock('system_menu_block:account');
$this
->drupalGet('menu_test_access_check_session');
$this
->assertSession()
->linkExists('Test custom route access check');
$this
->drupalGet('menu_test_access_check_session');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkNotExists('Test custom route access check');
$this
->drupalGet('menu_test_access_check_session');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet('foo/asdf');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkByHrefExists('foo/asdf');
$this
->assertSession()
->linkByHrefExists('foo/asdf/b');
$this
->assertSession()
->linkByHrefNotExists('foo/asdf/c');
$this
->drupalGet('foo/asdf/c');
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->elementNotExists('xpath', $this
->assertSession()
->buildXPathQuery('//ul[@class="tabs primary"]/li/a[@href=:href]', [
':href' => Url::fromRoute('menu_test.router_test1', [
'bar' => 'asdf',
])
->toString(),
]));
$this
->assertSession()
->linkByHrefNotExists('foo/asdf/b');
$this
->assertSession()
->linkByHrefNotExists('foo/asdf/c');
}
}