You are here

protected function HelpTest::verifyHelp in Drupal 9

Same name and namespace in other branches
  1. 8 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 119

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.');
  }
  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 = \Drupal::service('extension.list.module')
        ->getExtensionInfo($module);
      $admin_tasks = system_get_module_admin_tasks($module, $info);
      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;');

      // Ensure there are no escaped '<' characters.
      $this
        ->assertSession()
        ->assertNoEscaped('<');
    }
  }
}