function MenuActiveTrail403Test::setUp

Same name in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Menu/MenuActiveTrail403Test.php \Drupal\FunctionalTests\Menu\MenuActiveTrail403Test::setUp()
  2. 11.x core/tests/Drupal/FunctionalTests/Menu/MenuActiveTrail403Test.php \Drupal\FunctionalTests\Menu\MenuActiveTrail403Test::setUp()

Overrides BrowserTestBase::setUp

File

core/tests/Drupal/FunctionalTests/Menu/MenuActiveTrail403Test.php, line 43

Class

MenuActiveTrail403Test
Tests that 403 active trail behavior does not overwrite original entry.

Namespace

Drupal\FunctionalTests\Menu

Code

protected function setUp() : void {
    parent::setUp();
    // Place the menu block, so menu trail gets built and cached. Showing the
    // menu starting from the second level, so it is only shown when the active
    // trail matches.
    $this->drupalPlaceBlock('system_menu_block:' . $this->menu, [
        'level' => 2,
    ]);
    // Menu content, where the privileged user has access and the anonymous does
    // not have access. This route will be visited by both users. The privileged
    // user should see the menu with the menu content item created below.
    $parent_menu_link_content = MenuLinkContent::create([
        'title' => 'Admin overview',
        'menu_name' => 'footer',
        'link' => [
            'uri' => 'route:system.admin',
        ],
    ]);
    $parent_menu_link_content->save();
    // Menu content for the second level, which should be shown in the menu for
    // the privileged user.
    $menu_link_content = MenuLinkContent::create([
        'title' => 'Link to Status page',
        'menu_name' => 'footer',
        'link' => [
            'uri' => 'route:system.status',
        ],
        'parent' => 'menu_link_content:' . $parent_menu_link_content->uuid(),
    ]);
    $menu_link_content->save();
    $privileged_permissions = [
        'access administration pages',
        'administer site configuration',
    ];
    // Create a user who can access system.status and system.admin.
    $this->privilegedUser = $this->drupalCreateUser($privileged_permissions);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.