You are here

protected function AssertContentTrait::parse in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/AssertContentTrait.php \Drupal\simpletest\AssertContentTrait::parse()

Parse content returned from curlExec using DOM and SimpleXML.

Return value

\SimpleXMLElement|FALSE A SimpleXMLElement or FALSE on failure.

6 calls to AssertContentTrait::parse()
AssertContentTrait::xpath in core/modules/simpletest/src/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.
SyslogTest::testSettings in core/modules/syslog/src/Tests/SyslogTest.php
Tests the syslog settings page.
WebTestBase::checkForMetaRefresh in core/modules/simpletest/src/WebTestBase.php
Checks for meta refresh tag and if found call drupalGet() recursively.

... See full list

File

core/modules/simpletest/src/AssertContentTrait.php, line 128
Contains \Drupal\simpletest\AssertContentTrait.

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\simpletest

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(SafeMarkup::format('Valid HTML found on "@path"', array(
        '@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;
}