function AssertContentTrait::parse

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::parse()
  2. 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::parse()
  3. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::parse()
  4. 8.9.x 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 125

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function parse() : ?\SimpleXMLElement {
  if (!isset($this->elements)) {
    $content = $this->getRawContent();
    $dom = Html::load($content);
    if ($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($dom);
    }
  }
  $this->assertNotFalse($this->elements, 'The current HTML page should be available for DOM navigation.');
  return $this->elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.