PHPUnit_Util_XML::load PHP Method

load() public static method

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. 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.
Author: Mike Naberezny ([email protected])
Author: Derek DeVries ([email protected])
public static load ( string | DOMDocument $actual, boolean $isHtml = FALSE, string $filename = '' ) : DOMDocument
$actual string | DOMDocument
$isHtml boolean
$filename string
return DOMDocument
    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;
    }

Usage Example

コード例 #1
0
ファイル: base_testcase.php プロジェクト: evltuma/moodle
 /**
  * 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);
 }
All Usage Examples Of PHPUnit_Util_XML::load