Chris@0: adminUser = $this->drupalCreateUser(['access administration pages', 'view the administration theme', 'administer permissions']); Chris@0: $this->anyUser = $this->drupalCreateUser([]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Logs in users, tests help pages. Chris@0: */ Chris@0: public function testHelp() { Chris@0: // Log in the root user to ensure as many admin links appear as possible on Chris@0: // the module overview pages. Chris@0: $this->drupalLogin($this->rootUser); Chris@0: $this->verifyHelp(); Chris@0: Chris@0: // Log in the regular user. Chris@0: $this->drupalLogin($this->anyUser); Chris@0: $this->verifyHelp(403); Chris@0: Chris@0: // Verify that introductory help text exists, goes for 100% module coverage. Chris@0: $this->drupalLogin($this->adminUser); Chris@0: $this->drupalGet('admin/help'); Chris@0: $this->assertRaw(t('For more information, refer to the help listed on this page or to the online documentation and support pages at drupal.org.', [':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org'])); Chris@0: Chris@0: // Verify that hook_help() section title and description appear. Chris@0: $this->assertRaw('

' . t('Module overviews') . '

'); Chris@0: $this->assertRaw('

' . t('Module overviews are provided by modules. Overviews available for your installed modules:'), '

'); Chris@0: Chris@0: // Verify that an empty section is handled correctly. Chris@0: $this->assertRaw('

' . t('Empty section') . '

'); Chris@0: $this->assertRaw('

' . t('This description should appear.'), '

'); Chris@0: $this->assertText(t('There is currently nothing in this section.')); Chris@0: Chris@0: // Make sure links are properly added for modules implementing hook_help(). Chris@0: foreach ($this->getModuleList() as $module => $name) { Chris@0: $this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', ['@module' => $module, '@name' => $name])); Chris@0: } Chris@0: Chris@0: // Ensure that module which does not provide an module overview page is Chris@0: // handled correctly. Chris@0: $this->clickLink(\Drupal::moduleHandler()->getName('help_test')); Chris@0: $this->assertRaw(t('No help is available for module %module.', ['%module' => \Drupal::moduleHandler()->getName('help_test')])); Chris@0: Chris@0: // Verify that the order of topics is alphabetical by displayed module Chris@0: // name, by checking the order of some modules, including some that would Chris@0: // have a different order if it was done by machine name instead. Chris@0: $this->drupalGet('admin/help'); Chris@0: $page_text = $this->getTextContent(); Chris@0: $start = strpos($page_text, 'Module overviews'); Chris@0: $pos = $start; Chris@0: $list = ['Block', 'Color', 'Custom Block', 'History', 'Text Editor']; Chris@0: foreach ($list as $name) { Chris@0: $this->assertLink($name); Chris@0: $new_pos = strpos($page_text, $name, $start); Chris@0: $this->assertTrue($new_pos > $pos, 'Order of ' . $name . ' is correct on page'); Chris@0: $pos = $new_pos; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Verifies the logged in user has access to the various help pages. Chris@0: * Chris@0: * @param int $response Chris@0: * (optional) An HTTP response code. Defaults to 200. Chris@0: */ Chris@0: protected function verifyHelp($response = 200) { Chris@0: $this->drupalGet('admin/index'); Chris@0: $this->assertResponse($response); Chris@0: if ($response == 200) { Chris@0: $this->assertText('This page shows you all available administration tasks for each module.'); Chris@0: } Chris@0: else { Chris@0: $this->assertNoText('This page shows you all available administration tasks for each module.'); Chris@0: } Chris@0: Chris@0: foreach ($this->getModuleList() as $module => $name) { Chris@0: // View module help page. Chris@0: $this->drupalGet('admin/help/' . $module); Chris@0: $this->assertResponse($response); Chris@0: if ($response == 200) { Chris@0: $this->assertTitle($name . ' | Drupal', format_string('%module title was displayed', ['%module' => $module])); Chris@0: $this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed"); Chris@0: $admin_tasks = system_get_module_admin_tasks($module, system_get_info('module', $module)); Chris@0: if (!empty($admin_tasks)) { Chris@0: $this->assertText(t('@module administration pages', ['@module' => $name])); Chris@0: } Chris@0: foreach ($admin_tasks as $task) { Chris@0: $this->assertLink($task['title']); Chris@0: // Ensure there are no double escaped '&' or '<' characters. Chris@0: $this->assertNoEscaped('&', 'The help text does not have double escaped &.'); Chris@0: $this->assertNoEscaped('<', 'The help text does not have double escaped <.'); Chris@0: // Ensure there are no escaped '<' characters. Chris@0: $this->assertNoEscaped('<', 'The help text does not have single escaped <.'); Chris@0: } Chris@0: // Ensure there are no double escaped '&' or '<' characters. Chris@0: $this->assertNoEscaped('&'); Chris@0: $this->assertNoEscaped('<'); Chris@0: // Ensure there are no escaped '<' characters. Chris@0: $this->assertNoEscaped('<'); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the list of enabled modules that implement hook_help(). Chris@0: * Chris@0: * @return array Chris@0: * A list of enabled modules. Chris@0: */ Chris@0: protected function getModuleList() { Chris@0: $modules = []; Chris@0: $module_data = system_rebuild_module_data(); Chris@0: foreach (\Drupal::moduleHandler()->getImplementations('help') as $module) { Chris@0: $modules[$module] = $module_data[$module]->info['name']; Chris@0: } Chris@0: return $modules; Chris@0: } Chris@0: Chris@0: }