function HelpTopicTest::testHelpLinks

Same name in other branches
  1. 9 core/modules/help_topics/tests/src/Functional/HelpTopicTest.php \Drupal\Tests\help_topics\Functional\HelpTopicTest::testHelpLinks()
  2. 10 core/modules/help/tests/src/Functional/HelpTopicTest.php \Drupal\Tests\help\Functional\HelpTopicTest::testHelpLinks()

Verifies links on various topic pages.

File

core/modules/help/tests/src/Functional/HelpTopicTest.php, line 186

Class

HelpTopicTest
Verifies help topic display and user access to help based on permissions.

Namespace

Drupal\Tests\help\Functional

Code

public function testHelpLinks() : void {
    $session = $this->assertSession();
    $this->drupalLogin($this->adminUser);
    // Verify links on the test top-level page.
    $page = 'admin/help/topic/help_topics_test.test';
    // Array element is the page text if you click through.
    $links = [
        'Linked topic' => 'This topic is not supposed to be top-level',
        'Additional topic' => 'This topic should get listed automatically',
        'URL test topic' => 'It is used to test URLs',
    ];
    foreach ($links as $link_text => $page_text) {
        $this->drupalGet($page);
        $this->clickLink($link_text);
        $session->pageTextContains($page_text);
    }
    // Verify theme provided help topics work and can be related.
    $this->drupalGet('admin/help/topic/help_topics_test_theme.test');
    $session->pageTextContains('This is a theme provided topic.');
    $this->assertStringContainsString('This is a theme provided topic.', $session->elementExists('css', 'article')
        ->getText());
    $this->clickLink('Additional topic');
    $session->linkExists('XYZ Help Test theme');
    // Verify that the non-top-level topics do not appear on the Help page.
    $this->drupalGet('admin/help');
    $session->linkNotExists('Linked topic');
    $session->linkNotExists('Additional topic');
    // Verify links and non-links on the URL test page.
    $this->drupalGet('admin/help/topic/help_topics_test.test_urls');
    $links = [
        'not a route' => FALSE,
        'missing params' => FALSE,
        'invalid params' => FALSE,
        'valid link' => TRUE,
        'Additional topic' => TRUE,
        'Missing help topic not_a_topic' => FALSE,
    ];
    foreach ($links as $text => $should_be_link) {
        if ($should_be_link) {
            $session->linkExists($text);
        }
        else {
            // Should be text that is not a link.
            $session->pageTextContains($text);
            $session->linkNotExists($text);
        }
    }
    // Verify that the "no test" user, who should not be able to access
    // the 'valid link' URL, sees it as not a link.
    $this->drupalLogin($this->noTestUser);
    $this->drupalGet('admin/help/topic/help_topics_test.test_urls');
    $session->pageTextContains('valid link');
    $session->linkNotExists('valid link');
}

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