Skip to content
Snippets Groups Projects
Commit 5d921fba authored by Laurent's avatar Laurent
Browse files

add assertNotXPathContentContains

parent ff186d90
Branches
Tags
No related merge requests found
Pipeline #2092 passed with stage
in 7 seconds
......@@ -37,7 +37,7 @@ class Storm_Test_XPathXML {
public function newXPathForXml($xml) {
$document = $this->_getDocument($xml);
$document = $this->_getDocument($xml);
$xpath = new DOMXPath($document);
foreach ($this->_namespaces as $prefix => $uri) {
if (!$xpath->registerNamespace($prefix, $uri))
......@@ -55,7 +55,7 @@ class Storm_Test_XPathXML {
$nodeList = $this->_getNodeList($xml, $path);
$this->_assertNodeListNotEmpty($nodeList, $path, $message);
foreach ($nodeList as $node) {
if ('' === $match && '' === $node->nodeValue)
if ('' === $match && '' === $node->nodeValue)
return;
if (false !== strpos($node->nodeValue, $match))
return;
......@@ -66,6 +66,20 @@ class Storm_Test_XPathXML {
}
public function assertNotXpathContentContains($xml, $path, $match, $message = '') {
if (!$message)
$message = sprintf("Document:\n\n%s\n", $xml);
$nodeList = $this->_getNodeList($xml, $path);
$this->_assertNodeListNotEmpty($nodeList, $path, $message);
foreach ($nodeList as $node) {
if (false !== strpos($node->nodeValue, $match))
throw new Storm_Test_XPathException($message . sprintf('Failed asserting node denoted by %s DOES NOT CONTAIN content "%s"',
$path, $match));
}
}
public function assertXpath($xml, $path, $message = '') {
if (!$message)
$message = sprintf("Document:\n\n%s\n", $xml);
......@@ -82,7 +96,7 @@ class Storm_Test_XPathXML {
$nodeList = $this->_getNodeList($xml, $path);
if ($nodeList->length > 0)
throw new Storm_Test_XPathException($message . sprintf('Failed asserting that node denoted by "%s" DOES NOT EXIST',
$path));
$path));
}
......@@ -91,9 +105,9 @@ class Storm_Test_XPathXML {
$message = sprintf("Document:\n\n%s\n", $xml);
$nodeList = $this->_getNodeList($xml, $path);
if ($nodeList->length != (int)$count)
if ($nodeList->length != (int)$count)
throw new Storm_Test_XPathException($message . sprintf('Failed asserting that node denoted by "%s" APPEARS EXACTLY %s TIMES',
$path, $count));
$path, $count));
}
......@@ -103,7 +117,7 @@ class Storm_Test_XPathXML {
$document = $this->_getDocument($xml);
if ($document->xmlVersion != $version)
throw new Storm_Test_XPathException($message . sprintf('Failed asserting that XML version of document "%s" EQUALS "%s"',
$document->xmlVersion, $version));
$document->xmlVersion, $version));
}
......@@ -113,7 +127,7 @@ class Storm_Test_XPathXML {
$document = $this->_getDocument($xml);
if ($document->xmlEncoding != $encoding)
throw new Storm_Test_XPathException($message . sprintf('Failed asserting that XML encoding of document "%s" EQUALS "%s"',
$document->xmlEncoding, $encoding));
$document->xmlEncoding, $encoding));
}
......@@ -125,10 +139,10 @@ class Storm_Test_XPathXML {
}
protected function _assertNodeListNotEmpty($nodeList, $path, $message) {
if ($nodeList->length == 0)
protected function _assertNodeListNotEmpty($nodeList, $path, $message) {
if ($nodeList->length == 0)
throw new Storm_Test_XPathException($message . sprintf('Failed asserting that node denoted by "%s" EXISTS',
$path));
$path));
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment