Evaluate an HTML or XML string and assert its structure and/or contents.
The first argument ($matcher) is an associative array that specifies the match criteria for the assertion:
corresponsing value.
corresponsing values in the hash.
corresponsing hash.
must meet the criteria described by the hash.
meet the criteria described by the hash.
meet the criteria described by the hash.
Accepts the keys:
<code> // Matcher that asserts that there is an element with an id="my_id". $matcher = array('id' => 'my_id');
// Matcher that asserts that there is a "span" tag. $matcher = array('tag' => 'span');
// Matcher that asserts that there is a "span" tag with the content // "Hello World". $matcher = array('tag' => 'span', 'content' => 'Hello World');
// Matcher that asserts that there is a "span" tag with content matching // the regular expression pattern. $matcher = array('tag' => 'span', 'content' => 'regexp:/Try P(HP|ython)/');
// Matcher that asserts that there is a "span" with an "list" class // attribute. $matcher = array( 'tag'=> 'span', 'attributes' => array('class' => 'list') );
// Matcher that asserts that there is a "span" inside of a "div". $matcher = array( 'tag'=> 'span', 'parent' => array('tag' => 'div') );
// Matcher that asserts that there is a "span" somewhere inside a // "table". $matcher = array( 'tag' => 'span', 'ancestor' => array('tag' => 'table') );
// Matcher that asserts that there is a "span" with at least one "em" // child. $matcher = array( 'tag' => 'span', 'child' => array('tag' => 'em') );
// Matcher that asserts that there is a "span" containing a (possibly // nested) "strong" tag. $matcher = array( 'tag'=> 'span', 'descendant' => array('tag' => 'strong') );
// Matcher that asserts that there is a "span" containing 5-10 "em" tags // as immediate children. $matcher = array( 'tag' => 'span', 'children' => array( 'less_than'=> 11, 'greater_than' => 4, 'only' => array('tag' => 'em') ) );
// Matcher that asserts that there is a "div", with an "ul" ancestor and // a "li" parent (with class="enum"), and containing a "span" descendant // that contains an element with id="my_test" and the text "Hello World". $matcher = array( 'tag'=> 'div', 'ancestor' => array('tag' => 'ul'), 'parent' => array( 'tag'=> 'li', 'attributes' => array('class' => 'enum') ), 'descendant' => array( 'tag' => 'span', 'child' => array( 'id' => 'my_test', 'content' => 'Hello World' ) ) );
// Use assertTag() to apply a $matcher to a piece of $html. $this->assertTag($matcher, $html);
// Use assertTag() to apply a $matcher to a piece of $xml. $this->assertTag($matcher, $xml, '', FALSE); </code>
The second argument ($actual) is a string containing either HTML or XML text to be tested.
The third argument ($message) is an optional message that will be used if the assertion fails.
The fourth argument ($html) is an optional flag specifying whether to load the $actual string into a DOMDocument using the HTML or XML load strategy. It is TRUE by default, which assumes the HTML load strategy. In many cases, this will be acceptable for XML as well.
@since Method available since Release 3.3.0 @author Mike Naberezny <mike@maintainable.com> @author Derek DeVries <derek@maintainable.com>
array $matcher:
string $actual:
string $message:
boolean $isHtml:
function assertTag($matcher, $actual, $message = '', $isHtml = TRUE) {
return call_user_func_array('PHPUnit_Framework_Assert::assertTag', func_get_args());
}