function MenuUiTest::testUserLoginUserLogoutLinks

Same name in other branches
  1. 10 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testUserLoginUserLogoutLinks()

Tests the user login/logout links.

File

core/modules/menu_ui/tests/src/Functional/MenuUiTest.php, line 1239

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testUserLoginUserLogoutLinks() : void {
    MenuLinkContent::create([
        'menu' => 'tools',
        'link' => [
            'uri' => 'internal:/user/login',
        ],
        'title' => 'Login',
    ])->save();
    MenuLinkContent::create([
        'menu' => 'tools',
        'link' => [
            'uri' => 'internal:/user/logout',
        ],
        'title' => 'Logout',
    ])->save();
    $assert = $this->assertSession();
    $block = $this->drupalPlaceBlock('system_menu_block:tools');
    $this->drupalGet('<front>');
    $assert->linkExists('Login');
    $assert->linkNotExists('Logout');
    $this->drupalLogin($this->createUser());
    $this->drupalGet('<front>');
    $assert->linkNotExists('Login');
    $assert->linkExists('Logout');
    // Delete the block, we're now checking the Menu UI form.
    $block->delete();
    $this->drupalLogin($this->createUser([
        'administer menu',
    ]));
    $this->drupalGet('admin/structure/menu/manage/tools');
    $assert->linkExists('Logout');
    // Check that the login link is accessible even the route is not.
    $this->assertFalse(Url::fromRoute('user.login')->access($this->loggedInUser));
    $assert->linkExists('Login');
}

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