You are here

public function MenuLinkContentFormTest::testMenuLinkContentFormLinkToAnyPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php \Drupal\Tests\menu_link_content\Functional\MenuLinkContentFormTest::testMenuLinkContentFormLinkToAnyPage()

Tests the 'link to any page' permission for a restricted page.

File

core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php, line 61

Class

MenuLinkContentFormTest
Tests the menu link content UI.

Namespace

Drupal\Tests\menu_link_content\Functional

Code

public function testMenuLinkContentFormLinkToAnyPage() {
  $menu_link = MenuLinkContent::create([
    'title' => 'Menu link test',
    'provider' => 'menu_link_content',
    'menu_name' => 'admin',
    'link' => [
      'uri' => 'internal:/user/login',
    ],
  ]);
  $menu_link
    ->save();

  // The user should be able to edit a menu link to the page, even though
  // the user cannot access the page itself.
  $this
    ->drupalGet('/admin/structure/menu/item/' . $menu_link
    ->id() . '/edit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalLogin($this->basicUser);
  $this
    ->drupalGet('/admin/structure/menu/item/' . $menu_link
    ->id() . '/edit');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}