MenuAccessTest.php in Drupal 8
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 {
public static $modules = [
'block',
'menu_test',
];
protected $defaultTheme = 'stark';
protected function setUp() {
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
->assertLinkByHref('foo/asdf');
$this
->assertLinkByHref('foo/asdf/b');
$this
->assertNoLinkByHref('foo/asdf/c');
$this
->drupalGet('foo/asdf/c');
$this
->assertSession()
->statusCodeEquals(403);
$elements = $this
->xpath('//ul[@class=:class]/li/a[@href=:href]', [
':class' => 'tabs primary',
':href' => Url::fromRoute('menu_test.router_test1', [
'bar' => 'asdf',
])
->toString(),
]);
$this
->assertTrue(empty($elements), 'No tab linking to foo/asdf found');
$this
->assertNoLinkByHref('foo/asdf/b');
$this
->assertNoLinkByHref('foo/asdf/c');
}
}