You are here

public function HelpTopicTest::testHelp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/help_topics/tests/src/Functional/HelpTopicTest.php \Drupal\Tests\help_topics\Functional\HelpTopicTest::testHelp()

Tests the main help page and individual pages for topics.

File

core/modules/help_topics/tests/src/Functional/HelpTopicTest.php, line 82

Class

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

Namespace

Drupal\Tests\help_topics\Functional

Code

public function testHelp() {
  $session = $this
    ->assertSession();

  // Log in the regular user.
  $this
    ->drupalLogin($this->anyUser);
  $this
    ->verifyHelp(403);

  // Log in the admin user.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->verifyHelp();
  $this
    ->verifyHelpLinks();
  $this
    ->verifyBreadCrumb();

  // Verify that help topics text appears on admin/help, and cache tags.
  $this
    ->drupalGet('admin/help');
  $session
    ->responseContains('<h2>Topics</h2>');
  $session
    ->pageTextContains('Topics can be provided by modules or themes');
  $session
    ->responseHeaderContains('X-Drupal-Cache-Tags', 'core.extension');

  // Verify links for for help topics and order.
  $page_text = $this
    ->getTextContent();
  $start = strpos($page_text, 'Topics can be provided');
  $pos = $start;
  foreach ($this
    ->getTopicList() as $info) {
    $name = $info['name'];
    $session
      ->linkExists($name);
    $new_pos = strpos($page_text, $name, $start);
    $this
      ->assertTrue($new_pos > $pos, 'Order of ' . $name . ' is correct on page');
    $pos = $new_pos;
  }

  // Ensure the plugin manager alter hook works as expected.
  $session
    ->linkExists('ABC Help Test module');
  \Drupal::state()
    ->set('help_topics_test.test:top_level', FALSE);
  \Drupal::service('plugin.manager.help_topic')
    ->clearCachedDefinitions();
  $this
    ->drupalGet('admin/help');
  $session
    ->linkNotExists('ABC Help Test module');
  \Drupal::state()
    ->set('help_topics_test.test:top_level', TRUE);
  \Drupal::service('plugin.manager.help_topic')
    ->clearCachedDefinitions();
  $this
    ->drupalGet('admin/help');

  // Ensure all the expected links are present before uninstalling.
  $session
    ->linkExists('ABC Help Test module');
  $session
    ->linkExists('ABC Help Test');
  $session
    ->linkExists('XYZ Help Test theme');

  // Uninstall the test module and verify the topics are gone, after
  // reloading page.
  $this->container
    ->get('module_installer')
    ->uninstall([
    'help_topics_test',
  ]);
  $this
    ->drupalGet('admin/help');
  $session
    ->linkNotExists('ABC Help Test module');
  $session
    ->linkNotExists('ABC Help Test');
  $session
    ->linkExists('XYZ Help Test theme');

  // Uninstall the test theme and verify the topic is gone.
  $this->container
    ->get('theme_installer')
    ->uninstall([
    'help_topics_test_theme',
  ]);
  $this
    ->drupalGet('admin/help');
  $session
    ->linkNotExists('XYZ Help Test theme');
}