protected function AssertContentTrait::parse in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::parse()
- 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::parse()
Parse content returned from curlExec using DOM and SimpleXML.
Return value
\SimpleXMLElement|false A SimpleXMLElement or FALSE on failure.
File
- core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php, line 123
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\KernelTestsCode
protected function parse() {
if (!isset($this->elements)) {
// DOM can load HTML soup. But, HTML soup can throw warnings, suppress
// them.
$html_dom = new \DOMDocument();
@$html_dom
->loadHTML('<?xml encoding="UTF-8">' . $this
->getRawContent(), LIBXML_NOBLANKS);
if ($html_dom) {
// It's much easier to work with simplexml than DOM, luckily enough
// we can just simply import our DOM tree.
$this->elements = simplexml_import_dom($html_dom);
}
}
$this
->assertNotFalse($this->elements, 'The current HTML page should be available for DOM navigation.');
return $this->elements;
}