public static function load($actual, $isHtml = FALSE, $filename = '')
{
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);
}
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;
}
/** * Note: we are overriding this method to remove the deprecated error * @see https://tracker.moodle.org/browse/MDL-47129 * * @param array $matcher * @param string $actual * @param string $message * @param boolean $ishtml * * @deprecated 3.0 */ public static function assertNotTag($matcher, $actual, $message = '', $ishtml = true) { $dom = PHPUnit_Util_XML::load($actual, $ishtml); $tags = self::findNodes($dom, $matcher, $ishtml); $matched = count($tags) > 0 && $tags[0] instanceof DOMNode; self::assertFalse($matched, $message); }