From d2616018e49e666fd376ac9ca7e840174ee241f7 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 23 May 2009 14:44:37 +0000 Subject: [PATCH] - New tests (testfest BerlinUG) --- ext/xsl/tests/xsl-phpinfo.phpt | 18 +++++++++ ...ltprocessor_getParameter-invalidparam.phpt | 17 +++++++++ ...xsltprocessor_getParameter-wrongparam.phpt | 26 +++++++++++++ ext/xsl/tests/xsltprocessor_getParameter.phpt | 19 ++++++++++ ...ocessor_registerPHPFunctions-allfuncs.phpt | 30 +++++++++++++++ ...r_registerPHPFunctions-array-multiple.phpt | 34 +++++++++++++++++ ...registerPHPFunctions-array-notallowed.phpt | 28 ++++++++++++++ ...tprocessor_registerPHPFunctions-array.phpt | 26 +++++++++++++ ...sor_registerPHPFunctions-funcnostring.phpt | 37 +++++++++++++++++++ ...cessor_registerPHPFunctions-funcundef.phpt | 36 ++++++++++++++++++ ...ltprocessor_registerPHPFunctions-null.phpt | 32 ++++++++++++++++ ..._registerPHPFunctions-string-multiple.phpt | 32 ++++++++++++++++ ...egisterPHPFunctions-string-notallowed.phpt | 28 ++++++++++++++ ...processor_registerPHPFunctions-string.phpt | 26 +++++++++++++ ...rocessor_removeParameter-invalidparam.phpt | 18 +++++++++ ...processor_removeParameter-wrongparams.phpt | 23 ++++++++++++ .../tests/xsltprocessor_removeParameter.phpt | 20 ++++++++++ ...xsltprocessor_setparameter-errorquote.phpt | 21 +++++++++++ .../xsltprocessor_setparameter-nostring.phpt | 22 +++++++++++ 19 files changed, 493 insertions(+) create mode 100644 ext/xsl/tests/xsl-phpinfo.phpt create mode 100644 ext/xsl/tests/xsltprocessor_getParameter-invalidparam.phpt create mode 100644 ext/xsl/tests/xsltprocessor_getParameter-wrongparam.phpt create mode 100644 ext/xsl/tests/xsltprocessor_getParameter.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-allfuncs.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-multiple.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-notallowed.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-array.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcnostring.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcundef.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-null.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-multiple.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-notallowed.phpt create mode 100644 ext/xsl/tests/xsltprocessor_registerPHPFunctions-string.phpt create mode 100644 ext/xsl/tests/xsltprocessor_removeParameter-invalidparam.phpt create mode 100644 ext/xsl/tests/xsltprocessor_removeParameter-wrongparams.phpt create mode 100644 ext/xsl/tests/xsltprocessor_removeParameter.phpt create mode 100644 ext/xsl/tests/xsltprocessor_setparameter-errorquote.phpt create mode 100644 ext/xsl/tests/xsltprocessor_setparameter-nostring.phpt diff --git a/ext/xsl/tests/xsl-phpinfo.phpt b/ext/xsl/tests/xsl-phpinfo.phpt new file mode 100644 index 0000000000..83e6729ce6 --- /dev/null +++ b/ext/xsl/tests/xsl-phpinfo.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test phpinfo() displays xsl info +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +%a +libxslt compiled against libxml Version%a +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_getParameter-invalidparam.phpt b/ext/xsl/tests/xsltprocessor_getParameter-invalidparam.phpt new file mode 100644 index 0000000000..19f7791032 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_getParameter-invalidparam.phpt @@ -0,0 +1,17 @@ +--TEST-- +Check xsltprocessor::getParameter with undefined parameter +--SKIPIF-- + +--FILE-- +getParameter('', 'doesnotexist')); +--EXPECTF-- +bool(false) +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_getParameter-wrongparam.phpt b/ext/xsl/tests/xsltprocessor_getParameter-wrongparam.phpt new file mode 100644 index 0000000000..758d4bab21 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_getParameter-wrongparam.phpt @@ -0,0 +1,26 @@ +--TEST-- +Check xsltprocessor::getparameter error handling +--SKIPIF-- + +--FILE-- +getParameter()); +var_dump($proc->getParameter(array(), array())); +var_dump($proc->getParameter('', array())); +--EXPECTF-- +Warning: XSLTProcessor::getParameter() expects exactly 2 parameters, 0 given in %s on line %d +bool(false) + +Warning: XSLTProcessor::getParameter() expects parameter 1 to be %binary_string_optional%, array given in %s on line %d +bool(false) + +Warning: XSLTProcessor::getParameter() expects parameter 2 to be %binary_string_optional%, array given in %s on line %d +bool(false) +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_getParameter.phpt b/ext/xsl/tests/xsltprocessor_getParameter.phpt new file mode 100644 index 0000000000..2430bc88a4 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_getParameter.phpt @@ -0,0 +1,19 @@ +--TEST-- +Check xsltprocessor::getparameter functionality +--SKIPIF-- + +--FILE-- +importStylesheet($xsl); +$proc->setParameter('', 'key', 'value'); +var_dump($proc->getParameter('', 'key')); +--EXPECTF-- +%string|unicode%(5) "value" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-allfuncs.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-allfuncs.phpt new file mode 100644 index 0000000000..1f0453ec84 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-allfuncs.phpt @@ -0,0 +1,30 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions()); +var_dump($proc->transformToXml($dom)); + +//var_dump($proc->registerPHPFunctions(array())); +//var_dump($proc->transformToXml($dom)); + +--EXPECTF-- +NULL +string(18) "This Is An Example" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-multiple.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-multiple.phpt new file mode 100644 index 0000000000..a5f23735c9 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-multiple.phpt @@ -0,0 +1,34 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions with array called multiple times +--DESCRIPTION-- +When being called multiple times with an array, +registerPHPFunctions adds the new functions to the allowed parameter +list - it does not replace the previously allowed functions. +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions(array('strpos', 'ucwords'))); +var_dump($proc->registerPHPFunctions(array('strrev', 'array_key_exists'))); +var_dump($proc->registerPHPFunctions(array())); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL +NULL +NULL +string(18) "This Is An Example" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-notallowed.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-notallowed.phpt new file mode 100644 index 0000000000..9492fc6861 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array-notallowed.phpt @@ -0,0 +1,28 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions with array and a not allowed function +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions(array())); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL + +Warning: XSLTProcessor::transformToXml(): Not allowed to call handler 'ucwords()' in %s on line %d +NULL +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array.phpt new file mode 100644 index 0000000000..0e467aabaa --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-array.phpt @@ -0,0 +1,26 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions with array +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions(array('ucwords'))); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL +string(18) "This Is An Example" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcnostring.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcnostring.phpt new file mode 100644 index 0000000000..a0d6bf6b75 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcnostring.phpt @@ -0,0 +1,37 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions and a non-string function in xsl +--DESCRIPTION-- +The XSL script tries to call a php function that is not a string which +is expected to fail +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc-nostring.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions()); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL + +Warning: XSLTProcessor::transformToXml(): Handler name must be a string in %s on line %d + +Warning: XSLTProcessor::transformToXml(): xmlXPathCompiledEval: evaluation failed in %s on line %d + +Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element value-of in %s on line %d + +Warning: XSLTProcessor::transformToXml(): XPath evaluation returned no result. in %s on line %d +NULL +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcundef.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcundef.phpt new file mode 100644 index 0000000000..1aa7bb051d --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-funcundef.phpt @@ -0,0 +1,36 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions and a undefined php function +--DESCRIPTION-- +The XSL script tries to call a php function that is not defined +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc-undef.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions()); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL + +Warning: XSLTProcessor::transformToXml(): Unable to call handler undefinedfunc() in %s on line %d + +Warning: XSLTProcessor::transformToXml(): xmlXPathCompiledEval: evaluation failed in %s on line %d + +Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element value-of in %s on line %d + +Warning: XSLTProcessor::transformToXml(): XPath evaluation returned no result. in %s on line %d +NULL +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-null.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-null.phpt new file mode 100644 index 0000000000..f74d785042 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-null.phpt @@ -0,0 +1,32 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions called with null to reset +--DESCRIPTION-- +When being called multiple times with an array, +registerPHPFunctions adds the new functions to the allowed parameter +list - it does not replace the previously allowed functions. +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions('ucwords')); +var_dump($proc->registerPHPFunctions(null)); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL +NULL +string(18) "This Is An Example" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-multiple.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-multiple.phpt new file mode 100644 index 0000000000..f15c08d327 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-multiple.phpt @@ -0,0 +1,32 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions with string called multiple times +--DESCRIPTION-- +When being called multiple times with a stringular function name only, +registerPHPFunctions adds the new function to the allowed parameter +list - it does not replace the old function. +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions('ucwords')); +var_dump($proc->registerPHPFunctions('strpos')); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL +NULL +string(18) "This Is An Example" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-notallowed.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-notallowed.phpt new file mode 100644 index 0000000000..9257749714 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string-notallowed.phpt @@ -0,0 +1,28 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions with string and not allowed function +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions('strpos')); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL + +Warning: XSLTProcessor::transformToXml(): Not allowed to call handler 'ucwords()' in %s on line %d +NULL +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string.phpt b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string.phpt new file mode 100644 index 0000000000..5fbba909b1 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_registerPHPFunctions-string.phpt @@ -0,0 +1,26 @@ +--TEST-- +Check xsltprocessor::registerPHPFunctions with string +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__)."/phpfunc.xsl"); +if(!$phpfuncxsl) { + echo "Error while parsing the xsl document\n"; + exit; +} +$proc->importStylesheet($phpfuncxsl); +var_dump($proc->registerPHPFunctions('ucwords')); +var_dump($proc->transformToXml($dom)); +--EXPECTF-- +NULL +string(18) "This Is An Example" +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_removeParameter-invalidparam.phpt b/ext/xsl/tests/xsltprocessor_removeParameter-invalidparam.phpt new file mode 100644 index 0000000000..f35b470840 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_removeParameter-invalidparam.phpt @@ -0,0 +1,18 @@ +--TEST-- +Check xsltprocessor::removeParameter with invalid parameter +--SKIPIF-- + +--FILE-- +importStylesheet($xsl); +var_dump($proc->removeParameter('', 'doesnotexist')); +--EXPECT-- +bool(false) +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_removeParameter-wrongparams.phpt b/ext/xsl/tests/xsltprocessor_removeParameter-wrongparams.phpt new file mode 100644 index 0000000000..c2b4f4c0c3 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_removeParameter-wrongparams.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check xsltprocessor::removeParameter wrong parameter handling +--SKIPIF-- + +--FILE-- +removeParameter(); +$proc->removeParameter(array(), array()); +$proc->removeParameter('', array()); +--EXPECTF-- +Warning: XSLTProcessor::removeParameter() expects exactly 2 parameters, 0 given in %s on line %d + +Warning: XSLTProcessor::removeParameter() expects parameter 1 to be %binary_string_optional%, array given in %s on line %d + +Warning: XSLTProcessor::removeParameter() expects parameter 2 to be %binary_string_optional%, array given in %s on line %d +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_removeParameter.phpt b/ext/xsl/tests/xsltprocessor_removeParameter.phpt new file mode 100644 index 0000000000..92be056985 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_removeParameter.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check xsltprocessor::removeParameter functionality +--SKIPIF-- + +--FILE-- +importStylesheet($xsl); +$proc->setParameter('', 'key', 'value'); +$proc->removeParameter('', 'key'); +var_dump($proc->getParameter('', 'key')); +--EXPECT-- +bool(false) +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_setparameter-errorquote.phpt b/ext/xsl/tests/xsltprocessor_setparameter-errorquote.phpt new file mode 100644 index 0000000000..44e49de601 --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_setparameter-errorquote.phpt @@ -0,0 +1,21 @@ +--TEST-- +Check xsltprocessor::setparameter error handling with both single and double quotes +--DESCRIPTION-- +Memleak: http://bugs.php.net/bug.php?id=48221 +--SKIPIF-- + +--FILE-- +importStylesheet($xsl); +$proc->setParameter('', '', '"\''); +$proc->transformToXml($dom); +--EXPECTF-- +Warning: XSLTProcessor::transformToXml(): Cannot create XPath expression (string contains both quote and double-quotes) in %s on line %d +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 diff --git a/ext/xsl/tests/xsltprocessor_setparameter-nostring.phpt b/ext/xsl/tests/xsltprocessor_setparameter-nostring.phpt new file mode 100644 index 0000000000..c4fcd709ea --- /dev/null +++ b/ext/xsl/tests/xsltprocessor_setparameter-nostring.phpt @@ -0,0 +1,22 @@ +--TEST-- +Check xsltprocessor::setparameter error handling with no-string +--DESCRIPTION-- +Memleak: http://bugs.php.net/bug.php?id=48221 +--SKIPIF-- + +--FILE-- +importStylesheet($xsl); +var_dump($proc->setParameter('', array(4, 'abc'))); +$proc->transformToXml($dom); +--EXPECTF-- +Warning: XSLTProcessor::setParameter(): Invalid parameter array in %s on line %d +bool(false) +--CREDITS-- +Christian Weiske, cweiske@php.net +PHP Testfest Berlin 2009-05-09 -- 2.40.0