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 @author Mike Naberezny <mike@maintainable.com> @author Derek DeVries <derek@maintainable.com> @author Tobias Schlitt <toby@php.net>
string|DOMDocument $actual:
boolean $isHtml:
string $filename:
boolean $xinclude:
DOMDocument
public static function load($actual, $isHtml = FALSE, $filename = '', $xinclude = FALSE) {
if ($actual instanceof DOMDocument) {
return $actual;
}
$document = new DOMDocument();
$internal = libxml_use_internal_errors(TRUE);
$message = '';
$reporting = error_reporting(0);
if ($isHtml) {
$loaded = $document
->loadHTML($actual);
}
else {
$loaded = $document
->loadXML($actual);
}
if ('' !== $filename) {
// Necessary for xinclude
$document->documentURI = $filename;
}
if (!$isHtml && $xinclude) {
$document
->xinclude();
}
foreach (libxml_get_errors() as $error) {
$message .= $error->message;
}
libxml_use_internal_errors($internal);
error_reporting($reporting);
if ($loaded === FALSE) {
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;
}