msopacua Sat Oct 5 15:44:25 2002 EDT Added files: /php4/ext/xslt/tests 005.phpt 006.phpt 007.phpt args.xsl param.xsl test.xml qa.dtd Log: (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
Index: php4/ext/xslt/tests/005.phpt +++ php4/ext/xslt/tests/005.phpt --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® Index: php4/ext/xslt/tests/006.phpt +++ php4/ext/xslt/tests/006.phpt --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 Index: php4/ext/xslt/tests/007.phpt +++ php4/ext/xslt/tests/007.phpt --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 Index: php4/ext/xslt/tests/args.xsl +++ php4/ext/xslt/tests/args.xsl <?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> Index: php4/ext/xslt/tests/param.xsl +++ php4/ext/xslt/tests/param.xsl <?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> Index: php4/ext/xslt/tests/test.xml +++ php4/ext/xslt/tests/test.xml <?xml version="1.0" encoding="ISO-8859-1"?> <qa> <test type="simple">Test has passed</test> <test type="complex" /> </qa> Index: php4/ext/xslt/tests/qa.dtd +++ php4/ext/xslt/tests/qa.dtd <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT qa (test+)> <!ELEMENT test (#PCDATA)> <!ATTLIST test type CDATA #IMPLIED > <!ENTITY reg "®"> -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php