diff -u b/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php b/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php --- b/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php +++ b/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php @@ -64,25 +64,44 @@ foreach (array_keys($definitions) as $id) { $this->verifyTopic($id, $definitions, $top_level); } + } - // Create a single topic that is expected to fail discovery. - vfsStream::setup('root'); - vfsStream::create([ - 'modules' => [ - 'test' => [ - 'help_topics' => [ - // An invalid topic missing required details. - 'test.topic.html.twig' => '', - ], - ], + /** + * Tests that help topic discovery fails in expected ways. + */ + public function testDiscoveryExceptions() { + $base_bad_directory = \Drupal::service('extension.list.module')->getPath('help_topics_test') . '/bad_help_topics/discovery/'; + $discovery_problems = [ + [ + 'subdirectory' => 'provider', + 'file' => 'test.topic.html.twig', + 'message' => "file name should begin with 'expected_failure'", + ], + [ + 'subdirectory' => 'top_level', + 'file' => 'expected_failure.topic.html.twig', + 'message' => "contains invalid meta tag with name='help_topic:top_level', the 'content' property should not exist", ], - ]); - $fail_directories['expected_failure'] = vfsStream::url('root/modules/test/help_topics'); + [ + 'subdirectory' => 'bad_meta', + 'file' => 'expected_failure.topic.html.twig', + 'message' => "contains invalid meta tag with name='foo'", + ], + [ + 'subdirectory' => 'no_label', + 'file' => 'expected_failure.topic.html.twig', + 'message' => "does not contain the required meta tag with name='help_topic:label'", + ], + ]; - // Check that just this expected failure topic does throw an exception. - $this->expectException(DiscoveryException::class); - $this->expectExceptionMessage("vfs://root/modules/test/help_topics/test.topic.html.twig should begin with 'expected_failure.'"); - $this->discoverAllTopics($fail_directories); + foreach ($discovery_problems as $info) { + $fail_directories = [ + 'expected_failure' => $base_bad_directory . $info['subdirectory'], + ]; + $this->expectException(DiscoveryException::class); + $this->expectExceptionMessage($fail_directories['expected_failure'] . '/' . $info['file'] . ' ' . $info['message']); + $this->discoverAllTopics($fail_directories); + } } /** @@ -168,14 +187,14 @@ } /** - * Lists the extension directories of a certain type. + * Lists the extension help topic directories of a certain type. * * @param string $type * The type of extension to list: module, theme, or profile. * * @return string[] - * An array of all of the directories of this type of extension, keyed by - * extension short name. + * An array of all of the help topic directories for this type of + * extension, keyed by extension short name. */ protected function listDirectories($type) { $directories = []; only in patch2: unchanged: --- a/core/modules/help_topics/src/HelpTopicDiscovery.php +++ b/core/modules/help_topics/src/HelpTopicDiscovery.php @@ -102,7 +102,7 @@ public function findAll() { // help_topics special case once Help Topics is stable and core // modules can provide their own help topics. if ($provider !== 'help_topics' && $provider !== $file_name_provider) { - throw new DiscoveryException("$file should begin with '$provider.'"); + throw new DiscoveryException("$file file name should begin with '$provider'"); } $data = [ // The plugin ID is derived from the filename. The extension only in patch2: unchanged: --- /dev/null +++ b/core/modules/help_topics/tests/modules/help_topics_test/bad_help_topics/discovery/bad_meta/expected_failure.topic.html.twig @@ -0,0 +1 @@ + only in patch2: unchanged: --- /dev/null +++ b/core/modules/help_topics/tests/modules/help_topics_test/bad_help_topics/discovery/no_label/expected_failure.topic.html.twig @@ -0,0 +1 @@ + only in patch2: unchanged: --- /dev/null +++ b/core/modules/help_topics/tests/modules/help_topics_test/bad_help_topics/discovery/top_level/expected_failure.topic.html.twig @@ -0,0 +1 @@ +