mirror of
https://github.com/php/php-src.git
synced 2024-12-01 05:43:38 +08:00
Merge branch 'pull-request/855' into PHP-5.5
* pull-request/855: added some tests to datetime and dateinterval functions added various tests for XSLTProcessor and one test for iconv extension
This commit is contained in:
commit
9d7206dcea
34
ext/date/tests/date_interval_create_from_date_string.phpt
Normal file
34
ext/date/tests/date_interval_create_from_date_string.phpt
Normal file
@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
Test date_interval_create_from_date_string() function : basic functionality
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--FILE--
|
||||
<?php
|
||||
$string = '1 day'; //P1D
|
||||
$i = date_interval_create_from_date_string($string);
|
||||
var_dump($i->d);
|
||||
|
||||
$string = '2 weeks'; //14 days
|
||||
$i = date_interval_create_from_date_string($string);
|
||||
var_dump($i->d);
|
||||
|
||||
$string = '3 months';
|
||||
$i = date_interval_create_from_date_string($string);
|
||||
var_dump($i->m);
|
||||
|
||||
$string = '4 years';
|
||||
$i = date_interval_create_from_date_string($string);
|
||||
var_dump($i->y);
|
||||
|
||||
$string = '1 year + 1 day';
|
||||
$i = date_interval_create_from_date_string($string);
|
||||
var_dump($i->y);
|
||||
var_dump($i->d);
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(1)
|
||||
int(14)
|
||||
int(3)
|
||||
int(4)
|
||||
int(1)
|
||||
int(1)
|
@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
Test date_interval_create_from_date_string() function : null parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--FILE--
|
||||
<?php
|
||||
$i = date_interval_create_from_date_string(null); //returns a empty object
|
||||
var_dump($i);
|
||||
?>
|
||||
--EXPECTF--
|
||||
object(DateInterval)#1 (15) {
|
||||
["y"]=>
|
||||
int(0)
|
||||
["m"]=>
|
||||
int(0)
|
||||
["d"]=>
|
||||
int(0)
|
||||
["h"]=>
|
||||
int(0)
|
||||
["i"]=>
|
||||
int(0)
|
||||
["s"]=>
|
||||
int(0)
|
||||
["weekday"]=>
|
||||
int(0)
|
||||
["weekday_behavior"]=>
|
||||
int(0)
|
||||
["first_last_day_of"]=>
|
||||
int(0)
|
||||
["invert"]=>
|
||||
int(0)
|
||||
["days"]=>
|
||||
int(0)
|
||||
["special_type"]=>
|
||||
int(0)
|
||||
["special_amount"]=>
|
||||
int(0)
|
||||
["have_weekday_relative"]=>
|
||||
int(0)
|
||||
["have_special_relative"]=>
|
||||
int(0)
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
--TEST--
|
||||
Test date_interval_create_from_date_string() function : wrong parameter (array)
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--FILE--
|
||||
<?php
|
||||
$wrong_parameter = array();
|
||||
$i = date_interval_create_from_date_string($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_interval_create_from_date_string() expects parameter 1 to be string, array given in %s on line %d
|
@ -0,0 +1,9 @@
|
||||
--TEST--
|
||||
Test date_interval_create_from_date_string() function : with 2 parameters (wrong).
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--FILE--
|
||||
<?php
|
||||
$i = date_interval_create_from_date_string('1 year', 'wrong');
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_interval_create_from_date_string() expects exactly 1 parameter, 2 given in %s on line %d
|
19
ext/date/tests/date_timestamp_set.phpt
Normal file
19
ext/date/tests/date_timestamp_set.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
Test the basics to function date_timestamp_set().
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
$dtms021 = date_create();
|
||||
|
||||
date_timestamp_set($dtms021, 1234567890);
|
||||
|
||||
var_dump(date_format($dtms021, 'B => (U) => T Y-M-d H:i:s'));
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(47) "021 => (1234567890) => UTC 2009-Feb-13 23:31:30"
|
17
ext/date/tests/date_timestamp_set_nullparam.phpt
Normal file
17
ext/date/tests/date_timestamp_set_nullparam.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Test the function date_timestamp_set() with first null parameter.
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
$dtms021 = date_create();
|
||||
|
||||
date_timestamp_set(null, 1234567890);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_timestamp_set() expects parameter 1 to be DateTime, null given in %s on line %d
|
24
ext/date/tests/date_timestamp_set_nullparam2.phpt
Normal file
24
ext/date/tests/date_timestamp_set_nullparam2.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Test the function date_timestamp_set() with second null parameter.
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
$dtms021 = date_create();
|
||||
|
||||
var_dump(date_timestamp_set($dtms021, null));
|
||||
?>
|
||||
--EXPECTF--
|
||||
object(DateTime)#1 (3) {
|
||||
["date"]=>
|
||||
string(26) "1970-01-01 00:00:00.000000"
|
||||
["timezone_type"]=>
|
||||
int(3)
|
||||
["timezone"]=>
|
||||
string(3) "UTC"
|
||||
}
|
17
ext/date/tests/date_timestamp_set_wrongparam_001.phpt
Normal file
17
ext/date/tests/date_timestamp_set_wrongparam_001.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Check the function date_timestamp_set() with first parameter wrong (array).
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
$dtms021 = array();
|
||||
|
||||
date_timestamp_set($dtms021, 123456789);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_timestamp_set() expects parameter 1 to be DateTime, array given in %s on line %d
|
15
ext/date/tests/date_timestamp_set_wrongparam_002.phpt
Normal file
15
ext/date/tests/date_timestamp_set_wrongparam_002.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Check the function date_timestamp_set() with first parameter wrong (integer).
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
date_timestamp_set(987654321, 123456789);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_timestamp_set() expects parameter 1 to be DateTime, integer given in %s on line %d
|
19
ext/date/tests/date_timestamp_set_wrongparam_003.phpt
Normal file
19
ext/date/tests/date_timestamp_set_wrongparam_003.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
Check the function date_timestamp_set() with second parameter wrong (array).
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
$dtms021 = new DateTime();
|
||||
|
||||
$wrong_parameter = array();
|
||||
|
||||
date_timestamp_set($dtms021, $wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_timestamp_set() expects parameter 2 to be long, array given in %s on line %d
|
17
ext/date/tests/date_timestamp_set_wrongparam_004.phpt
Normal file
17
ext/date/tests/date_timestamp_set_wrongparam_004.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Check the function date_timestamp_set() with 3 parameters.
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
$dftz021 = date_default_timezone_get(); //UTC
|
||||
|
||||
$dtms021 = new DateTime();
|
||||
|
||||
date_timestamp_set($dtms021, 123456789, 'error');
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: date_timestamp_set() expects exactly 2 parameters, 3 given in %s on line %d
|
13
ext/date/tests/timezone_version_get.phpt
Normal file
13
ext/date/tests/timezone_version_get.phpt
Normal file
@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
Test the basics to function timezone_version_get().
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--INI--
|
||||
date.timezone = UTC;
|
||||
date_default_timezone_set("America/Sao_Paulo");
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(timezone_version_get());
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
string\([6-7]\) \"20[0-9][0-9]\.[1-9][0-9]?\"
|
18
ext/iconv/tests/iconv_basic_001.phpt
Normal file
18
ext/iconv/tests/iconv_basic_001.phpt
Normal file
@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
Test the basics to function iconv.
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$in_charset = 'UTF-8';
|
||||
$out_charset = 'ASCII//TRANSLIT';
|
||||
$string_to_translate = 'Žluťoučký kůň\n';
|
||||
|
||||
$string_out = iconv($in_charset, $out_charset, $string_to_translate);
|
||||
|
||||
var_dump($string_out);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(15) "Zlutoucky kun\n"
|
13
ext/xsl/tests/xsltprocessor_hasExsltSupport.phpt
Normal file
13
ext/xsl/tests/xsltprocessor_hasExsltSupport.phpt
Normal file
@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
Test the basics to function XSLTProcessor::hasExsltSupport().
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$proc = new XSLTProcessor();
|
||||
var_dump($proc->hasExsltSupport());
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
Test the basics to function XSLTProcessor::hasExsltSupport() when the xsl extension os not available.
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php (!extension_loaded('xsl')) or die('skip xsl extension is available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$proc = new XSLTProcessor();
|
||||
var_dump($proc->hasExsltSupport());
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Class 'XSLTProcessor' not found in %s on line %i
|
@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::hasExsltSupport() with 1 parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$proc = new XSLTProcessor();
|
||||
var_dump($proc->hasExsltSupport('stringValue'));
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
51
ext/xsl/tests/xsltprocessor_transformToDoc.phpt
Normal file
51
ext/xsl/tests/xsltprocessor_transformToDoc.phpt
Normal file
@ -0,0 +1,51 @@
|
||||
--TEST--
|
||||
Test the basics to function XSLTProcessor::transformToDoc().
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>royopa</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
var_dump($proc->transformToDoc($xmldoc)->firstChild->tagName);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(4) "html"
|
54
ext/xsl/tests/xsltprocessor_transformToDoc_nullparam.phpt
Normal file
54
ext/xsl/tests/xsltprocessor_transformToDoc_nullparam.phpt
Normal file
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToDoc() with null parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
echo $proc->transformToDoc(null);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, null given in %s on line %i
|
@ -0,0 +1,56 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToDoc() with array parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = array();
|
||||
|
||||
echo $proc->transformToDoc($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, array given in %s on line %i
|
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToDoc() with 4 parameters
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
echo $proc->transformToDoc($xmldoc, 'string', 98, true);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToDoc() expects at most 2 parameters, 4 given in %s on line %i
|
@ -0,0 +1,56 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToDoc() with string parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = 'stringValue';
|
||||
|
||||
echo $proc->transformToDoc($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, string given in %s on line %i
|
@ -0,0 +1,56 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToDoc() with boolean parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = true;
|
||||
|
||||
echo $proc->transformToDoc($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, boolean given in %s on line %i
|
53
ext/xsl/tests/xsltprocessor_transformToURI.phpt
Normal file
53
ext/xsl/tests/xsltprocessor_transformToURI.phpt
Normal file
@ -0,0 +1,53 @@
|
||||
--TEST--
|
||||
Test the basics to function XSLTProcessor::transformToURI().
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
var_dump($proc->transformToURI($xsldoc, 'php://output'));
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(56)
|
54
ext/xsl/tests/xsltprocessor_transformToURI_nullparam.phpt
Normal file
54
ext/xsl/tests/xsltprocessor_transformToURI_nullparam.phpt
Normal file
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToURI() with null parameters
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
echo $proc->transformToURI(null, null);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToUri() expects parameter 1 to be object, null given in %s on line %i
|
@ -0,0 +1,57 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToURI() with array parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = array();
|
||||
$uri = 'php://output';
|
||||
|
||||
echo $proc->transformToURI($wrong_parameter, $uri);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToUri() expects parameter 1 to be object, array given in %s on line %i
|
@ -0,0 +1,57 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToURI() with string parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = 'stringValue';
|
||||
$uri = 'php://output';
|
||||
|
||||
echo $proc->transformToURI($wrong_parameter, $uri);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToUri() expects parameter 1 to be object, string given in %s on line %i
|
@ -0,0 +1,57 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToURI() with boolean parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = false;
|
||||
$uri = 'php://output';
|
||||
|
||||
echo $proc->transformToURI($wrong_parameter, $uri);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToUri() expects parameter 1 to be object, boolean given in %s on line %i
|
@ -0,0 +1,56 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToURI() with 3 parameters
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$uri = 'php://output';
|
||||
|
||||
echo $proc->transformToURI($xsldoc, $uri, 'stringValue');
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToUri() expects exactly 2 parameters, 3 given in %s on line %i
|
61
ext/xsl/tests/xsltprocessor_transformToXML.phpt
Normal file
61
ext/xsl/tests/xsltprocessor_transformToXML.phpt
Normal file
@ -0,0 +1,61 @@
|
||||
--TEST--
|
||||
Test the basics to function XSLTProcessor::transformToXml().
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
var_dump($proc->transformToXML($xmldoc));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(135) "<html xmlns:php="http://php.net/xsl"><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<tr><td>Bob</td></tr>
|
||||
<tr><td>Joe</td></tr>
|
||||
</table>
|
||||
</body></html>
|
||||
"
|
54
ext/xsl/tests/xsltprocessor_transformToXML_nullparam.phpt
Normal file
54
ext/xsl/tests/xsltprocessor_transformToXML_nullparam.phpt
Normal file
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToXml() with null parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
echo $proc->transformToXML(null);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToXml() expects parameter 1 to be object, null given in %s on line %i
|
@ -0,0 +1,55 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToXML() with array parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = array();
|
||||
echo $proc->transformToXML($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToXml() expects parameter 1 to be object, array given in %s on line %d
|
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToXML() with 3 parameters
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
echo $proc->transformToXML($xmldoc, 'string', 98);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToXml() expects exactly 1 parameter, 3 given in %s on line %i
|
@ -0,0 +1,55 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToXML() with string parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = 'stringValue';
|
||||
echo $proc->transformToXML($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToXml() expects parameter 1 to be object, string given in %s on line %d
|
@ -0,0 +1,55 @@
|
||||
--TEST--
|
||||
Check XSLTProcessor::transformToXML() with boolean parameter
|
||||
--CREDITS--
|
||||
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$xml = <<<EOB
|
||||
<allusers>
|
||||
<user>
|
||||
<uid>bob</uid>
|
||||
</user>
|
||||
<user>
|
||||
<uid>joe</uid>
|
||||
</user>
|
||||
</allusers>
|
||||
EOB;
|
||||
$xsl = <<<EOB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:php="http://php.net/xsl">
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes"/>
|
||||
<xsl:template match="allusers">
|
||||
<html><body>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
<xsl:for-each select="user">
|
||||
<tr><td>
|
||||
<xsl:value-of
|
||||
select="php:function('ucfirst',string(uid))"/>
|
||||
</td></tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body></html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
EOB;
|
||||
|
||||
$xmldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xmldoc->loadXML($xml);
|
||||
|
||||
$xsldoc = new DOMDocument('1.0', 'utf-8');
|
||||
$xsldoc->loadXML($xsl);
|
||||
|
||||
$proc = new XSLTProcessor();
|
||||
$proc->registerPHPFunctions();
|
||||
$proc->importStyleSheet($xsldoc);
|
||||
|
||||
$wrong_parameter = true;
|
||||
echo $proc->transformToXML($wrong_parameter);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: XSLTProcessor::transformToXml() expects parameter 1 to be object, boolean given in %s on line %d
|
Loading…
Reference in New Issue
Block a user