function AdminTest::testAdminPages

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testAdminPages()
  2. 8.9.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testAdminPages()
  3. 10 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testAdminPages()

Tests output on administrative listing pages.

File

core/modules/system/tests/src/Functional/System/AdminTest.php, line 64

Class

AdminTest
Tests output on administrative pages and compact mode functionality.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testAdminPages() : void {
    // Go to Administration.
    $this->drupalGet('admin');
    // Verify that all visible, top-level administration links are listed on
    // the main administration page.
    foreach ($this->getTopLevelMenuLinks() as $element) {
        $item = $element->link;
        if (!$element->access
            ->isAllowed()) {
            // If the link is not accessible, it should not be rendered.
            // @see \Drupal\Core\Menu\MenuLinkTree::buildItems().
            $this->assertSession()
                ->linkNotExists($item->getTitle());
            continue;
        }
        $this->assertSession()
            ->linkExists($item->getTitle());
        $this->assertSession()
            ->linkByHrefExists($item->getUrlObject()
            ->toString());
        // The description should appear below the link.
        $this->assertSession()
            ->pageTextContains($item->getDescription());
    }
    // For each administrative listing page on which the Locale module appears,
    // verify that there are links to the module's primary configuration pages,
    // but no links to its individual sub-configuration pages. Also verify that
    // a user with access to only some Locale module administration pages only
    // sees links to the pages they have access to.
    $admin_list_pages = [
        'admin/index',
        'admin/config',
        'admin/config/regional',
    ];
    foreach ($admin_list_pages as $page) {
        // For the administrator, verify that there are links to Locale's primary
        // configuration pages, but no links to individual sub-configuration
        // pages.
        $this->drupalLogin($this->adminUser);
        $this->drupalGet($page);
        $this->assertSession()
            ->linkByHrefExists('admin/config');
        $this->assertSession()
            ->linkByHrefExists('admin/config/regional/settings');
        $this->assertSession()
            ->linkByHrefExists('admin/config/regional/date-time');
        $this->assertSession()
            ->linkByHrefExists('admin/config/regional/language');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/language/detection/session');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/language/detection/url');
        $this->assertSession()
            ->linkByHrefExists('admin/config/regional/translate');
        // On admin/index only, the administrator should also see a "Configure
        // permissions" link for the Locale module.
        if ($page == 'admin/index') {
            $this->assertSession()
                ->linkByHrefExists("admin/people/permissions/module/locale");
        }
        // For a less privileged user, verify that there are no links to Locale's
        // primary configuration pages, but a link to the translate page exists.
        $this->drupalLogin($this->webUser);
        $this->drupalGet($page);
        $this->assertSession()
            ->linkByHrefExists('admin/config');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/settings');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/date-time');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/language');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/language/detection/session');
        $this->assertSession()
            ->linkByHrefNotExists('admin/config/regional/language/detection/url');
        $this->assertSession()
            ->linkByHrefExists('admin/config/regional/translate');
        // This user cannot configure permissions, so even on admin/index should
        // not see a "Configure permissions" link for the Locale module.
        if ($page == 'admin/index') {
            $this->assertSession()
                ->linkByHrefNotExists("admin/people/permissions#module-locale");
        }
    }
}

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