- \PHPUnit_Util_XML
class (none) \ PHPUnit_Util_XML
XML helpers.
Method Summary
Name | Description |
---|---|
assertValidKeys(array $hash, array $validKeys) | Validate list of keys in the associative array. |
convertSelectToTag($selector, $content = true) | Parse a CSS selector into an associative array suitable for use with findNodes(). |
cssSelect($selector, $content, $actual, $isHtml = true) | Parse an $actual document and return an array of DOMNodes matching the CSS $selector. If an error occurs, it will return false. |
findNodes(DOMDocument $dom, array $options, $isHtml = true) | Parse out the options from the tag using DOM object tree. |
getDescendants(DOMNode $node) | Recursively get flat array of all descendants of this node. |
getElementsByCaseInsensitiveTagName(DOMDocument $dom, $tag) | Gets elements by case insensitive tagname. |
getNodeText(DOMNode $node) | Get the text value of this node's child text node. |
load($actual, $isHtml = false, $filename = "", $xinclude = false, $strict = false) | Load an $actual document into a DOMDocument. This is called from the selector assertions. |
loadFile($filename, $isHtml = false, $xinclude = false, $strict = false) | Loads an XML (or HTML) file into a DOMDocument object. |
nodeToText(DOMNode $node) | |
prepareString($string) | Escapes a string for the use in XML documents Any Unicode character is allowed, excluding the surrogate blocks, FFFE, and FFFF (not even as character reference). See http://www.w3.org/TR/xml/#charsets |
removeCharacterDataNodes(DOMNode $node) | |
xmlToVariable(DOMElement $element) | "Convert" a DOMElement object into a PHP variable. |
public static function assertValidKeys(array $hash, array $validKeys)
Validate list of keys in the associative array.
- Parameters:
array
- $validKeys- Returns:
- array
- Throws:
- PHPUnit_Framework_Exception
public static function convertSelectToTag($selector, $content = true)
Parse a CSS selector into an associative array suitable for use with findNodes().
- Parameters:
string
- $selectormixed
- $content- Defaults:
content
=true
- Returns:
- array
public static function cssSelect($selector, $content, $actual, $isHtml = true)
Parse an $actual document and return an array of DOMNodes matching the CSS $selector. If an error occurs, it will return false.
To only return nodes containing a certain content, give the $content to match as a string. Otherwise, setting $content to true will return all nodes matching $selector.
The $actual document may be a DOMDocument or a string containing XML or HTML, identified by $isHtml.
- Parameters:
array
- $selectorstring
- $contentmixed
- $actualboolean
- $isHtml- Defaults:
isHtml
=true
- Returns:
- boolean|array
public static function findNodes(DOMDocument $dom, array $options, $isHtml = true)
Parse out the options from the tag using DOM object tree.
- Parameters:
DOMDocument
- $domarray
- $optionsboolean
- $isHtml- Defaults:
isHtml
=true
- Returns:
- array
protected static function getDescendants(DOMNode $node)
Recursively get flat array of all descendants of this node.
- Parameters:
DOMNode
- $node- Returns:
- array
protected static function getElementsByCaseInsensitiveTagName(DOMDocument $dom, $tag)
Gets elements by case insensitive tagname.
- Parameters:
DOMDocument
- $domstring
- $tag- Returns:
- DOMNodeList
protected static function getNodeText(DOMNode $node)
Get the text value of this node's child text node.
- Parameters:
DOMNode
- $node- Returns:
- string
public static function load($actual, $isHtml = false, $filename = "", $xinclude = false, $strict = false)
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.
- Parameters:
string|DOMDocument
- $actualboolean
- $strictstring
- $filename- Defaults:
isHtml
=false
filename
=""
xinclude
=false
strict
=false
- Returns:
- DOMDocument
public static function loadFile($filename, $isHtml = false, $xinclude = false, $strict = false)
Loads an XML (or HTML) file into a DOMDocument object.
- Parameters:
string
- $filenameboolean
- $strict- Defaults:
isHtml
=false
xinclude
=false
strict
=false
- Returns:
- DOMDocument
public static function nodeToText(DOMNode $node)
- Parameters:
DOMNode
- $node- Returns:
- string
public static function prepareString($string)
Escapes a string for the use in XML documents Any Unicode character is allowed, excluding the surrogate blocks, FFFE, and FFFF (not even as character reference). See http://www.w3.org/TR/xml/#charsets
- Parameters:
string
- $string- Returns:
- string
public static function removeCharacterDataNodes(DOMNode $node)
- Parameters:
DOMNode
- $node
public static function xmlToVariable(DOMElement $element)
"Convert" a DOMElement object into a PHP variable.
- Parameters:
DOMElement
- $element- Returns:
- mixed