[php-src] master: Add test for performing special operations on XSLTProcessor properties (#13959)
| From: | Niels Dossche via GitHub | Date: | Sun, 14 Apr 2024 14:53:00 +0000 |
| Subject: | [php-src] master: Add test for performing special operations on XSLTProcessor properties (#13959) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-128104@lists.php.net to get a copy of this message | ||
Author: Niels Dossche (nielsdos)
Committer: GitHub (web-flow)
Pusher: nielsdos
Date: 2024-04-14T16:52:54+02:00
Commit: https://github.com/php/php-src/commit/8ce9f2e2b0bd943998aebe8829a13251edbafdc7
Raw diff: https://github.com/php/php-src/commit/8ce9f2e2b0bd943998aebe8829a13251edbafdc7.diff
Add test for performing special operations on XSLTProcessor properties (#13959)
This covers some uncovered code paths in custom property handling in
php_xsl.c
Changed paths:
A ext/xsl/tests/special_operations_with_properties.phpt
Diff:
diff --git a/ext/xsl/tests/special_operations_with_properties.phpt
b/ext/xsl/tests/special_operations_with_properties.phpt
new file mode 100644
index 0000000000000..b7904fad8d866
--- /dev/null
+++ b/ext/xsl/tests/special_operations_with_properties.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Special operations with XSLTProcessor properties
+--EXTENSIONS--
+xsl
+dom
+--FILE--
+<?php
+
+$xml = new DOMDocument;
+$xml->loadXML('<?xml
version="1.0"?><root><foo>hello</foo></root>');
+
+function test() {
+ echo "Called test\n";
+}
+
+$xsl = new DOMDocument;
+$xsl->loadXML(<<<XML
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
version="1.0">
+ <xsl:template match="/root">
+ <xsl:value-of select="php:function('test')"/>
+ <xsl:value-of select="//root/foo"/>
+ </xsl:template>
+</xsl:stylesheet>
+XML);
+
+echo "--- Unset cloneDocument ---\n";
+
+$xslt = new XSLTProcessor;
+$xslt->registerPHPFunctions();
+unset($xslt->cloneDocument);
+try {
+ $xslt->importStylesheet($xsl);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+
+echo "--- Unset doXInclude ---\n";
+
+$xslt = new XSLTProcessor;
+$xslt->registerPHPFunctions();
+unset($xslt->doXInclude);
+$xslt->importStylesheet($xsl);
+try {
+ echo $xslt->transformToXml($xml);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+
+echo "--- Make properties references ---\n";
+
+$xslt = new XSLTProcessor;
+$xslt->registerPHPFunctions();
+$clone =& $xslt->cloneDocument;
+$xinclude =& $xslt->doXInclude;
+$xslt->importStylesheet($xsl);
+echo $xslt->transformToXml($xml);
+
+?>
+--EXPECT--
+--- Unset cloneDocument ---
+Typed property XSLTProcessor::$cloneDocument must not be accessed before initialization
+--- Unset doXInclude ---
+Typed property XSLTProcessor::$doXInclude must not be accessed before initialization
+--- Make properties references ---
+Called test
+<?xml version="1.0"?>
+hello