forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters