mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Cover more paths in dom_xpath_ext_function_php() with tests
Also removes an incorrect comment: we *do* need the special namespace node handling code, otherwise we'd segfault.
This commit is contained in:
33
ext/dom/tests/DOMXPath_evaluate_namespace_node_set.phpt
Normal file
33
ext/dom/tests/DOMXPath_evaluate_namespace_node_set.phpt
Normal file
@@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
DOMXPath::evaluate() with PHP function passing a namespace node-set
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadXML(<<<XML
|
||||
<?xml version="1.0"?>
|
||||
<container>
|
||||
<p>hi</p>
|
||||
</container>
|
||||
XML);
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
function node_test($nodes) {
|
||||
echo "nodes count: ", count($nodes), "\n";
|
||||
return array_sum(array_map(fn ($node) => strlen($node->nodeName), $nodes));
|
||||
}
|
||||
|
||||
$xpath->registerNamespace("php", "http://php.net/xpath");
|
||||
$xpath->registerPhpFunctions(['node_test']);
|
||||
var_dump($xpath->evaluate('number(php:function("node_test", //namespace::*))'));
|
||||
var_dump($xpath->evaluate('boolean(php:function("node_test", //namespace::*))'));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
nodes count: 2
|
||||
float(18)
|
||||
nodes count: 2
|
||||
bool(true)
|
||||
26
ext/dom/tests/DOMXPath_evaluate_node_set_to_string.phpt
Normal file
26
ext/dom/tests/DOMXPath_evaluate_node_set_to_string.phpt
Normal file
@@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
DOMXPath::evaluate() with PHP function passing node-set returning a string
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadXML(<<<XML
|
||||
<?xml version="1.0"?>
|
||||
<container>
|
||||
<p>hi</p>
|
||||
</container>
|
||||
XML);
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$xpath->registerNamespace("php", "http://php.net/xpath");
|
||||
$xpath->registerPhpFunctions(['strrev']);
|
||||
var_dump($xpath->evaluate('php:functionString("strrev", //p)'));
|
||||
var_dump($xpath->evaluate('php:functionString("strrev", //namespace::*)'));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(2) "ih"
|
||||
string(36) "ecapseman/8991/LMX/gro.3w.www//:ptth"
|
||||
@@ -100,7 +100,6 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
|
||||
for (j = 0; j < obj->nodesetval->nodeNr; j++) {
|
||||
xmlNodePtr node = obj->nodesetval->nodeTab[j];
|
||||
zval child;
|
||||
/* not sure, if we need this... it's copied from xpath.c */
|
||||
if (node->type == XML_NAMESPACE_DECL) {
|
||||
xmlNodePtr nsparent = node->_private;
|
||||
xmlNsPtr original = (xmlNsPtr) node;
|
||||
|
||||
Reference in New Issue
Block a user