diff --git core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php index 55e3c23931..58043232a1 100644 --- core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php +++ core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Extension\ExtensionLifecycle; use Drupal\Component\FrontMatter\FrontMatter; +use Drupal\Component\Utility\Html; use Drupal\Tests\BrowserTestBase; use Drupal\help\HelpTopicDiscovery; use Drupal\help_topics_twig_tester\HelpTestTwigNodeVisitor; @@ -188,16 +189,19 @@ protected function verifyTopic($id, $definitions, $response = 200) { * ID of help topic (for error messages). */ protected function validateHtml(string $body, string $id) { - // Mimics \Drupal\Component\Utility\Html::load(), but keeping the HTML5 - // object to be able to use it later. + // Inspired on \Drupal\Component\Utility\Html::load(), but keeping the + // HTML5 object to be able to use it later, and use the fragment related + // method. $html5 = new HTML5(['disable_html_ns' => TRUE, 'encoding' => 'UTF-8']); - $doc = $html5->loadHTML('' . $body); + $doc = $html5->loadHTMLFragment($body); if ($html5->hasErrors()) { foreach ($html5->getErrors() as $error) { $this->fail('Topic ' . $id . ' fails HTML validation: ' . $error); } } + // Load it again, as full document, to walk over it. + $doc = Html::load($body); // Check for headings hierarchy. $levels = [1, 2, 3, 4, 5, 6]; foreach ($levels as $level) { @@ -244,7 +248,7 @@ protected function verifyBadTopic($id, $definitions) { case 'bad_html': case 'bad_html2': case 'bad_html3': - $this->assertStringContainsString('Opening and ending tag mismatch', $message); + $this->assertStringContainsString('Could not find closing tag for', $message); break; case 'top_level':