function HelpTest::verifyHelp

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

Verifies the logged in user has access to the various help pages.

Parameters

int $response: (optional) An HTTP response code. Defaults to 200.

1 call to HelpTest::verifyHelp()
HelpTest::testHelp in core/modules/help/tests/src/Functional/HelpTest.php
Logs in users, tests help pages.

File

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

Class

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

Namespace

Drupal\Tests\help\Functional

Code

protected function verifyHelp($response = 200) {
    $this->drupalGet('admin/index');
    $this->assertSession()
        ->statusCodeEquals($response);
    if ($response == 200) {
        $this->assertSession()
            ->pageTextContains('This page shows you all available administration tasks for each module.');
    }
    else {
        $this->assertSession()
            ->pageTextNotContains('This page shows you all available administration tasks for each module.');
    }
    $module_list = \Drupal::service('extension.list.module');
    foreach ($this->getModuleList() as $module => $name) {
        // View module help page.
        $this->drupalGet('admin/help/' . $module);
        $this->assertSession()
            ->statusCodeEquals($response);
        if ($response == 200) {
            $this->assertSession()
                ->titleEquals("{$name} | Drupal");
            $this->assertEquals($name, $this->cssSelect('h1.page-title')[0]
                ->getText(), "{$module} heading was displayed");
            $info = $module_list->getExtensionInfo($module);
            $admin_tasks = \Drupal::service('system.module_admin_links_helper')->getModuleAdminLinks($module);
            if ($module_permissions_link = \Drupal::service('user.module_permissions_link_helper')->getModulePermissionsLink($module, $info['name'])) {
                $admin_tasks["user.admin_permissions.{$module}"] = $module_permissions_link;
            }
            if (!empty($admin_tasks)) {
                $this->assertSession()
                    ->pageTextContains($name . ' administration pages');
            }
            foreach ($admin_tasks as $task) {
                $this->assertSession()
                    ->linkExists($task['title']);
                // Ensure there are no double escaped '&' or '<' characters.
                $this->assertSession()
                    ->assertNoEscaped('&amp;');
                $this->assertSession()
                    ->assertNoEscaped('&lt;');
                // Ensure there are no escaped '<' characters.
                $this->assertSession()
                    ->assertNoEscaped('<');
            }
            // Ensure there are no double escaped '&' or '<' characters.
            $this->assertSession()
                ->assertNoEscaped('&amp;');
            $this->assertSession()
                ->assertNoEscaped('&lt;');
            // The help for CKEditor 5 intentionally has escaped '<' so leave this
            // iteration before the assertion below.
            if ($module === 'ckeditor5') {
                continue;
            }
            // Ensure there are no escaped '<' characters.
            $this->assertSession()
                ->assertNoEscaped('<');
        }
    }
}

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