Index: library/Zend/Dom/Query.php =================================================================== --- library/Zend/Dom/Query.php (revision 22267) +++ library/Zend/Dom/Query.php (working copy) @@ -65,6 +65,12 @@ protected $_docType; /** + * XPath namespaces + * @var array + */ + protected $_xpathNamespaces = array(); + + /** * Constructor * * @param null|string $document @@ -221,6 +227,17 @@ } /** + * Register XPath namespaces + * + * @param array $xpathNamespaces + * @return void + */ + public function registerXpathNamespaces($xpathNamespaces) + { + $this->_xpathNamespaces = $xpathNamespaces; + } + + /** * Prepare node list * * @param DOMDocument $document @@ -230,6 +247,9 @@ protected function _getNodeList($document, $xpathQuery) { $xpath = new DOMXPath($document); + foreach ($this->_xpathNamespaces as $prefix => $namespaceUri) { + $xpath->registerNamespace($prefix, $namespaceUri); + } $xpathQuery = (string) $xpathQuery; if (preg_match_all('|\[contains\((@[a-z0-9_-]+),\s?\' |i', $xpathQuery, $matches)) { foreach ($matches[1] as $attribute) { Index: library/Zend/Test/PHPUnit/ControllerTestCase.php =================================================================== --- library/Zend/Test/PHPUnit/ControllerTestCase.php (revision 22267) +++ library/Zend/Test/PHPUnit/ControllerTestCase.php (working copy) @@ -78,6 +78,12 @@ protected $_response; /** + * XPath namespaces + * @var array + */ + protected $_xpathNamespaces = array(); + + /** * Overloading: prevent overloading to special properties * * @param string $name @@ -463,6 +469,17 @@ } /** + * Register XPath namespaces + * + * @param array $xpathNamespaces + * @return void + */ + public function registerXpathNamespaces($xpathNamespaces) + { + $this->_xpathNamespaces = $xpathNamespaces; + } + + /** * Assert against XPath selection * * @param string $path XPath path @@ -474,6 +491,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__)) { $constraint->fail($path, $message); @@ -492,6 +510,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__)) { $constraint->fail($path, $message); @@ -511,6 +530,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $match)) { $constraint->fail($path, $message); @@ -530,6 +550,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $match)) { $constraint->fail($path, $message); @@ -549,6 +570,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) { $constraint->fail($path, $message); @@ -568,6 +590,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) { $constraint->fail($path, $message); @@ -587,6 +610,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $count)) { $constraint->fail($path, $message); @@ -606,6 +630,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $count)) { $constraint->fail($path, $message); @@ -625,6 +650,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $count)) { $constraint->fail($path, $message); @@ -644,6 +670,7 @@ $this->_incrementAssertionCount(); require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php'; $constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path); + $constraint->registerXpathNamespaces($this->_xpathNamespaces); $content = $this->response->outputBody(); if (!$constraint->evaluate($content, __FUNCTION__, $count)) { $constraint->fail($path, $message); Index: library/Zend/Test/PHPUnit/Constraint/DomQuery.php =================================================================== --- library/Zend/Test/PHPUnit/Constraint/DomQuery.php (revision 22267) +++ library/Zend/Test/PHPUnit/Constraint/DomQuery.php (working copy) @@ -93,6 +93,12 @@ protected $_useXpath = false; /** + * XPath namespaces + * @var array + */ + protected $_xpathNamespaces = array(); + + /** * Constructor; setup constraint state * * @param string $path CSS selector path @@ -154,6 +160,7 @@ $method = $this->_useXpath ? 'queryXpath' : 'query'; $domQuery = new Zend_Dom_Query($other); + $domQuery->registerXpathNamespaces($this->_xpathNamespaces); $result = $domQuery->$method($this->_path); $argv = func_get_args(); $argc = func_num_args(); @@ -267,6 +274,17 @@ } /** + * Register XPath namespaces + * + * @param array $xpathNamespaces + * @return void + */ + public function registerXpathNamespaces($xpathNamespaces) + { + $this->_xpathNamespaces = $xpathNamespaces; + } + + /** * Check to see if content is matched in selected nodes * * @param Zend_Dom_Query_Result $result