You are here

protected function AssertContentTrait::parse in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::parse()
  2. 10 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.

1 call to AssertContentTrait::parse()
AssertContentTrait::xpath in core/tests/Drupal/KernelTests/AssertContentTrait.php
Performs an xpath search on the contents of the internal browser.

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 123

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

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());
    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;
}