function HelpTest::testHelp

Same name in other branches
  1. 9 core/modules/help/tests/src/Functional/HelpTest.php \Drupal\Tests\help\Functional\HelpTest::testHelp()
  2. 10 core/modules/help/tests/src/Functional/HelpTest.php \Drupal\Tests\help\Functional\HelpTest::testHelp()
  3. 11.x core/modules/help/tests/src/Functional/HelpTest.php \Drupal\Tests\help\Functional\HelpTest::testHelp()

Logs in users, tests help pages.

File

core/modules/help/tests/src/Functional/HelpTest.php, line 63

Class

HelpTest
Verify help display and user access to help based on permissions.

Namespace

Drupal\Tests\help\Functional

Code

public function testHelp() {
    // Log in the root user to ensure as many admin links appear as possible on
    // the module overview pages.
    $this->drupalLogin($this->rootUser);
    $this->verifyHelp();
    // Log in the regular user.
    $this->drupalLogin($this->anyUser);
    $this->verifyHelp(403);
    // Verify that introductory help text exists, goes for 100% module coverage.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/help');
    $this->assertRaw(t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', [
        ':docs' => 'https://www.drupal.org/documentation',
        ':support' => 'https://www.drupal.org/support',
        ':drupal' => 'https://www.drupal.org',
    ]));
    // Verify that hook_help() section title and description appear.
    $this->assertRaw('<h2>' . t('Module overviews') . '</h2>');
    $this->assertRaw('<p>' . t('Module overviews are provided by modules. Overviews available for your installed modules:'), '</p>');
    // Verify that an empty section is handled correctly.
    $this->assertRaw('<h2>' . t('Empty section') . '</h2>');
    $this->assertRaw('<p>' . t('This description should appear.'), '</p>');
    $this->assertText(t('There is currently nothing in this section.'));
    // Make sure links are properly added for modules implementing hook_help().
    foreach ($this->getModuleList() as $module => $name) {
        $this->assertSession()
            ->linkExists($name, 0, new FormattableMarkup('Link properly added to @name (admin/help/@module)', [
            '@module' => $module,
            '@name' => $name,
        ]));
    }
    // Ensure that module which does not provide an module overview page is
    // handled correctly.
    $this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
    $this->assertRaw(t('No help is available for module %module.', [
        '%module' => \Drupal::moduleHandler()->getName('help_test'),
    ]));
    // Verify that the order of topics is alphabetical by displayed module
    // name, by checking the order of some modules, including some that would
    // have a different order if it was done by machine name instead.
    $this->drupalGet('admin/help');
    $page_text = $this->getTextContent();
    $start = strpos($page_text, 'Module overviews');
    $pos = $start;
    $list = [
        'Block',
        'Color',
        'Custom Block',
        'History',
        'Text Editor',
    ];
    foreach ($list as $name) {
        $this->assertSession()
            ->linkExists($name);
        $new_pos = strpos($page_text, $name, $start);
        $this->assertTrue($new_pos > $pos, 'Order of ' . $name . ' is correct on page');
        $pos = $new_pos;
    }
}

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