summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelvyn Sopacua <msopacua@php.net>2002-10-05 19:44:26 +0000
committerMelvyn Sopacua <msopacua@php.net>2002-10-05 19:44:26 +0000
commit9bb526c28386c37141f1818ab12162d5e442f42f (patch)
tree0115ef3ffff9794ce418b5fda7e119aec4807082
parent778615bd6c22ff260b2c5ddb13ba55b895746c5a (diff)
downloadphp-git-9bb526c28386c37141f1818ab12162d5e442f42f.tar.gz
(xslt tests) Add test for new backend API (005.phpt), new function
(006.phpt) and a crash test (007.phpt) 006.phpt also tests handling of public entities, which is in essence new to the extension, since there was no way to turn it on. # These new functions and backend will be added shortly. # TODO: test for xslt_set_object
-rw-r--r--ext/xslt/tests/005.phpt60
-rw-r--r--ext/xslt/tests/006.phpt74
-rw-r--r--ext/xslt/tests/007.phpt47
-rwxr-xr-xext/xslt/tests/args.xsl10
-rw-r--r--ext/xslt/tests/param.xsl15
-rwxr-xr-xext/xslt/tests/qa.dtd8
-rw-r--r--ext/xslt/tests/test.xml5
7 files changed, 219 insertions, 0 deletions
diff --git a/ext/xslt/tests/005.phpt b/ext/xslt/tests/005.phpt
new file mode 100644
index 0000000000..935c7c273d
--- /dev/null
+++ b/ext/xslt/tests/005.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Various ways to provide xml and xslt arguments and params
+--SKIPIF--
+<?php
+include("skipif.inc");
+if(!function_exists('utf8_encode')) {
+ die("skip\n");
+}
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+$xmlfile = 'ext/xslt/tests/test.xml';
+$xslfile = 'ext/xslt/tests/args.xsl';
+$xmldata = @implode('', @file($xmlfile));
+$xslsheet = @implode('', @file($xslfile));
+
+$xh = xslt_create();
+$result = xslt_process($xh, $xmlfile, $xslfile);
+print "$result\n";
+$result = xslt_process($xh, 'arg:/_xml', $xslfile, NULL, array('/_xml' => $xmldata));
+print "$result\n";
+$result = xslt_process($xh, $xmlfile, 'arg:/_xsl', NULL, array('/_xsl' => $xslsheet));
+print "$result\n";
+$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, array('/_xml' => $xmldata, '/_xsl' => $xslsheet));
+print "$result\n";
+
+// The same, with params
+$xslfile = 'ext/xslt/tests/param.xsl';
+$xslsheet = implode('', file($xslfile));
+$params = array("Test has passed", "PHP QA®");
+
+foreach($params AS $val)
+{
+ $val = utf8_encode($val);
+ $result = xslt_process($xh, $xmlfile, $xslfile, NULL, NULL, array('insertion' => $val));
+ print "$result\n";
+ $result = xslt_process($xh, 'arg:/_xml', $xslfile, NULL, array('/_xml' => $xmldata), array('insertion' => $val));
+ print "$result\n";
+ $result = xslt_process($xh, $xmlfile, 'arg:/_xsl', NULL, array('/_xsl' => $xslsheet), array('insertion' => $val));
+ print "$result\n";
+ $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, array('/_xml' => $xmldata, '/_xsl' => $xslsheet), array('insertion' => $val));
+ print "$result\n";
+}
+
+xslt_free($xh);
+?>
+--EXPECT--
+Test has passed
+Test has passed
+Test has passed
+Test has passed
+Test has passed
+Test has passed
+Test has passed
+Test has passed
+PHP QA®
+PHP QA®
+PHP QA®
+PHP QA®
diff --git a/ext/xslt/tests/006.phpt b/ext/xslt/tests/006.phpt
new file mode 100644
index 0000000000..7c6f14fa45
--- /dev/null
+++ b/ext/xslt/tests/006.phpt
@@ -0,0 +1,74 @@
+--TEST--
+Crash xslt_process with reused handler (this test may take a while)
+--SKIPIF--
+<?php
+include("skipif.inc");
+if(!function_exists('utf8_encode')) {
+ die("skip\n");
+}
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+$xmlfile = 'ext/xslt/tests/test.xml';
+$xslfile = 'ext/xslt/tests/param.xsl';
+$xmldata = @implode('', @file($xmlfile));
+$xslsheet = @implode('', @file($xslfile));
+
+/*
+ * Tested on a Cyrix 200MMX/128MB took 2 secs. Should be a reasonable margin.
+ *
+ * It's not meant as an actual speed test, but if it's slower than this,
+ * there must be something significantly off in the php/sablot/expat trio.
+ * Emulation OS's come to mind...
+ */
+$want_time = 6;
+
+function make_param()
+{
+ $ret_val = '';
+ $numchars = mt_rand(2,16);
+ $illegal = array(0,256,512);
+ for($i=0;$i<$numchars;$i++)
+ {
+ $char=0;
+ while(in_array($char, $illegal))
+ {
+ $char .= mt_rand(32, 512);
+ }
+ $ret_val .= chr($char);
+ }
+
+ return utf8_encode($ret_val);
+}
+
+function decode($string)
+{
+ $ret_val = '';
+ for($i=0; $i<strlen($string);$i++)
+ {
+ $ret_val .= ord(substr($string,$i,1)) . " ";
+ }
+ return $ret_val;
+}
+
+
+$xh = xslt_create();
+
+$t1 = time();
+for ($i=0; $i<50; $i++)
+{
+ $val = make_param();
+ $result = xslt_process($xh, $xmlfile, $xslfile, NULL, NULL, array('insertion' => $val));
+ if(!$result or $result != utf8_decode($val))
+ print "Failed $i / ".utf8_decode($val).": $result\n\tDecode: " . decode(utf8_decode($val)) . "\n" ;
+}
+print "OK\n";
+xslt_free($xh);
+$t2 = time();
+$op_time = $t2 - $t1;
+if($op_time > $want_time)
+ print "This test took more than $want_time seconds. Either you have a very slow / busy machine, or there's something very wrong with the speed. Your time: $op_time";
+?>
+--EXPECT--
+OK
diff --git a/ext/xslt/tests/007.phpt b/ext/xslt/tests/007.phpt
new file mode 100644
index 0000000000..3967e6723d
--- /dev/null
+++ b/ext/xslt/tests/007.phpt
@@ -0,0 +1,47 @@
+--TEST--
+xslt_set_opt function and public entities
+--SKIPIF--
+<?php
+include("skipif.inc");
+if(!function_exists('xslt_setopt')) {
+ die("skip\n");
+}
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+$xmlfile = 'ext/xslt/tests/public.xml';
+$xslfile = 'ext/xslt/tests/args.xsl';
+
+$xh = xslt_create();
+// Tell Sablotron to process public entities
+xslt_setopt($xh, XSLT_SAB_PARSE_PUBLIC_ENTITIES);
+
+$result = xslt_process($xh, $xmlfile, $xslfile);
+print "$result\n";
+
+$xslstring = implode('', file($xslfile));
+$xslstring = str_replace('method="text"', 'method="html"', $xslstring);
+$xslstring = str_replace('<xsl:value-of select="." />', '<html><head><title>foo</title></head><body><p><xsl:value-of select="." /></p></body></html>', $xslstring);
+// DEBUG: print $xslstring;
+
+xslt_setopt($xh, XSLT_SAB_PARSE_PUBLIC_ENTITIES | XSLT_SAB_DISABLE_ADDING_META);
+$result_nometa = xslt_process($xh, $xmlfile, 'arg:/_xsl', NULL, array('/_xsl' => $xslstring));
+// DEBUG: print "$result_nometa\n";
+
+xslt_setopt($xh, XSLT_SAB_PARSE_PUBLIC_ENTITIES);
+$result_meta = xslt_process($xh, $xmlfile, 'arg:/_xsl', NULL, array('/_xsl' => $xslstring));
+// DEBUG: print "$result_meta\n";
+
+/* Also test if they're equal. That would mean, that disable-adding-meta is set to off
+ at compile time and our call to xslt_setopt failed to reset that */
+if($result_meta != $result_nometa && FALSE === stristr($result_nometa, '<meta http-equiv="Content-Type"'))
+{
+ print "OK\n";
+}
+
+xslt_free($xh);
+?>
+--EXPECT--
+PHP QA®
+OK
diff --git a/ext/xslt/tests/args.xsl b/ext/xslt/tests/args.xsl
new file mode 100755
index 0000000000..4ff140c777
--- /dev/null
+++ b/ext/xslt/tests/args.xsl
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output encoding="ISO-8859-1" method="text" omit-xml-declaration="yes" />
+ <xsl:template match="/qa">
+ <xsl:apply-templates select="test" />
+ </xsl:template>
+ <xsl:template match="test[@type = 'simple']">
+ <xsl:value-of select="." />
+ </xsl:template>
+</xsl:stylesheet>
diff --git a/ext/xslt/tests/param.xsl b/ext/xslt/tests/param.xsl
new file mode 100644
index 0000000000..64b78fafe7
--- /dev/null
+++ b/ext/xslt/tests/param.xsl
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="text" omit-xml-declaration="yes" encoding="ISO-8859-1" />
+ <xsl:param name="insertion">Test failed</xsl:param>
+ <xsl:template match="/qa">
+ <xsl:apply-templates select="test" />
+ </xsl:template>
+ <xsl:template match="test">
+ <xsl:choose>
+ <xsl:when test="@type != 'simple'">
+ <xsl:value-of select="$insertion" />
+ </xsl:when>
+ </xsl:choose>
+ </xsl:template>
+</xsl:stylesheet>
diff --git a/ext/xslt/tests/qa.dtd b/ext/xslt/tests/qa.dtd
new file mode 100755
index 0000000000..370302dcce
--- /dev/null
+++ b/ext/xslt/tests/qa.dtd
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!ELEMENT qa (test+)>
+
+<!ELEMENT test (#PCDATA)>
+<!ATTLIST test
+ type CDATA #IMPLIED
+>
+<!ENTITY reg "&#174;"> \ No newline at end of file
diff --git a/ext/xslt/tests/test.xml b/ext/xslt/tests/test.xml
new file mode 100644
index 0000000000..f7c69d4c4a
--- /dev/null
+++ b/ext/xslt/tests/test.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<qa>
+ <test type="simple">Test has passed</test>
+ <test type="complex" />
+</qa>