Skip to content

Commit 813830e

Browse files
royoparogeriopradoj
authored andcommitted
added various tests for XSLTProcessor and one test for iconv extension
1 parent ef39f40 commit 813830e

22 files changed

+1052
-0
lines changed

ext/iconv/tests/iconv_basic_001.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Test the basics to function iconv.
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$in_charset = 'UTF-8';
10+
$out_charset = 'ASCII//TRANSLIT';
11+
$string_to_translate = 'Žluťoučký kůň\n';
12+
13+
$string_out = iconv($in_charset, $out_charset, $string_to_translate);
14+
15+
var_dump($string_out);
16+
?>
17+
--EXPECT--
18+
string(15) "Zlutoucky kun\n"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Test the basics to function XSLTProcessor::hasExsltSupport().
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$proc = new XSLTProcessor();
10+
var_dump($proc->hasExsltSupport());
11+
?>
12+
--EXPECTF--
13+
bool(true)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Test the basics to function XSLTProcessor::hasExsltSupport() when the xsl extension os not available.
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php (!extension_loaded('xsl')) or die('skip xsl extension is available'); ?>
7+
--FILE--
8+
<?php
9+
$proc = new XSLTProcessor();
10+
var_dump($proc->hasExsltSupport());
11+
?>
12+
--EXPECTF--
13+
Fatal error: Class 'XSLTProcessor' not found in %s on line %i
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Check XSLTProcessor::hasExsltSupport() with 1 parameter
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$proc = new XSLTProcessor();
10+
var_dump($proc->hasExsltSupport('stringValue'));
11+
?>
12+
--EXPECTF--
13+
bool(true)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Test the basics to function XSLTProcessor::transformToDoc().
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$xml = <<<EOB
10+
<allusers>
11+
<user>
12+
<uid>royopa</uid>
13+
</user>
14+
</allusers>
15+
EOB;
16+
$xsl = <<<EOB
17+
<?xml version="1.0" encoding="UTF-8"?>
18+
<xsl:stylesheet version="1.0"
19+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20+
xmlns:php="http://php.net/xsl">
21+
<xsl:output method="html" encoding="utf-8" indent="yes"/>
22+
<xsl:template match="allusers">
23+
<html><body>
24+
<h2>Users</h2>
25+
<table>
26+
<xsl:for-each select="user">
27+
<tr><td>
28+
<xsl:value-of
29+
select="php:function('ucfirst',string(uid))"/>
30+
</td></tr>
31+
</xsl:for-each>
32+
</table>
33+
</body></html>
34+
</xsl:template>
35+
</xsl:stylesheet>
36+
EOB;
37+
38+
$xmldoc = new DOMDocument('1.0', 'utf-8');
39+
$xmldoc->loadXML($xml);
40+
41+
$xsldoc = new DOMDocument('1.0', 'utf-8');
42+
$xsldoc->loadXML($xsl);
43+
44+
$proc = new XSLTProcessor();
45+
$proc->registerPHPFunctions();
46+
$proc->importStyleSheet($xsldoc);
47+
48+
var_dump($proc->transformToDoc($xmldoc)->firstChild->tagName);
49+
?>
50+
--EXPECT--
51+
string(4) "html"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Check XSLTProcessor::transformToDoc() with null parameter
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$xml = <<<EOB
10+
<allusers>
11+
<user>
12+
<uid>bob</uid>
13+
</user>
14+
<user>
15+
<uid>joe</uid>
16+
</user>
17+
</allusers>
18+
EOB;
19+
$xsl = <<<EOB
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<xsl:stylesheet version="1.0"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:php="http://php.net/xsl">
24+
<xsl:output method="html" encoding="utf-8" indent="yes"/>
25+
<xsl:template match="allusers">
26+
<html><body>
27+
<h2>Users</h2>
28+
<table>
29+
<xsl:for-each select="user">
30+
<tr><td>
31+
<xsl:value-of
32+
select="php:function('ucfirst',string(uid))"/>
33+
</td></tr>
34+
</xsl:for-each>
35+
</table>
36+
</body></html>
37+
</xsl:template>
38+
</xsl:stylesheet>
39+
EOB;
40+
41+
$xmldoc = new DOMDocument('1.0', 'utf-8');
42+
$xmldoc->loadXML($xml);
43+
44+
$xsldoc = new DOMDocument('1.0', 'utf-8');
45+
$xsldoc->loadXML($xsl);
46+
47+
$proc = new XSLTProcessor();
48+
$proc->registerPHPFunctions();
49+
$proc->importStyleSheet($xsldoc);
50+
51+
echo $proc->transformToDoc(null);
52+
?>
53+
--EXPECTF--
54+
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, null given in %s on line %i
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
Check XSLTProcessor::transformToDoc() with array parameter
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$xml = <<<EOB
10+
<allusers>
11+
<user>
12+
<uid>bob</uid>
13+
</user>
14+
<user>
15+
<uid>joe</uid>
16+
</user>
17+
</allusers>
18+
EOB;
19+
$xsl = <<<EOB
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<xsl:stylesheet version="1.0"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:php="http://php.net/xsl">
24+
<xsl:output method="html" encoding="utf-8" indent="yes"/>
25+
<xsl:template match="allusers">
26+
<html><body>
27+
<h2>Users</h2>
28+
<table>
29+
<xsl:for-each select="user">
30+
<tr><td>
31+
<xsl:value-of
32+
select="php:function('ucfirst',string(uid))"/>
33+
</td></tr>
34+
</xsl:for-each>
35+
</table>
36+
</body></html>
37+
</xsl:template>
38+
</xsl:stylesheet>
39+
EOB;
40+
41+
$xmldoc = new DOMDocument('1.0', 'utf-8');
42+
$xmldoc->loadXML($xml);
43+
44+
$xsldoc = new DOMDocument('1.0', 'utf-8');
45+
$xsldoc->loadXML($xsl);
46+
47+
$proc = new XSLTProcessor();
48+
$proc->registerPHPFunctions();
49+
$proc->importStyleSheet($xsldoc);
50+
51+
$wrong_parameter = array();
52+
53+
echo $proc->transformToDoc($wrong_parameter);
54+
?>
55+
--EXPECTF--
56+
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, array given in %s on line %i
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Check XSLTProcessor::transformToDoc() with 4 parameters
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$xml = <<<EOB
10+
<allusers>
11+
<user>
12+
<uid>bob</uid>
13+
</user>
14+
<user>
15+
<uid>joe</uid>
16+
</user>
17+
</allusers>
18+
EOB;
19+
$xsl = <<<EOB
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<xsl:stylesheet version="1.0"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:php="http://php.net/xsl">
24+
<xsl:output method="html" encoding="utf-8" indent="yes"/>
25+
<xsl:template match="allusers">
26+
<html><body>
27+
<h2>Users</h2>
28+
<table>
29+
<xsl:for-each select="user">
30+
<tr><td>
31+
<xsl:value-of
32+
select="php:function('ucfirst',string(uid))"/>
33+
</td></tr>
34+
</xsl:for-each>
35+
</table>
36+
</body></html>
37+
</xsl:template>
38+
</xsl:stylesheet>
39+
EOB;
40+
41+
$xmldoc = new DOMDocument('1.0', 'utf-8');
42+
$xmldoc->loadXML($xml);
43+
44+
$xsldoc = new DOMDocument('1.0', 'utf-8');
45+
$xsldoc->loadXML($xsl);
46+
47+
$proc = new XSLTProcessor();
48+
$proc->registerPHPFunctions();
49+
$proc->importStyleSheet($xsldoc);
50+
51+
echo $proc->transformToDoc($xmldoc, 'string', 98, true);
52+
?>
53+
--EXPECTF--
54+
Warning: XSLTProcessor::transformToDoc() expects at most 2 parameters, 4 given in %s on line %i
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
Check XSLTProcessor::transformToDoc() with string parameter
3+
--CREDITS--
4+
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php extension_loaded('xsl') or die('skip xsl extension is not available'); ?>
7+
--FILE--
8+
<?php
9+
$xml = <<<EOB
10+
<allusers>
11+
<user>
12+
<uid>bob</uid>
13+
</user>
14+
<user>
15+
<uid>joe</uid>
16+
</user>
17+
</allusers>
18+
EOB;
19+
$xsl = <<<EOB
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<xsl:stylesheet version="1.0"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:php="http://php.net/xsl">
24+
<xsl:output method="html" encoding="utf-8" indent="yes"/>
25+
<xsl:template match="allusers">
26+
<html><body>
27+
<h2>Users</h2>
28+
<table>
29+
<xsl:for-each select="user">
30+
<tr><td>
31+
<xsl:value-of
32+
select="php:function('ucfirst',string(uid))"/>
33+
</td></tr>
34+
</xsl:for-each>
35+
</table>
36+
</body></html>
37+
</xsl:template>
38+
</xsl:stylesheet>
39+
EOB;
40+
41+
$xmldoc = new DOMDocument('1.0', 'utf-8');
42+
$xmldoc->loadXML($xml);
43+
44+
$xsldoc = new DOMDocument('1.0', 'utf-8');
45+
$xsldoc->loadXML($xsl);
46+
47+
$proc = new XSLTProcessor();
48+
$proc->registerPHPFunctions();
49+
$proc->importStyleSheet($xsldoc);
50+
51+
$wrong_parameter = 'stringValue';
52+
53+
echo $proc->transformToDoc($wrong_parameter);
54+
?>
55+
--EXPECTF--
56+
Warning: XSLTProcessor::transformToDoc() expects parameter 1 to be object, string given in %s on line %i

0 commit comments

Comments
 (0)