You are here

public static function PHPUnit_Util_XML::load in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpunit/phpunit/src/Util/XML.php \PHPUnit_Util_XML::load()

Load an $actual document into a DOMDocument. This is called from the selector assertions.

If $actual is already a DOMDocument, it is returned with no changes. Otherwise, $actual is loaded into a new DOMDocument as either HTML or XML, depending on the value of $isHtml. If $isHtml is false and $xinclude is true, xinclude is performed on the loaded DOMDocument.

Note: prior to PHPUnit 3.3.0, this method loaded a file and not a string as it currently does. To load a file into a DOMDocument, use loadFile() instead.

@since Method available since Release 3.3.0

Parameters

string|DOMDocument $actual:

bool $isHtml:

string $filename:

bool $xinclude:

bool $strict:

Return value

DOMDocument

10 calls to PHPUnit_Util_XML::load()
Framework_AssertTest::equalValues in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
Framework_AssertTest::notEqualValues in vendor/phpunit/phpunit/tests/Framework/AssertTest.php
PHPUnit_Framework_Assert::assertNotTag in vendor/phpunit/phpunit/src/Framework/Assert.php
This assertion is the exact opposite of assertTag().
PHPUnit_Framework_Assert::assertTag in vendor/phpunit/phpunit/src/Framework/Assert.php
Evaluate an HTML or XML string and assert its structure and/or contents.
PHPUnit_Framework_Assert::assertXmlStringEqualsXmlFile in vendor/phpunit/phpunit/src/Framework/Assert.php
Asserts that two XML documents are equal.

... See full list

File

vendor/phpunit/phpunit/src/Util/XML.php, line 91

Class

PHPUnit_Util_XML
XML helpers.

Code

public static function load($actual, $isHtml = false, $filename = '', $xinclude = false, $strict = false) {
  if ($actual instanceof DOMDocument) {
    return $actual;
  }

  // Required for XInclude on Windows.
  if ($xinclude) {
    $cwd = getcwd();
    @chdir(dirname($filename));
  }
  $document = new DOMDocument();
  $document->preserveWhiteSpace = false;
  $internal = libxml_use_internal_errors(true);
  $message = '';
  $reporting = error_reporting(0);
  if ('' !== $filename) {

    // Necessary for xinclude
    $document->documentURI = $filename;
  }
  if ($isHtml) {
    $loaded = $document
      ->loadHTML($actual);
  }
  else {
    $loaded = $document
      ->loadXML($actual);
  }
  if (!$isHtml && $xinclude) {
    $document
      ->xinclude();
  }
  foreach (libxml_get_errors() as $error) {
    $message .= "\n" . $error->message;
  }
  libxml_use_internal_errors($internal);
  error_reporting($reporting);
  if ($xinclude) {
    @chdir($cwd);
  }
  if ($loaded === false || $strict && $message !== '') {
    if ($filename !== '') {
      throw new PHPUnit_Framework_Exception(sprintf('Could not load "%s".%s', $filename, $message != '' ? "\n" . $message : ''));
    }
    else {
      throw new PHPUnit_Framework_Exception($message);
    }
  }
  return $document;
}