You are here

protected function AssertContentTrait::parse in Drupal 8

Same name and namespace in other branches
  1. 9 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.

5 calls to AssertContentTrait::parse()
AssertContentTrait::xpath in core/tests/Drupal/KernelTests/AssertContentTrait.php
Performs an xpath search on the contents of the internal browser.
SearchTestBase::submitGetForm in core/modules/search/src/Tests/SearchTestBase.php
Simulates submission of a form using GET instead of POST.
SimpleTestTest::getTestResults in core/modules/simpletest/src/Tests/SimpleTestTest.php
Get the results from a test and store them in the class array $results.
WebTestBase::checkForMetaRefresh in core/modules/simpletest/src/WebTestBase.php
Checks for meta refresh tag and if found call drupalGet() recursively.
WebTestBase::drupalPostForm in core/modules/simpletest/src/WebTestBase.php
Executes a form submission.

File

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

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) {
      $this
        ->pass(new FormattableMarkup('Valid HTML found on "@path"', [
        '@path' => $this
          ->getUrl(),
      ]), 'Browser');

      // 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);
    }
  }
  if ($this->elements === FALSE) {
    $this
      ->fail('Parsed page successfully.', 'Browser');
  }
  return $this->elements;
}