public function HelpTopicsSyntaxTest::testHelpTopics in Drupal 9
Same name and namespace in other branches
- 8 core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help_topics\Functional\HelpTopicsSyntaxTest::testHelpTopics()
Tests that all Core help topics can be rendered and have good syntax.
File
- core/
modules/ help_topics/ tests/ src/ Functional/ HelpTopicsSyntaxTest.php, line 41
Class
- HelpTopicsSyntaxTest
- Verifies that all core Help topics can be rendered and comply with standards.
Namespace
Drupal\Tests\help_topics\FunctionalCode
public function testHelpTopics() {
$this
->drupalLogin($this->rootUser);
// 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 strpos($directory, 'core') === 0;
});
// 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('seven', $directories, 'Seven 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 (strpos($id, 'bad_help_topics.') === 0) {
$this
->verifyBadTopic($id, $definitions);
}
else {
$this
->verifyTopic($id, $definitions);
}
}
}