You are here

function assertTag in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/Assert/Functions.php \assertTag()

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:

  • `id` : the node with the given id attribute must match the

corresponding value.

  • `tag` : the node type must match the corresponding value.
  • `attributes` : a hash. The node's attributes must match the

corresponding values in the hash.

  • `content` : The text content must match the given value.
  • `parent` : a hash. The node's parent must match the

corresponding hash.

  • `child`: a hash. At least one of the node's immediate children

must meet the criteria described by the hash.

  • `ancestor` : a hash. At least one of the node's ancestors must

meet the criteria described by the hash.

  • `descendant` : a hash. At least one of the node's descendants must

meet the criteria described by the hash.

  • `children` : a hash, for counting children of a node.

Accepts the keys:

  • `count`: a number which must equal the number of children that match
  • `less_than`: the number of matching children must be greater than this number
  • `greater_than` : the number of matching children must be less than this number
  • `only` : another hash consisting of the keys to use to match on the children, and only matching children will be counted

<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

Parameters

array $matcher:

string $actual:

string $message:

bool $isHtml:

File

vendor/phpunit/phpunit/src/Framework/Assert/Functions.php, line 1626

Code

function assertTag($matcher, $actual, $message = '', $isHtml = true) {
  return call_user_func_array('PHPUnit_Framework_Assert::assertTag', func_get_args());
}