function HelpTopicsSyntaxTest::testHelpTopics
Same name in other branches
- 9 core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help_topics\Functional\HelpTopicsSyntaxTest::testHelpTopics()
- 8.9.x core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help_topics\Functional\HelpTopicsSyntaxTest::testHelpTopics()
- 11.x core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help\Functional\HelpTopicsSyntaxTest::testHelpTopics()
Tests that all Core help topics can be rendered and have good syntax.
File
-
core/
modules/ help/ tests/ src/ Functional/ HelpTopicsSyntaxTest.php, line 40
Class
- HelpTopicsSyntaxTest
- Verifies that all core Help topics can be rendered and comply with standards.
Namespace
Drupal\Tests\help\FunctionalCode
public function testHelpTopics() : void {
$this->drupalLogin($this->createUser([
'administer modules',
'access help pages',
]));
// Enable all modules and themes, so that all routes mentioned in topics
// will be defined.
$module_directories = $this->listDirectories('module');
$modules_to_install = array_keys($module_directories);
\Drupal::service('module_installer')->install($modules_to_install);
$theme_directories = $this->listDirectories('theme');
\Drupal::service('theme_installer')->install(array_keys($theme_directories));
$directories = $module_directories + $theme_directories + $this->listDirectories('profile');
$directories['core'] = \Drupal::root() . '/core/help_topics';
$directories['bad_help_topics'] = \Drupal::service('extension.list.module')->getPath('help_topics_test') . '/bad_help_topics/syntax/';
// Filter out directories outside of core. If you want to run this test
// on a contrib/custom module, remove the next line.
$directories = array_filter($directories, function ($directory) {
return str_starts_with($directory, 'core');
});
// Verify that a few key modules, themes, and profiles are listed, so that
// we can be certain our directory list is complete and we will be testing
// all existing help topics. If these lines in the test fail in the future,
// it is probably because something we chose to list here is being removed.
// Substitute another item of the same type that still exists, so that this
// test can continue.
$this->assertArrayHasKey('system', $directories, 'System module is being scanned');
$this->assertArrayHasKey('help', $directories, 'Help module is being scanned');
$this->assertArrayHasKey('claro', $directories, 'Claro theme is being scanned');
$this->assertArrayHasKey('standard', $directories, 'Standard profile is being scanned');
$definitions = (new HelpTopicDiscovery($directories))->getDefinitions();
$this->assertGreaterThan(0, count($definitions), 'At least 1 topic was found');
// Test each topic for compliance with standards, or for failing in the
// right way.
foreach (array_keys($definitions) as $id) {
if (str_starts_with($id, 'bad_help_topics.')) {
$this->verifyBadTopic($id, $definitions);
}
else {
$this->verifyTopic($id, $definitions);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.