1--TEST--
2registerPhpFunctions() with callables - legit cases
3--EXTENSIONS--
4xsl
5--FILE--
6<?php
7
8require __DIR__ . '/xpath_callables.inc';
9
10$inputdom = new DomDocument();
11$inputdom->loadXML('<?xml version="1.0" encoding="iso-8859-1"?><a href="https://php.net">hello</a>');
12
13echo "--- Legit cases: none ---\n";
14
15$proc = createProcessor(["'var_dump', string(@href)"]);
16try {
17    $proc->transformToXml($inputdom);
18} catch (Error $e) {
19    echo $e->getMessage(), "\n";
20}
21
22echo "--- Legit cases: all ---\n";
23
24$proc = createProcessor(["'var_dump', string(@href)", "'MyClass::dump', string(@href)"]);
25$proc->registerPHPFunctions();
26var_dump($proc->transformToXml($inputdom));
27
28echo "--- Legit cases: set ---\n";
29
30$proc = createProcessor(["'mydump', string(@href)", "'xyz', string(@href)", "'var_dump', string(@href)"]);
31$proc->registerPhpFunctions([]);
32$proc->registerPHPFunctions(["xyz" => MyClass::dump(...), "mydump" => function (string $x) {
33    var_dump($x);
34}]);
35$proc->registerPhpFunctions(str_repeat("var_dump", mt_rand(1, 1) /* defeat SCCP */));
36var_dump($proc->transformToXml($inputdom));
37
38$proc = createProcessor(["'notinset', string(@href)"]);
39$proc->registerPhpFunctions([]);
40try {
41    var_dump($proc->transformToXml($inputdom));
42} catch (Throwable $e) {
43    echo $e->getMessage(), "\n";
44}
45
46echo "--- Legit cases: set with cycle ---\n";
47
48$proc = createProcessor(["'cycle', string(@href)"], 'MyXSLTProcessor');
49$proc->registerCycle();
50var_dump($proc->transformToXml($inputdom));
51
52?>
53--EXPECT--
54--- Legit cases: none ---
55No callbacks were registered
56--- Legit cases: all ---
57string(15) "https://php.net"
58string(15) "https://php.net"
59string(44) "<?xml version="1.0"?>
60dump: https://php.net
61"
62--- Legit cases: set ---
63string(15) "https://php.net"
64string(15) "https://php.net"
65string(15) "https://php.net"
66string(44) "<?xml version="1.0"?>
67dump: https://php.net
68"
69No callback handler "notinset" registered
70--- Legit cases: set with cycle ---
71string(45) "<?xml version="1.0"?>
72dummy: https://php.net
73"
74