Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,46 @@
--TEST--
File_Find::glob()
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
$ff = new File_Find();
$result0 = &$ff->glob( '/.*txt/', $tmpdir.'/File_Find/dir/', 'perl' ) ;
$result1 = &$ff->glob( '/.*txt/', $tmpdir.'/File_Find/dir', 'perl' ) ;
$result2 = &File_Find::glob( '/.*txt/', $tmpdir.'/File_Find/dir/', 'perl' ) ;
$result3 = &File_Find::glob( '/.*txt/', '/nosuch/', 'perl' ) ;
print_r($result0);
print_r($result1);
print_r($result2);
print $result3->getMessage();
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => 1.txt
[1] => 2.txt
[2] => txtdir
)
Array
(
[0] => 1.txt
[1] => 2.txt
[2] => txtdir
)
Array
(
[0] => 1.txt
[1] => 2.txt
[2] => txtdir
)
Cannot open directory /nosuch/

View File

@@ -0,0 +1,97 @@
--TEST--
File_Find::mapTree()
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
$ff = new File_Find();
$result[0] = $ff->mapTree('File_Find/dir/') ;
$result[1] = $ff->mapTree('File_Find/dir') ;
$result[2] = File_Find::mapTree('File_Find/dir') ;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($result as $k => $r) {
$result[$k][0] = str_replace("\\", '/', $result[$k][0]);
$result[$k][1] = str_replace("\\", '/', $result[$k][1]);
}
}
print_r($result[0]);
print_r($result[1]);
print_r($result[2]);
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => Array
(
[0] => File_Find/dir
[1] => File_Find/dir/dir2
[2] => File_Find/dir/dir3
[3] => File_Find/dir/txtdir
)
[1] => Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.bak
[3] => File_Find/dir/dir2/3.txt
[4] => File_Find/dir/dir3/4.bak
[5] => File_Find/dir/dir3/4.txt
[6] => File_Find/dir/txtdir/5.txt
)
)
Array
(
[0] => Array
(
[0] => File_Find/dir
[1] => File_Find/dir/dir2
[2] => File_Find/dir/dir3
[3] => File_Find/dir/txtdir
)
[1] => Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.bak
[3] => File_Find/dir/dir2/3.txt
[4] => File_Find/dir/dir3/4.bak
[5] => File_Find/dir/dir3/4.txt
[6] => File_Find/dir/txtdir/5.txt
)
)
Array
(
[0] => Array
(
[0] => File_Find/dir
[1] => File_Find/dir/dir2
[2] => File_Find/dir/dir3
[3] => File_Find/dir/txtdir
)
[1] => Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.bak
[3] => File_Find/dir/dir2/3.txt
[4] => File_Find/dir/dir3/4.bak
[5] => File_Find/dir/dir3/4.txt
[6] => File_Find/dir/txtdir/5.txt
)
)

View File

@@ -0,0 +1,91 @@
--TEST--
File_Find::mapTreeMultiple()
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
$ff = new File_Find();
$result0 = $ff->mapTreeMultiple('File_Find//dir/') ;
$result1 = $ff->mapTreeMultiple('File_Find/dir') ;
$result2 = File_Find::mapTreeMultiple('File_Find/dir') ;
print_r($result0);
print_r($result1);
print_r($result2);
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => 1.txt
[1] => 2.txt
[dir2] => Array
(
[0] => 3.bak
[1] => 3.txt
)
[dir3] => Array
(
[0] => 4.bak
[1] => 4.txt
)
[txtdir] => Array
(
[0] => 5.txt
)
)
Array
(
[0] => 1.txt
[1] => 2.txt
[dir2] => Array
(
[0] => 3.bak
[1] => 3.txt
)
[dir3] => Array
(
[0] => 4.bak
[1] => 4.txt
)
[txtdir] => Array
(
[0] => 5.txt
)
)
Array
(
[0] => 1.txt
[1] => 2.txt
[dir2] => Array
(
[0] => 3.bak
[1] => 3.txt
)
[dir3] => Array
(
[0] => 4.bak
[1] => 4.txt
)
[txtdir] => Array
(
[0] => 5.txt
)
)

View File

@@ -0,0 +1,53 @@
--TEST--
File_Find::search()
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
$ff = new File_Find();
$result[0] = $ff->search('/txt/', 'File_Find/dir/', 'perl') ;
$result[1] = $ff->search('/txt/', 'File_Find/dir', 'perl') ;
$result[2] = File_Find::search('/3/', 'File_Find/dir/', 'perl') ;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($result as $k => $r) {
$result[$k] = str_replace("\\", '/', $result[$k]);
}
}
print_r($result[0]);
print_r($result[1]);
print_r($result[2]);
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.txt
[3] => File_Find/dir/dir3/4.txt
[4] => File_Find/dir/txtdir/5.txt
)
Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.txt
[3] => File_Find/dir/dir3/4.txt
[4] => File_Find/dir/txtdir/5.txt
)
Array
(
[0] => File_Find/dir/dir2/3.bak
[1] => File_Find/dir/dir2/3.txt
[2] => File_Find/dir/dir3/4.bak
[3] => File_Find/dir/dir3/4.txt
)

View File

@@ -0,0 +1,63 @@
--TEST--
File_Find::search() inside another object
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
class Foo {
function search($pattern, $path, $type='php') {
$retval = File_Find::search($pattern, $path, $type) ;
return($retval);
}
}
$f = new Foo();
$result[0] = $f->search('/txt/', 'File_Find/dir/', 'perl') ;
$result[1] = $f->search('/txt/', 'File_Find/dir', 'perl') ;
$result[2] = Foo::search('/txt/', 'File_Find/dir/', 'perl') ;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($result as $k => $r) {
$result[$k] = str_replace("\\", '/', $result[$k]);
}
}
print_r($result[0]);
print_r($result[1]);
print_r($result[2]);
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.txt
[3] => File_Find/dir/dir3/4.txt
[4] => File_Find/dir/txtdir/5.txt
)
Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.txt
[3] => File_Find/dir/dir3/4.txt
[4] => File_Find/dir/txtdir/5.txt
)
Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.txt
[3] => File_Find/dir/dir3/4.txt
[4] => File_Find/dir/txtdir/5.txt
)

View File

@@ -0,0 +1,96 @@
--TEST--
File_Find::test 'shell' mode patterns
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
// *.php -> .*\.php$
$result[0] = &File_Find::search('*.*', 'File_Find/dir/', 'shell', false);
$result[1] = &File_Find::search('*.bak', 'File_Find/dir/', 'shell', false);
$result[2] = &File_Find::search('*3*', 'File_Find/', 'shell', false, 'both');
$result[3] = &File_Find::glob('', 'File_Find/dir', 'shell');
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($result as $k => $r) {
$result[$k] = str_replace("\\", '/', $result[$k]);
}
}
print_r($result[0]);
print_r($result[1]);
print_r($result[2]);
print_r($result[3]);
$tcases[] = array("*scope", "msscope");
$tcases[] = array("some*", "something");
$tcases[] = array("some*", "some");
$tcases[] = array("some", "something.wrong");
$tcases[] = array("*som?e*", "som_exx.dll");
$tcases[] = array("*.dll", "som_exx.dll");
$tcases[] = array("*.dll", "som_exx.dll.bak");
$tcases[] = array("*.", "som_exx.dll.bak");
$tcases[] = array("*.", "som_exx");
$tcases[] = array("*.", ".exx");
$tcases[] = array("some file.xml.*", "some file.xml");
$tcases[] = array("some file.*", "some file");
$tcases[] = array("some.*", "some.xml");
$tcases[] = array("some.*", "somexml");
foreach($tcases as $tc) {
list($tm, $tf) = $tc;
echo ( File_Find_match_shell($tm, $tf) ) ? "TRUE " : "FALSE ";
echo "$tm \t$tf\n";
}
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => File_Find/dir/1.txt
[1] => File_Find/dir/2.txt
[2] => File_Find/dir/dir2/3.bak
[3] => File_Find/dir/dir2/3.txt
[4] => File_Find/dir/dir3/4.bak
[5] => File_Find/dir/dir3/4.txt
[6] => File_Find/dir/txtdir/5.txt
)
Array
(
[0] => File_Find/dir/dir2/3.bak
[1] => File_Find/dir/dir3/4.bak
)
Array
(
[0] => File_Find/dir/dir2/3.bak
[1] => File_Find/dir/dir2/3.txt
[2] => File_Find/dir/dir3
)
Array
(
[0] => 1.txt
[1] => 2.txt
[2] => dir2
[3] => dir3
[4] => txtdir
)
TRUE *scope msscope
TRUE some* something
TRUE some* some
TRUE some something.wrong
TRUE *som?e* som_exx.dll
TRUE *.dll som_exx.dll
FALSE *.dll som_exx.dll.bak
FALSE *. som_exx.dll.bak
TRUE *. som_exx
FALSE *. .exx
TRUE some file.xml.* some file.xml
TRUE some file.* some file
TRUE some.* some.xml
FALSE some.* somexml

View File

@@ -0,0 +1,23 @@
--TEST--
1.phpt: addRow 1 row 1 column with no extra options
--FILE--
<?php
// $Id: 1.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,75 @@
--TEST--
10.phpt: 6 row 3 column, setAllAttributes
--FILE--
<?php
// $Id: 10.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
$data[3][] = 'Foo';
$data[3][] = 'Bar';
$data[3][] = 'Test';
$data[4][] = 'Foo';
$data[4][] = 'Bar';
$data[4][] = 'Test';
$data[5][] = 'Foo';
$data[5][] = 'Bar';
$data[5][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
// This overwrites attrs thus removing align="right"
$table->setColAttributes(0, 'bgcolor = "pink"');
// This updates attrs thus keeping aligh="right" but change bgcolor
$table->updateColAttributes(2, array('bgcolor = "blue"', 'bgcolor="green"', 'bgcolor="red"'));
// this overwrites
$table->setAllAttributes('bgcolor="pink"');
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink">Bar</td>
<td bgcolor="pink">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink">Bar</td>
<td bgcolor="pink">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink">Bar</td>
<td bgcolor="pink">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink">Bar</td>
<td bgcolor="pink">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink">Bar</td>
<td bgcolor="pink">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink">Bar</td>
<td bgcolor="pink">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,32 @@
--TEST--
11.phpt: 2 row 1 column, setAutoFill / getAutoFill
--FILE--
<?php
// $Id: 11.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$table->setAutoFill('N/A');
$data[0][] = 'Test';
$data[1][] = '';
foreach($data as $key => $value) {
$table->addRow($value);
}
echo $table->getAutoFill() . "\n";
// output
echo $table->toHTML();
?>
--EXPECT--
N/A
<table>
<tr>
<td>Test</td>
</tr>
<tr>
<td>N/A</td>
</tr>
</table>

View File

@@ -0,0 +1,35 @@
--TEST--
12.phpt: 2 row 2 column, setAutoGrow / getAutoGrow
--FILE--
<?php
// $Id: 12.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$table->setAutoGrow(true);
$data[0][] = 'Test';
$data[1][] = '';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
var_dump($table->getAutoGrow());
// output
echo $table->toHTML();
?>
--EXPECT--
bool(true)
<table>
<tr>
<td>Test</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,32 @@
--TEST--
13.phpt: 2 row 1 column, setCellContents / getCellContents
--FILE--
<?php
// $Id: 13.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][] = 'Test';
$data[1][] = '';
foreach($data as $key => $value) {
$table->addRow($value);
}
echo $table->getCellContents(0, 0) . "\n";
$table->setCellContents(0, 0, 'FOOBAR');
echo $table->getCellContents(0, 0) . "\n";
// output
echo $table->toHTML();
?>
--EXPECT--
Test
FOOBAR
<table>
<tr>
<td>FOOBAR</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>

View File

@@ -0,0 +1,49 @@
--TEST--
14.phpt: 3 row 3 column, setColCount / getColCount / setRowCount / getRowCount
--FILE--
<?php
// $Id: 14.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow"');
}
echo $table->getRowCount() . "\n";
echo $table->getColCount() . "\n";
echo $table->setRowCount(2);
echo $table->setColCount(2);
echo $table->getRowCount() . "\n";
echo $table->getColCount() . "\n";
// output
echo $table->toHTML();
?>
--EXPECT--
3
3
2
2
<table width="400">
<tr>
<td bgcolor="yellow">Foo</td>
<td bgcolor="yellow">Bar</td>
</tr>
<tr>
<td bgcolor="yellow">Foo</td>
<td bgcolor="yellow">Bar</td>
</tr>
</table>

View File

@@ -0,0 +1,33 @@
--TEST--
15.phpt: 2 row 2 column, setHeaderContents
--FILE--
<?php
// $Id: 15.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Test';
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
$table->setHeaderContents(0, 0, 'Header', 'bgcolor="blue"');
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<th bgcolor="blue" align="right">Header</th>
<td bgcolor="yellow" align="right">Test</td>
</tr>
<tr>
<td bgcolor="yellow" align="right">Test</td>
<td bgcolor="yellow" align="right">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,34 @@
--TEST--
16.phpt: 2 row 2 column, setCaption
--FILE--
<?php
// $Id: 16.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Test';
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
$table->setCaption('Foobar', 'bgcolor="green"');
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<caption bgcolor="green">Foobar</caption>
<tr>
<td bgcolor="yellow" align="right">Test</td>
<td bgcolor="yellow" align="right">Test</td>
</tr>
<tr>
<td bgcolor="yellow" align="right">Test</td>
<td bgcolor="yellow" align="right">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,41 @@
--TEST--
17.phpt: 3 row 2 column, setCaption
--FILE--
<?php
// $Id: 17.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Test';
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[1][] = 'Test';
$data[2][] = 'Test';
$data[2][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
$table->setColType(0, 'TH');
$table->setRowType(1, 'TD');
$table->setRowType(2, 'TH');
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<th bgcolor="yellow" align="right">Test</th>
<td bgcolor="yellow" align="right">Test</td>
</tr>
<tr>
<td bgcolor="yellow" align="right">Test</td>
<td bgcolor="yellow" align="right">Test</td>
</tr>
<tr>
<th bgcolor="yellow" align="right">Test</th>
<th bgcolor="yellow" align="right">Test</th>
</tr>
</table>

View File

@@ -0,0 +1,27 @@
--TEST--
18.phpt: addCol 1 cell 2 column with no extra options
--FILE--
<?php
// $Id: 18.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][] = 'Test';
$data[0][] = 'Test';
foreach($data as $key => $value) {
$table->addCol($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,31 @@
--TEST--
19.phpt: addCol 2 cell 2 column with no extra options
--FILE--
<?php
// $Id: 19.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][] = 'Test';
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$table->addCol($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,25 @@
--TEST--
2.phpt: addRow 1 row 2 column with no extra options
--FILE--
<?php
// $Id: 2.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][] = 'Test';
$data[0][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,33 @@
--TEST--
20.phpt: addRow with indexed columns (row 0, col 3; row 1, col 2)
--FILE--
<?php
// $Id: 20.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][3] = 'Test';
$data[1][2] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Test</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Test</td>
<td>&nbsp;</td>
</tr>
</table>

View File

@@ -0,0 +1,37 @@
--TEST--
21.phpt: addCol with indexed rows (row 2, col 1; row 3, col 0)
--FILE--
<?php
// $Id: 21.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][3] = 'Test';
$data[1][2] = 'Test';
foreach($data as $key => $value) {
$table->addCol($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>&nbsp;</td>
</tr>
</table>

View File

@@ -0,0 +1,45 @@
--TEST--
22.phpt: thead, tfoot, tbody and addCol
--FILE--
<?php
// $Id: 22.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$thead =& $table->getHeader();
$tfoot =& $table->getFooter();
$tbody =& $table->getBody();
$data[0][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$thead->addCol($value);
$tfoot->addCol($value);
$tbody->addCol($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<thead>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
</thead>
<tfoot>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,41 @@
--TEST--
23.phpt: thead, tbody and addRow (tfoot not in output)
--FILE--
<?php
// $Id: 23.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$thead =& $table->getHeader();
$tbody =& $table->getBody();
$data[0][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$thead->addRow($value);
$tbody->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<thead>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</thead>
<tbody>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,65 @@
--TEST--
24.phpt: thead, tfoot, 2 tbodies (with ids) and addRow
--FILE--
<?php
// $Id: 24.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$thead =& $table->getHeader();
$tfoot =& $table->getFooter();
$tbody1 =& $table->getBody(1);
$tbody1->setAttribute('id', 'tbody1');
$tbody2 =& $table->getBody(2);
$tbody2->setAttribute('id', 'tbody2');
$data[0][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$thead->addRow($value);
$tfoot->addRow($value);
$tbody1->addRow($value);
$tbody2->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<thead>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</thead>
<tfoot>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</tfoot>
<tbody id="tbody1">
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</tbody>
<tbody id="tbody2">
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,41 @@
--TEST--
25.phpt: tbody, tfoot and addRow (thead not in output)
--FILE--
<?php
// $Id: 25.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$tbody =& $table->getBody();
$tfoot =& $table->getFooter();
$data[0][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$tbody->addRow($value);
$tfoot->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tfoot>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,69 @@
--TEST--
26.phpt: thead, tfoot, tbody with mixed function calls
--FILE--
<?php
// $Id: 26.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$thead =& $table->getHeader();
$tfoot =& $table->getFooter();
$tbody =& $table->getBody();
$thead->setHeaderContents(2, 2, 'some th content', 'bgcolor="red"');
$tfoot->setHeaderContents(1, 1, 'another th content', 'bgcolor="yellow"');
$data[0][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$tbody->addRow($value, 'bgcolor="darkblue"');
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<thead>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<th bgcolor="red">some th content</th>
</tr>
</thead>
<tfoot>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<th bgcolor="yellow">another th content</th>
<td>&nbsp;</td>
</tr>
</tfoot>
<tbody>
<tr>
<td bgcolor="darkblue">Test</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="darkblue">Test</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,82 @@
--TEST--
27.phpt: thead, tfoot, tbody with mixed function calls
--FILE--
<?php
// $Id: 27.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table(null, null, false);
$thead =& $table->getHeader();
$tfoot =& $table->getFooter();
$tbody =& $table->getBody();
$thead->setAutoFill('foo');
$tfoot->setAutoFill('bar');
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[2][] = 'Test';
foreach($data as $key => $value) {
$thead->setCellAttributes($key, $key, array('style' => 'border: 1px solid purple;'));
$tfoot->setCellContents($key, $key, 'some content', 'TH');
$tbody->addRow($value, 'bgcolor="darkblue"');
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<thead>
<tr>
<td style="border: 1px solid purple;">foo</td>
<td>foo</td>
<td>foo</td>
</tr>
<tr>
<td>foo</td>
<td style="border: 1px solid purple;">foo</td>
<td>foo</td>
</tr>
<tr>
<td>foo</td>
<td>foo</td>
<td style="border: 1px solid purple;">foo</td>
</tr>
</thead>
<tfoot>
<tr>
<th>some content</th>
<td>bar</td>
<td>bar</td>
</tr>
<tr>
<td>bar</td>
<th>some content</th>
<td>bar</td>
</tr>
<tr>
<td>bar</td>
<td>bar</td>
<th>some content</th>
</tr>
</tfoot>
<tbody>
<tr>
<td bgcolor="darkblue">Test</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="darkblue">Test</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="darkblue">Test</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,96 @@
--TEST--
28.phpt: thead, tfoot, tbody with array functionality of setCellContents()
--FILE--
<?php
// $Id: 28.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table(null, null, false);
$thead =& $table->getHeader();
$tfoot =& $table->getFooter();
$tbody =& $table->getBody();
$thead->setAutoFill('foo');
$tfoot->setAutoFill('bar');
$table->setAutoFill('[empty]');
$data = array(1 => 'row1', 'row2', 'row3');
foreach($data as $key => $value) {
$thead->setCellContents($key, 0, $value);
$tfoot->setCellContents($key, 1, $value);
$tbody->setCellContents($key, 2, $value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<thead>
<tr>
<td>foo</td>
<td>foo</td>
<td>foo</td>
</tr>
<tr>
<td>row1</td>
<td>foo</td>
<td>foo</td>
</tr>
<tr>
<td>row2</td>
<td>foo</td>
<td>foo</td>
</tr>
<tr>
<td>row3</td>
<td>foo</td>
<td>foo</td>
</tr>
</thead>
<tfoot>
<tr>
<td>bar</td>
<td>bar</td>
<td>bar</td>
</tr>
<tr>
<td>bar</td>
<td>row1</td>
<td>bar</td>
</tr>
<tr>
<td>bar</td>
<td>row2</td>
<td>bar</td>
</tr>
<tr>
<td>bar</td>
<td>row3</td>
<td>bar</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>[empty]</td>
<td>[empty]</td>
<td>[empty]</td>
</tr>
<tr>
<td>[empty]</td>
<td>[empty]</td>
<td>row1</td>
</tr>
<tr>
<td>[empty]</td>
<td>[empty]</td>
<td>row2</td>
</tr>
<tr>
<td>[empty]</td>
<td>[empty]</td>
<td>row3</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,71 @@
--TEST--
29.phpt: colgroup usage without a col tag
--FILE--
<?php
// $Id: 29.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$colgroup = '';
$attributes = 'span="3" class="group1"';
$table->setColGroup($colgroup, $attributes);
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
$data[3][] = 'Foo';
$data[3][] = 'Bar';
$data[3][] = 'Test';
$data[4][] = 'Foo';
$data[4][] = 'Bar';
$data[4][] = 'Test';
$data[5][] = 'Foo';
$data[5][] = 'Bar';
$data[5][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
echo $table->toHTML();
?>
--EXPECT--
<table>
<colgroup span="3" class="group1"></colgroup>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,31 @@
--TEST--
3.phpt: addRow 2 row 2 column with no extra options
--FILE--
<?php
// $Id: 3.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$data[0][] = 'Test';
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,75 @@
--TEST--
30.phpt: colgroup usage with col tags
--FILE--
<?php
// $Id: 30.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$colgroup = array('style="font-size: 120%;"', 'class="col2"', 'align="right"');
$attributes = 'span="3" class="group1"';
$table->setColGroup($colgroup, $attributes);
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
$data[3][] = 'Foo';
$data[3][] = 'Bar';
$data[3][] = 'Test';
$data[4][] = 'Foo';
$data[4][] = 'Bar';
$data[4][] = 'Test';
$data[5][] = 'Foo';
$data[5][] = 'Bar';
$data[5][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
echo $table->toHTML();
?>
--EXPECT--
<table>
<colgroup span="3" class="group1">
<col style="font-size: 120%;" />
<col class="col2" />
<col align="right" />
</colgroup>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,107 @@
--TEST--
29.phpt: colgroup usage with multiple colgroups
--FILE--
<?php
// $Id: 31.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table();
$colgroup = array('style="font-size:120%;"', 'class="col2"', 'align="right"');
$attributes = 'span="3" class="group1"';
$table->setColGroup($colgroup, $attributes);
$colgroup = array(array('class' => 'col4'), array('class' => 'col5'));
$attributes = 'span="2" class="group2"';
$table->setColGroup($colgroup, $attributes);
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[0][] = 'Test2';
$data[0][] = 'Test3';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[1][] = 'Test2';
$data[1][] = 'Test3';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
$data[2][] = 'Test2';
$data[2][] = 'Test3';
$data[3][] = 'Foo';
$data[3][] = 'Bar';
$data[3][] = 'Test';
$data[3][] = 'Test2';
$data[3][] = 'Test3';
$data[4][] = 'Foo';
$data[4][] = 'Bar';
$data[4][] = 'Test';
$data[4][] = 'Test2';
$data[4][] = 'Test3';
$data[5][] = 'Foo';
$data[5][] = 'Bar';
$data[5][] = 'Test';
$data[5][] = 'Test2';
$data[5][] = 'Test3';
foreach($data as $key => $value) {
$table->addRow($value);
}
echo $table->toHTML();
?>
--EXPECT--
<table>
<colgroup span="3" class="group1">
<col style="font-size:120%;" />
<col class="col2" />
<col align="right" />
</colgroup>
<colgroup span="2" class="group2">
<col class="col4" />
<col class="col5" />
</colgroup>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
<td>Test2</td>
<td>Test3</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
<td>Test2</td>
<td>Test3</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
<td>Test2</td>
<td>Test3</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
<td>Test2</td>
<td>Test3</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
<td>Test2</td>
<td>Test3</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
<td>Test</td>
<td>Test2</td>
<td>Test3</td>
</tr>
</table>

View File

@@ -0,0 +1,31 @@
--TEST--
4.phpt: 2 row 2 column with various options
--FILE--
<?php
// $Id: 4.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Test';
$data[0][] = 'Test';
$data[1][] = 'Test';
$data[1][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<td bgcolor="yellow" align="right">Test</td>
<td bgcolor="yellow" align="right">Test</td>
</tr>
<tr>
<td bgcolor="yellow" align="right">Test</td>
<td bgcolor="yellow" align="right">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,48 @@
--TEST--
5.phpt: 3 row 3 column, setColAttributes / updateColAttributes
--FILE--
<?php
// $Id: 5.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
// This overwrites attrs thus removing align="right"
$table->setColAttributes(0, 'bgcolor = "purple"');
// This updates attrs thus keeping aligh="right" but change bgcolor
$table->updateColAttributes(2, 'bgcolor = "blue"');
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="blue" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="blue" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="blue" align="right">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,72 @@
--TEST--
6.phpt: 6 row 3 column, setColAttributes / updateColAttributes (switching colors on each row)
--FILE--
<?php
// $Id: 6.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
$data[3][] = 'Foo';
$data[3][] = 'Bar';
$data[3][] = 'Test';
$data[4][] = 'Foo';
$data[4][] = 'Bar';
$data[4][] = 'Test';
$data[5][] = 'Foo';
$data[5][] = 'Bar';
$data[5][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
// This overwrites attrs thus removing align="right"
$table->setColAttributes(0, 'bgcolor = "purple"');
// This updates attrs thus keeping aligh="right" but change bgcolor
$table->updateColAttributes(2, array('bgcolor = "blue"', 'bgcolor="green"', 'bgcolor="red"'));
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="blue" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="green" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="red" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="blue" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="green" align="right">Test</td>
</tr>
<tr>
<td bgcolor="purple">Foo</td>
<td bgcolor="yellow" align="right">Bar</td>
<td bgcolor="red" align="right">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,43 @@
--TEST--
7.phpt: 3 row 3 column, getCellAttributes / getRowAttributes
--FILE--
<?php
// $Id: 7.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
// This overwrites attrs thus removing align="right"
$table->setColAttributes(0, 'bgcolor = "purple"');
// This updates attrs, change bgcolor, but in tr
$table->updateRowAttributes(2, 'bgcolor = "blue"', true);
// output
// row 2, cell 2
var_dump($table->getCellAttributes(2, 2));
var_dump($table->getRowAttributes(2));
?>
--EXPECT--
array(2) {
["bgcolor"]=>
string(6) "yellow"
["align"]=>
string(5) "right"
}
array(1) {
["bgcolor"]=>
string(4) "blue"
}

View File

@@ -0,0 +1,23 @@
--TEST--
8.phpt: testing taboffset
--FILE--
<?php
// $Id: 8.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('', 1);
$data[0][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value);
}
// output
echo $table->toHTML();
?>
--EXPECT--
<table>
<tr>
<td>Test</td>
</tr>
</table>

View File

@@ -0,0 +1,75 @@
--TEST--
9.phpt: 6 row 3 column, updateAllAttributes
--FILE--
<?php
// $Id: 9.phpt 297540 2010-04-05 19:58:39Z wiesemann $
require_once 'HTML/Table.php';
$table = new HTML_Table('width="400"');
$data[0][] = 'Foo';
$data[0][] = 'Bar';
$data[0][] = 'Test';
$data[1][] = 'Foo';
$data[1][] = 'Bar';
$data[1][] = 'Test';
$data[2][] = 'Foo';
$data[2][] = 'Bar';
$data[2][] = 'Test';
$data[3][] = 'Foo';
$data[3][] = 'Bar';
$data[3][] = 'Test';
$data[4][] = 'Foo';
$data[4][] = 'Bar';
$data[4][] = 'Test';
$data[5][] = 'Foo';
$data[5][] = 'Bar';
$data[5][] = 'Test';
foreach($data as $key => $value) {
$table->addRow($value, 'bgcolor = "yellow" align = "right"');
}
// This overwrites attrs thus removing align="right"
$table->setColAttributes(0, 'bgcolor = "pink"');
// This updates attrs thus keeping aligh="right" but change bgcolor
$table->updateColAttributes(2, array('bgcolor = "blue"', 'bgcolor="green"', 'bgcolor="red"'));
// this updates
$table->updateAllAttributes('bgcolor="pink"');
// output
echo $table->toHTML();
?>
--EXPECT--
<table width="400">
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink" align="right">Bar</td>
<td bgcolor="pink" align="right">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink" align="right">Bar</td>
<td bgcolor="pink" align="right">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink" align="right">Bar</td>
<td bgcolor="pink" align="right">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink" align="right">Bar</td>
<td bgcolor="pink" align="right">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink" align="right">Bar</td>
<td bgcolor="pink" align="right">Test</td>
</tr>
<tr>
<td bgcolor="pink">Foo</td>
<td bgcolor="pink" align="right">Bar</td>
<td bgcolor="pink" align="right">Test</td>
</tr>
</table>

View File

@@ -0,0 +1,38 @@
<?php
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Event_Dispatcher_AllTests::main');
}
require_once 'PHPUnit/Framework/TestSuite.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'DispatcherTest.php';
class Event_Dispatcher_AllTests
{
// {{{ main()
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
// }}}
// {{{ suite()
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Event Dispatcher Tests');
$suite->addTestSuite('DispatcherTest');
return $suite;
}
// }}}
}
if (PHPUnit_MAIN_METHOD == 'Event_Dispatcher_AllTests::main') {
Event_Dispatcher_AllTests::main();
}
?>

View File

@@ -0,0 +1,148 @@
<?php
// $Id: DispatcherTest.php 284686 2009-07-24 05:22:17Z clockwerx $
/**
* Unit tests for Event_Dispatcher package.
*
* @author Bertrand Mansion <bmansion@mamasam.com>
* @package Event_Dispatcher
* @subpackage Tests
*/
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'Event/Dispatcher.php';
class Notified
{
var $notif;
function notifReceived(&$notif)
{
$this->notif =& $notif;
}
function description()
{
$notObj =& $this->notif->getNotificationObject();
$name = $this->notif->getNotificationName();
$info = $this->notif->getNotificationInfo();
$desc = $name.':'.implode(':', $info).':'.$notObj->id;
return $desc;
}
}
class Dummy
{
var $id;
function Dummy($id = 'default')
{
$this->id = $id;
}
}
class Notifier
{
var $id = 'notifier';
function Notifier($id)
{
$this->id = $id;
$ed =& Event_Dispatcher::getInstance();
$ed->post($this, 'NotifierInstanciated', array('info'));
}
}
function notified(&$notif)
{
$obj = $notif->getNotificationObject();
$obj->id = $notif->getNotificationName().':'.implode(':', $notif->getNotificationInfo());
}
class DispatcherTest extends PHPUnit_Framework_TestCase
{
// Get the default dispatch center
function test1()
{
$nf = new Notified();
$dm = new Dummy();
$ed =& Event_Dispatcher::getInstance();
// Generic notification, global observer
$ed->addObserver(array(&$nf, 'notifReceived'));
$not =& $ed->post($dm, 'test', array('A', 'B'));
$this->assertEquals('test:A:B:default', $nf->description(), "Error");
$this->assertEquals(1, $not->getNotificationCount(), "Wrong notification count");
// Object references
$dm->id = 'dummy';
$this->assertEquals('test:A:B:dummy', $nf->description(), "Wrong notification description");
// Named notifications
$ed->addObserver('notified', 'NotifierInstanciated');
$nt = new Notifier('notifier');
$this->assertEquals('NotifierInstanciated:info', $nt->id, "Wrong notification id");
// Pending notifications
$not =& $ed->post($nt, 'PendingNotification');
$ed->addObserver(array(&$nf, 'notifReceived'), 'PendingNotification');
$this->assertEquals('PendingNotification::NotifierInstanciated:info', $nf->description(), "Error");
$this->assertEquals(2, $not->getNotificationCount(), "Error");
// Class filter 1
$ed->addObserver(array(&$nf, 'notifReceived'), 'ClassFilterNotification', 'Dummy');
$not =& $ed->post($nt, 'ClassFilterNotification', array('isGlobal'));
$this->assertEquals('ClassFilterNotification:isGlobal:NotifierInstanciated:info', $nf->description(), "Error");
$this->assertEquals(1, $not->getNotificationCount(), "Error");
// Remove observer
$ed->removeObserver(array(&$nf, 'notifReceived'));
$nt->id = 'reset';
$not =& $ed->post($nt, 'ClassFilterNotification', array('test'));
$this->assertEquals('ClassFilterNotification:isGlobal:reset', $nf->description(), "Error");
$this->assertEquals(0, $not->getNotificationCount(), "Error");
// Class filter 2
$not =& $ed->post($dm, 'ClassFilterNotification');
$this->assertEquals('ClassFilterNotification::dummy', $nf->description(), "Error");
$this->assertEquals(1, $not->getNotificationCount(), "Error");
// Re-add the global observer
$ed->addObserver(array(&$nf, 'notifReceived'));
$not =& $ed->post($dm, 'ClassFilterNotification');
$this->assertEquals('ClassFilterNotification::dummy', $nf->description(), "Error");
$this->assertEquals(2, $not->getNotificationCount(), "Error");
}
// Tests with 2 dispatchers
function test2()
{
$nf = new Notified();
$dm = new Dummy();
$ed2 =& Event_Dispatcher::getInstance('another');
$ed1 =& Event_Dispatcher::getInstance();
$ed2->addObserver(array(&$nf, 'notifReceived'));
$not =& $ed2->post($dm, 'test', array('A', 'B'));
$this->assertEquals('test:A:B:default', $nf->description(), "Error");
$this->assertEquals(1, $not->getNotificationCount(), "Error");
$not =& $ed1->post($dm, 'test', array('A2', 'B2'));
$this->assertEquals(1, $not->getNotificationCount(), "Error");
$not =& $ed1->post($dm, 'test', array('A2', 'B2'));
$this->assertEquals(1, $not->getNotificationCount(), "Error");
$ed2->addObserver(array(&$nf, 'notifReceived'), 'ClassFilterNotification', 'Notifier');
$not =& $ed2->post($dm, 'ClassFilterNotification');
$this->assertEquals('ClassFilterNotification::default', $nf->description(), "Error");
$this->assertEquals(1, $not->getNotificationCount(), "Error");
$ed2->addObserver(array(&$nf, 'notifReceived'), 'ClassFilterNotification', 'Dummy');
$not =& $ed2->post($dm, 'ClassFilterNotification');
$this->assertEquals(2, $not->getNotificationCount(), "Error");
}
}
?>

View File

@@ -0,0 +1,478 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: Getargs_basic_testcase.php 304307 2010-10-11 11:28:02Z jespino $
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Getargs_Basic_testCase::main');
}
require_once 'Console/Getargs.php';
require_once 'PHPUnit/Framework.php';
/**
* Unit tests for Console_Getargs package.
*/
class Getargs_Basic_testCase extends PHPUnit_Framework_TestCase
{
/**
* Runs the test methods of this class.
*
* @access public
* @static
*/
public static function main() {
require_once 'PHPUnit/TextUI/TestRunner.php';
$suite = new PHPUnit_Framework_TestSuite('Getargs_Basic_testCase');
PHPUnit_TextUI_TestRunner::run($suite);
}
function testFixed1()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'An argument.')
);
$args = array('-n', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals($args[1], $obj->getValue('n'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals($args[1], $obj->getValue('name'), "'$message' Incorrect value returned");
}
}
function testFixed2()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 2,
'max' => 2,
'desc' => 'Two arguments.')
);
$args = array('-n', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(array($args[1], $args[2]), $obj->getValue('n'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(array($args[1], $args[2]), $obj->getValue('name'), "'$message' Incorrect value returned");
}
}
function testFixed1WithDefault()
{
$config = array(
'name' => array(
'min' => 1,
'max' => 1,
'desc' => 'Fixed number with default value if not used.',
'default' => 'default1')
);
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals($args[1], $obj->getValue('name'), "'$message' Incorrect value returned");
}
$args = array();
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail($obj->getMessage());
} else {
$this->assertEquals('default1', $obj->getValue('name'), "Incorrect value returned");
}
}
function testFixed2WithDefault()
{
$config = array(
'names' => array(
'min' => 2,
'max' => 2,
'desc' => 'Fixed number with default values if not used.',
'default' => array('default1', 'default2'))
);
$args = array('--names', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(array($args[1], $args[2]), $obj->getValue('names'), "'$message' Incorrect value returned");
}
$args = array();
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail($obj->getMessage());
} else {
$this->assertEquals(array('default1', 'default2'), $obj->getValue('names'), "Incorrect value returned");
}
}
function testSwitch()
{
$config = array(
'switch' => array(
'short' => 's',
'max' => 0,
'desc' => 'A switch.')
);
$args = array('-s');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertTrue($obj->isDefined('s'), "'$message' Switch not defined");
$this->assertTrue($obj->isDefined('switch'), "'$message' Switch not defined");
}
$args = array('--switch');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertTrue($obj->isDefined('s'), "'$message' Switch not defined");
$this->assertTrue($obj->isDefined('switch'), "'$message' Switch not defined");
}
}
function testSwitchWithDefaultIfValueNotSet()
{
$config = array(
'default' => array(
'short' => 'd',
'min' => 0,
'max' => 1,
'desc' => 'A switch with a default value if no value set.',
'default' => 3)
);
$args = array('-d');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(3, $obj->getValue('d'), "'$message' Incorrect value returned");
$this->assertEquals(3, $obj->getValue('default'), "'$message' Incorrect value returned");
}
$args = array('-d', 4);
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(4, $obj->getValue('d'), "'$message' Incorrect value returned");
$this->assertEquals(4, $obj->getValue('default'), "'$message' Incorrect value returned");
}
}
function testVariable1_3()
{
$config = array(
'name' => array(
'min' => 1,
'max' => 3,
'desc' => 'One to three values.')
);
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals('arg1', $obj->getValue('name'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', 'arg2', 'arg3');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(array('arg1', 'arg2', 'arg3'), $obj->getValue('name'), "'$message' Incorrect values returned");
}
}
function testVariable1_3WithDefault()
{
// TODO : using min => 0 should maybe work too
$config = array(
'name' => array(
'min' => 1,
'max' => 3,
'desc' => 'Zero to three values using default if no values set.',
'default' => 'default1')
);
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals('arg1', $obj->getValue('name'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', 'arg2', 'arg3');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals(array('arg1', 'arg2', 'arg3'), $obj->getValue('name'), "'$message' Incorrect values returned");
}
$args = array();
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail($obj->getMessage());
} else {
$this->assertEquals('default1', $obj->getValue('name'), "'$message' Incorrect values returned");
}
}
function testNoLimit()
{
$config = array(
'name' => array(
'min' => 1,
'max' => -1,
'desc' => 'Unlimited number of values.')
);
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' ".$obj->getMessage());
} else {
$this->assertEquals('arg1', $obj->getValue('name'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', 'arg2', 'arg3');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail($obj->getMessage());
} else {
$this->assertEquals(array('arg1', 'arg2', 'arg3'), $obj->getValue('name'), "'$message' Incorrect values returned");
}
}
function testNoLimitWithDefault()
{
$config = array(
'name' => array(
'min' => 1,
'max' => -1,
'desc' => 'Unlimited number of values.',
'default' => 'default1')
);
$args = array();
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail($obj->getMessage());
} else {
$this->assertEquals('default1', $obj->getValue('name'), "Incorrect values returned");
}
}
function testAlias()
{
$config = array(
'name|alias' => array(
'short' => 'n|a',
'min' => 0,
'max' => 0,
'desc' => 'Unlimited number of values with alias.')
);
$args = array('-n', '-a', '--name', '--alias');
foreach ($args as $arg) {
$message = $arg;
$obj =& Console_Getargs::factory($config, array($arg));
if (PEAR::isError($obj)) {
$this->fail($obj->getMessage());
} else {
$this->assertTrue($obj->isDefined('name'), "Value 'name' is not defined");
$this->assertTrue($obj->isDefined('alias'), "Value 'alias' is not defined");
$this->assertTrue($obj->isDefined('n'), "Value 'n' is not defined");
$this->assertTrue($obj->isDefined('a'), "Value 'a' is not defined");
}
}
}
/**
* isDefined should return true when the parameter is passed on cmdline
*/
function testIsDefined()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'An argument.',
'default' => 'john'
)
);
$args = array('-n', 'arg1');
$obj =& Console_Getargs::factory($config, $args);
$this->assertFalse(PEAR::isError($obj));
$this->assertTrue($obj->isDefined('n'));
$this->assertTrue($obj->isDefined('name'));
}
/**
* isDefined should return true when the parameter is passed on cmdline,
* even when checking for the alias name
*/
function testIsDefinedAlias()
{
$config = array(
'name|alias' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'An argument.',
'default' => 'john'
)
);
$args = array('-n', 'arg1');
$obj =& Console_Getargs::factory($config, $args);
$this->assertFalse(PEAR::isError($obj));
$this->assertTrue($obj->isDefined('n'));
$this->assertTrue($obj->isDefined('name'));
$this->assertTrue($obj->isDefined('alias'));
}
/**
* isDefined should return false when the parameter is not
* given on cmdline - even if there is a default value
*/
function testIsDefinedDefaultOnly()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'An argument.',
'default' => 'john'
)
);
$args = array();
$obj =& Console_Getargs::factory($config, $args);
$this->assertFalse(PEAR::isError($obj));
$this->assertFalse($obj->isDefined('n'));
$this->assertFalse($obj->isDefined('name'));
}
}
if (PHPUnit_MAIN_METHOD == 'Getargs_Basic_testCase::main') {
Getargs_Basic_testCase::main();
}
?>

View File

@@ -0,0 +1,297 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* getValues Test case for Console_Getargs
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Console
* @package Console_Getargs
* @subpackage Tests
* @author Stephan Schmidt <schst@php.net>
* @copyright 1997-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Getargs_getValues_testcase.php 269139 2008-11-17 10:02:30Z clockwerx $
* @link http://pear.php.net/package/Console_Getargs
*/
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Getargs_getValues_testCase::main');
}
require_once 'Console/Getargs.php';
require_once 'PHPUnit/Framework.php';
/**
* getValues Test case for Console_Getargs
*
* @category Console
* @package Console_Getargs
* @subpackage Tests
* @author Stephan Schmidt <schst@php.net>
* @copyright 1997-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: @package_version@
* @link http://pear.php.net/package/Console_Getargs
*/
class Getargs_getValues_testCase extends PHPUnit_Framework_TestCase
{
/**
* Runs the test methods of this class.
*
* @access public
* @static
*/
public static function main() {
require_once 'PHPUnit/TextUI/TestRunner.php';
$suite = new PHPUnit_Framework_TestSuite('Getargs_getValues_testCase');
PHPUnit_TextUI_TestRunner::run($suite);
}
/**
* Test getValues('long') with one argument
*
* @access public
* @return void
*/
function testLong1()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'An argument.')
);
$args = array('-n', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('name' => 'arg1'), $obj->getValues('long'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('name' => 'arg1'), $obj->getValues('long'), "'$message' Incorrect value returned");
}
}
/**
* Test getValues('long') with one argument and two values
*
* @access public
* @return void
*/
function testLong2()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 2,
'max' => 2,
'desc' => 'Two arguments.')
);
$args = array('-n', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('name' => array('arg1', 'arg2')), $obj->getValues('long'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('name' => array('arg1', 'arg2')), $obj->getValues('long'), "'$message' Incorrect value returned");
}
}
/**
* Test getValues('short') with one argument
*
* @access public
* @return void
*/
function testShort()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'An argument.')
);
$args = array('-n', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('n' => 'arg1'), $obj->getValues('short'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('n' => 'arg1'), $obj->getValues('short'), "'$message' Incorrect value returned");
}
}
/**
* Test getValues('short') with one argument and two values
*
* @access public
* @return void
*/
function testShort2()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 2,
'max' => 2,
'desc' => 'Two arguments.')
);
$args = array('-n', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('n' => array('arg1', 'arg2')), $obj->getValues('short'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', 'arg2');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('n' => array('arg1', 'arg2')), $obj->getValues('short'), "'$message' Incorrect value returned");
}
}
/**
* Test getValues('short') and getValues('long') with a switch
*
* @access public
* @return void
*/
function testSwitch()
{
$config = array(
'switch' => array(
'short' => 's',
'max' => 0,
'desc' => 'A switch.')
);
$args = array('-s');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertTrue($obj->isDefined('s'), "'$message' Switch not defined");
$this->assertTrue($obj->isDefined('switch'), "'$message' Switch not defined");
}
$args = array('--switch');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('switch' => true), $obj->getValues('long'), "'$message' Switch not defined");
$this->assertEquals(array('s' => true), $obj->getValues('short'), "'$message' Switch not defined");
}
}
/**
* Test getValues('long') and getValues('short') with two arguments
*
* @access public
* @return void
*/
function testMultiple()
{
$config = array(
'name' => array(
'short' => 'n',
'min' => 1,
'max' => 1,
'desc' => 'One argument.'),
'email' => array(
'short' => 'e',
'min' => 2,
'max' => 2,
'desc' => 'Two arguments.'),
);
$args = array('-n', 'arg1', '-e', 'schst@php.net', 'wenz@php.net');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('name' => $args[1], 'email' => array($args[3], $args[4])), $obj->getValues('long'), "'$message' Incorrect value returned");
$this->assertEquals(array('n' => $args[1], 'e' => array($args[3], $args[4])), $obj->getValues('short'), "'$message' Incorrect value returned");
}
$args = array('--name', 'arg1', '--email', 'schst@php.net', 'wenz@php.net');
$message = implode(' ', $args);
$obj =& Console_Getargs::factory($config, $args);
if (PEAR::isError($obj)) {
$this->fail("'$message' " . $obj->getMessage());
} else {
$this->assertEquals(array('name' => $args[1], 'email' => array($args[3], $args[4])), $obj->getValues('long'), "'$message' Incorrect value returned");
$this->assertEquals(array('n' => $args[1], 'e' => array($args[3], $args[4])), $obj->getValues('short'), "'$message' Incorrect value returned");
}
}
}
if (PHPUnit_MAIN_METHOD == 'Getargs_getValues_testCase::main') {
Getargs_getValues_testCase::main();
}
?>

View File

@@ -0,0 +1,58 @@
--TEST--
File_Find bug #2773
--SKIPIF--
<?php
include(dirname(__FILE__).'/setup.php');
print $status;
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/setup.php');
$ff = new File_Find();
$result = $ff->mapTreeMultiple('File_Find/dir2') ;
$result2 = File_Find::mapTreeMultiple('File_Find/dir2') ;
print_r($result);
print_r($result2);
?>
--GET--
--POST--
--EXPECT--
Array
(
[0] => Array
(
[0] => 1.txt
)
[1] => Array
(
[0] => 1.txt
)
[2] => Array
(
[0] => 1.txt
)
)
Array
(
[0] => Array
(
[0] => 1.txt
)
[1] => Array
(
[0] => 1.txt
)
[2] => Array
(
[0] => 1.txt
)
)

View File

@@ -0,0 +1,44 @@
<?php
if (@include(dirname(__FILE__)."/../Find.php")) {
$status = '';
} else if (@include('File/Find.php')) {
$status = '';
} else {
$status = 'skip - PEAR File_Find class is not available';
return;
}
$tmpdir = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
? getenv('TMP')
: '/tmp';
chdir($tmpdir);
@mkdir('File_Find/');
@mkdir('File_Find/dir');
touch('File_Find/dir/1.txt');
touch('File_Find/dir/2.txt');
@mkdir('File_Find/dir/dir2');
touch('File_Find/dir/dir2/3.bak');
touch('File_Find/dir/dir2/3.txt');
@mkdir('File_Find/dir/dir3');
touch('File_Find/dir/dir3/4.bak');
touch('File_Find/dir/dir3/4.txt');
@mkdir('File_Find/dir/txtdir');
touch('File_Find/dir/txtdir/5.txt');
@mkdir('File_Find/dir2/');
@mkdir('File_Find/dir2/0');
touch('File_Find/dir2/0/1.txt');
@mkdir('File_Find/dir2/1');
touch('File_Find/dir2/1/1.txt');
@mkdir('File_Find/dir2/2');
touch('File_Find/dir2/2/1.txt');
?>

View File

@@ -0,0 +1,18 @@
--TEST--
XML_Util::apiVersion() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::apiVersion() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: basic apiVersion() call" . PHP_EOL;
echo XML_Util::apiVersion() . PHP_EOL;
?>
--EXPECT--
=====XML_Util::apiVersion() basic tests=====
TEST: basic apiVersion() call
1.1

View File

@@ -0,0 +1,118 @@
--TEST--
XML_Util::attributesToString() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::attributesToString() basic tests=====' . PHP_EOL . PHP_EOL;
$att = array("foo" => "bar", "boo" => "baz");
$sort1 = array(
'multiline' => true,
'indent' => '----',
'linebreak' => "^",
'entities' => XML_UTIL_ENTITIES_XML,
'sort' => true
);
$sort2 = array(
'multiline' => true,
'indent' => '----',
'linebreak' => "^",
'entities' => XML_UTIL_ENTITIES_XML,
);
echo "TEST: basic usage" . PHP_EOL;
echo XML_Util::attributesToString($att) . PHP_EOL . PHP_EOL;
echo "TEST: explicit \$sort = true" . PHP_EOL;
echo XML_Util::attributesToString($att, true) . PHP_EOL . PHP_EOL;
echo "TEST: explicit \$sort = false" . PHP_EOL;
echo XML_Util::attributesToString($att, false) . PHP_EOL . PHP_EOL;
echo "TEST: explicit \$multiline = false" . PHP_EOL;
echo XML_Util::attributesToString($att, true, false) . PHP_EOL . PHP_EOL;
echo "TEST: explicit \$multiline = true" . PHP_EOL;
echo XML_Util::attributesToString($att, true, true) . PHP_EOL . PHP_EOL;
echo "TEST: explicit \$indent = ' ' (8 spaces)" . PHP_EOL;
echo XML_Util::attributesToString($att, true, true, ' ') . PHP_EOL . PHP_EOL;
echo "TEST: explicit \$linebreak = '^' (some dummy char)" . PHP_EOL;
echo XML_Util::attributesToString($att, true, true, '^') . PHP_EOL . PHP_EOL;
echo "TEST: passing \$sort array of options that includes 'sort'" . PHP_EOL;
echo XML_Util::attributesToString($att, $sort1) . PHP_EOL . PHP_EOL;
echo "TEST: passing \$sort array of options that doesn't include 'sort'" . PHP_EOL;
echo XML_Util::attributesToString($att, $sort2) . PHP_EOL . PHP_EOL;
echo "TEST: do not replace entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
XML_UTIL_ENTITIES_NONE) . PHP_EOL . PHP_EOL;
echo "TEST: replace all XML entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
XML_UTIL_ENTITIES_XML) . PHP_EOL . PHP_EOL;
echo "TEST: replace only required XML entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
XML_UTIL_ENTITIES_XML_REQUIRED) . PHP_EOL . PHP_EOL;
echo "TEST: replace HTML entities" . PHP_EOL;
$arr = array("foo" => "b@&r", "boo" => "b><z");
echo XML_Util::attributesToString($arr, true, false, ' ', PHP_EOL,
XML_UTIL_ENTITIES_HTML) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::attributesToString() basic tests=====
TEST: basic usage
boo="baz" foo="bar"
TEST: explicit $sort = true
boo="baz" foo="bar"
TEST: explicit $sort = false
foo="bar" boo="baz"
TEST: explicit $multiline = false
boo="baz" foo="bar"
TEST: explicit $multiline = true
boo="baz"
foo="bar"
TEST: explicit $indent = ' ' (8 spaces)
boo="baz"
foo="bar"
TEST: explicit $linebreak = '^' (some dummy char)
boo="baz"
^foo="bar"
TEST: passing $sort array of options that includes 'sort'
boo="baz"
----foo="bar"
TEST: passing $sort array of options that doesn't include 'sort'
boo="baz"
----foo="bar"
TEST: do not replace entities
boo="b><z" foo="b@&r"
TEST: replace all XML entities
boo="b&gt;&lt;z" foo="b@&amp;r"
TEST: replace only required XML entities
boo="b>&lt;z" foo="b@&amp;r"
TEST: replace HTML entities
boo="b&gt;&lt;z" foo="b@&amp;r"

View File

@@ -0,0 +1,52 @@
--TEST--
XML_Util::collapseEmptyTags() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::collapseEmptyTags() basic tests=====' . PHP_EOL . PHP_EOL;
$emptyTag = "<foo></foo>";
$otherTag = "<bar>baz</bar>";
$xhtmlTag = "<b></b>";
echo "TEST: basic usage" . PHP_EOL;
echo XML_Util::collapseEmptyTags($emptyTag) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage alongside non-empty tag" . PHP_EOL;
echo XML_Util::collapseEmptyTags($emptyTag . $otherTag) . PHP_EOL . PHP_EOL;
echo "TEST: one empty tag, with COLLAPSE_ALL set" . PHP_EOL;
echo XML_Util::collapseEmptyTags($emptyTag, XML_UTIL_COLLAPSE_ALL) . PHP_EOL . PHP_EOL;
echo "TEST: one empty tag alongside non-empty tag, with COLLAPSE_ALL set" . PHP_EOL;
echo XML_Util::collapseEmptyTags($emptyTag . $otherTag, XML_UTIL_COLLAPSE_ALL) . PHP_EOL . PHP_EOL;
echo "TEST: one empty tag, with COLLAPSE_XHTML_ONLY set" . PHP_EOL;
echo XML_Util::collapseEmptyTags($emptyTag, XML_UTIL_COLLAPSE_XHTML_ONLY) . PHP_EOL . PHP_EOL;
echo "TEST: one empty tag alongside non-empty tag, with COLLAPSE_XHTML_ONLY set" . PHP_EOL;
echo XML_Util::collapseEmptyTags($emptyTag . $xhtmlTag . $otherTag, XML_UTIL_COLLAPSE_XHTML_ONLY) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::collapseEmptyTags() basic tests=====
TEST: basic usage
<foo />
TEST: basic usage alongside non-empty tag
<foo /><bar>baz</bar>
TEST: one empty tag, with COLLAPSE_ALL set
<foo />
TEST: one empty tag alongside non-empty tag, with COLLAPSE_ALL set
<foo /><bar>baz</bar>
TEST: one empty tag, with COLLAPSE_XHTML_ONLY set
<foo></foo>
TEST: one empty tag alongside non-empty tag, with COLLAPSE_XHTML_ONLY set
<foo></foo><b></b><bar>baz</bar>

View File

@@ -0,0 +1,18 @@
--TEST--
XML_Util::createCDataSection() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::createCDataSection() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: basic usage" . PHP_EOL;
echo XML_Util::createCDataSection("I am content.") . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createCDataSection() basic tests=====
TEST: basic usage
<![CDATA[I am content.]]>

View File

@@ -0,0 +1,18 @@
--TEST--
XML_Util::createComment() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::createComment() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: basic usage" . PHP_EOL;
echo XML_Util::createComment("I am comment.") . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createComment() basic tests=====
TEST: basic usage
<!-- I am comment. -->

View File

@@ -0,0 +1,24 @@
--TEST--
XML_Util::createEndElement() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::createEndElement() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: basic usage (myTag)" . PHP_EOL;
echo XML_Util::createEndElement("myTag") . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a namespaced tag (myNs:myTag)" . PHP_EOL;
echo XML_Util::createEndElement("myNs:myTag") . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createEndElement() basic tests=====
TEST: basic usage (myTag)
</myTag>
TEST: basic usage with a namespaced tag (myNs:myTag)
</myNs:myTag>

View File

@@ -0,0 +1,124 @@
--TEST--
XML_Util::createStartElement() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::createStartElement() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: tag only" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag"
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar")
) . PHP_EOL . PHP_EOL;
echo "TEST: tag only, passing '' as attribute arg" . PHP_EOL;
echo XML_Util::createStartElement(
'myNs:myTag',
''
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes and namespace" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar"),
"http://www.w3c.org/myNs#"
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with empty attributes, whose namespaceUri is not a full namespace" . PHP_EOL;
echo XML_Util::createStartElement(
'myTag',
'',
'foo'
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes, namespace, and multiline = true" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar"),
"http://www.w3c.org/myNs#",
true
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes, namespace, multiline = true, and indent = (2 spaces only)" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar"),
"http://www.w3c.org/myNs#",
true,
' '
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes, namespace, multiline = true, indent = (2 spaces only), and linebreak = '^'" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar"),
"http://www.w3c.org/myNs#",
true,
' ',
'^'
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes, namespace, multiline = true, indent = (2 spaces only), linebreak = '^', and sortAttributes = true" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar", "boo" => "baz"),
"http://www.w3c.org/myNs#",
true,
' ',
'^',
true
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attributes, namespace, multiline = true, indent = (2 spaces only), linebreak = '^', and sortAttributes = false" . PHP_EOL;
echo XML_Util::createStartElement(
"myNs:myTag",
array("foo" => "bar", "boo" => "baz"),
"http://www.w3c.org/myNs#",
true,
' ',
'^',
false
) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createStartElement() basic tests=====
TEST: tag only
<myNs:myTag>
TEST: tag with attributes
<myNs:myTag foo="bar">
TEST: tag only, passing '' as attribute arg
<myNs:myTag>
TEST: tag with attributes and namespace
<myNs:myTag foo="bar" xmlns:myNs="http://www.w3c.org/myNs#">
TEST: tag with empty attributes, whose namespaceUri is not a full namespace
<myTag xmlns="foo">
TEST: tag with attributes, namespace, and multiline = true
<myNs:myTag foo="bar"
xmlns:myNs="http://www.w3c.org/myNs#">
TEST: tag with attributes, namespace, multiline = true, and indent = (2 spaces only)
<myNs:myTag foo="bar"
xmlns:myNs="http://www.w3c.org/myNs#">
TEST: tag with attributes, namespace, multiline = true, indent = (2 spaces only), and linebreak = '^'
<myNs:myTag foo="bar"^ xmlns:myNs="http://www.w3c.org/myNs#">
TEST: tag with attributes, namespace, multiline = true, indent = (2 spaces only), linebreak = '^', and sortAttributes = true
<myNs:myTag boo="baz"^ foo="bar"^ xmlns:myNs="http://www.w3c.org/myNs#">
TEST: tag with attributes, namespace, multiline = true, indent = (2 spaces only), linebreak = '^', and sortAttributes = false
<myNs:myTag foo="bar"^ boo="baz"^ xmlns:myNs="http://www.w3c.org/myNs#">

View File

@@ -0,0 +1,155 @@
--TEST--
XML_Util::createTag() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::createTag() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar")
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute and content" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag"
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, and namespace" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag",
"http://www.w3c.org/myNs#"
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, and REPLACE_ENTITIES" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, and CDATA_SECTION" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_CDATA_SECTION
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, and multiline = false" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES,
false
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, and multiline = true" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES,
true
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, and indent = (2 spaces)" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES,
true,
' '
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, indent = (2 spaces), and linebreak = '^'" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES,
true,
' ',
'^'
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = true" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar", "boo" => "baz"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES,
true,
' ',
'^',
true
) . PHP_EOL . PHP_EOL;
echo "TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = false" . PHP_EOL;
echo XML_Util::createTag(
"myNs:myTag",
array("foo" => "bar", "boo" => "baz"),
"This is inside the tag and has < & @ > in it",
"http://www.w3c.org/myNs#",
XML_UTIL_REPLACE_ENTITIES,
true,
' ',
'^',
false
) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createTag() basic tests=====
TEST: tag with attribute
<myNs:myTag foo="bar" />
TEST: tag with attribute and content
<myNs:myTag foo="bar">This is inside the tag</myNs:myTag>
TEST: tag with attribute, content, and namespace
<myNs:myTag foo="bar" xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag</myNs:myTag>
TEST: tag with attribute, content, namespace, and REPLACE_ENTITIES
<myNs:myTag foo="bar" xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>
TEST: tag with attribute, content, namespace, and CDATA_SECTION
<myNs:myTag foo="bar" xmlns:myNs="http://www.w3c.org/myNs#"><![CDATA[This is inside the tag and has < & @ > in it]]></myNs:myTag>
TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, and multiline = false
<myNs:myTag foo="bar" xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>
TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, and multiline = true
<myNs:myTag foo="bar"
xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>
TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, and indent = (2 spaces)
<myNs:myTag foo="bar"
xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>
TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, indent = (2 spaces), and linebreak = '^'
<myNs:myTag foo="bar"^ xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>
TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = true
<myNs:myTag boo="baz"^ foo="bar"^ xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>
TEST: tag with attribute, content, namespace, REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = false
<myNs:myTag foo="bar"^ boo="baz"^ xmlns:myNs="http://www.w3c.org/myNs#">This is inside the tag and has &lt; &amp; @ &gt; in it</myNs:myTag>

View File

@@ -0,0 +1,203 @@
--TEST--
XML_Util::createTagFromArray() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::createTagFromArray() basic tests=====' . PHP_EOL . PHP_EOL;
$bad = array(
"foo" => "bar",
);
$tag1 = array(
"qname" => "foo:bar",
);
$tag2 = array(
"qname" => "foo:bar",
"namespaceUri" => "http://foo.com",
);
$tag3 = array(
"qname" => "foo:bar",
"namespaceUri" => "http://foo.com",
"attributes" => array( "key" => "value", "argh" => "fruit&vegetable" ),
);
$tag4 = array(
"qname" => "foo:bar",
"namespaceUri" => "http://foo.com",
"attributes" => array( "key" => "value", "argh" => "fruit&vegetable" ),
"content" => "I'm inside the tag",
);
$tag5 = array(
"qname" => "foo:bar",
"attributes" => array( "key" => "value", "argh" => "fruit&vegetable" ),
"content" => "I'm inside the tag",
);
$tag6 = array(
"qname" => "foo:bar",
"namespaceUri" => "http://foo.com",
"content" => "I'm inside the tag",
);
$tag7 = array(
"namespaceUri" => "http://foo.com",
"attributes" => array( "key" => "value", "argh" => "fruit&vegetable" ),
"content" => "I'm inside the tag",
);
$tag8 = array(
'content' => array('foo', 'bar')
);
$tag9 = array(
'qname' => 'foo:bar',
'namespaces' => array('ns1' => 'uri1', 'ns2' => 'uri2')
);
$tag10 = array(
'namespace' => 'http://foo.org',
'localPart' => 'bar'
);
$tag11 = array(
'namespace' => '',
'localPart' => 'bar'
);
$tag12 = array(
'localPart' => 'foo',
'namespaceUri' => 'http://bar.org'
);
echo "TEST: basic usage with an invalid array" . PHP_EOL;
echo XML_Util::createTagFromArray($bad) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname only)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag1) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname and namespaceUri)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag2) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, and attributes)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag3) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, attributes, and content)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag5) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, and content)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag6) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (namespaceUri, attributes, and content)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag7) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), plus REPLACE_ENTITIES" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), plus ENTITIES_NONE" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_ENTITIES_NONE) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, and multiline = false" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, false) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, and multiline = true" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, and indent = (2 spaces)" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true, ' ') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), and linebreak = '^'" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true, ' ', '^') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = true" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true, ' ', '^', true) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = false" . PHP_EOL;
echo XML_Util::createTagFromArray($tag4, XML_UTIL_REPLACE_ENTITIES, true, ' ', '^', false) . PHP_EOL . PHP_EOL;
echo 'TEST: cause a non-scalar error on the content tag' . PHP_EOL;
echo XML_Util::createTagFromArray($tag8) . PHP_EOL . PHP_EOL;
echo 'TEST: handle an array of namespaces being passed' . PHP_EOL;
echo XML_Util::createTagFromArray($tag9) . PHP_EOL . PHP_EOL;
echo 'TEST: qname is derived from namespace + localPart' . PHP_EOL;
echo XML_Util::createTagFromArray($tag10) . PHP_EOL . PHP_EOL;
echo 'TEST: qname is derived from localPart only' . PHP_EOL;
echo XML_Util::createTagFromArray($tag11) . PHP_EOL . PHP_EOL;
echo 'TEST: namespaceUri is given, but namespace is not' . PHP_EOL;
echo XML_Util::createTagFromArray($tag12) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::createTagFromArray() basic tests=====
TEST: basic usage with an invalid array
You must either supply a qualified name (qname) or local tag name (localPart).
TEST: basic usage with a valid array (qname only)
<foo:bar />
TEST: basic usage with a valid array (qname and namespaceUri)
<foo:bar xmlns:foo="http://foo.com" />
TEST: basic usage with a valid array (qname, namespaceUri, and attributes)
<foo:bar argh="fruit&amp;vegetable" key="value" xmlns:foo="http://foo.com" />
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content)
<foo:bar argh="fruit&amp;vegetable" key="value" xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, attributes, and content)
<foo:bar argh="fruit&amp;vegetable" key="value">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, and content)
<foo:bar xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (namespaceUri, attributes, and content)
You must either supply a qualified name (qname) or local tag name (localPart).
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), plus REPLACE_ENTITIES
<foo:bar argh="fruit&amp;vegetable" key="value" xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), plus ENTITIES_NONE
<foo:bar argh="fruit&amp;vegetable" key="value" xmlns:foo="http://foo.com">I'm inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, and multiline = false
<foo:bar argh="fruit&amp;vegetable" key="value" xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, and multiline = true
<foo:bar argh="fruit&amp;vegetable"
key="value"
xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, and indent = (2 spaces)
<foo:bar argh="fruit&amp;vegetable"
key="value"
xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), and linebreak = '^'
<foo:bar argh="fruit&amp;vegetable"^ key="value"^ xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = true
<foo:bar argh="fruit&amp;vegetable"^ key="value"^ xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: basic usage with a valid array (qname, namespaceUri, attributes, and content), REPLACE_ENTITIES, multiline = true, indent = (2 spaces), linebreak = '^', and sortAttributes = false
<foo:bar key="value"^ argh="fruit&amp;vegetable"^ xmlns:foo="http://foo.com">I&apos;m inside the tag</foo:bar>
TEST: cause a non-scalar error on the content tag
Supplied non-scalar value as tag content
TEST: handle an array of namespaces being passed
<foo:bar xmlns:ns1="uri1" xmlns:ns2="uri2" />
TEST: qname is derived from namespace + localPart
<http://foo.org:bar />
TEST: qname is derived from localPart only
<bar />
TEST: namespaceUri is given, but namespace is not
<foo xmlns="http://bar.org" />

View File

@@ -0,0 +1,44 @@
--TEST--
XML_Util::getDocTypeDeclaration() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::getDocTypeDeclaration() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: using root only" . PHP_EOL;
echo XML_Util::getDocTypeDeclaration("rootTag") . PHP_EOL . PHP_EOL;
echo "TEST: using root and a string URI" . PHP_EOL;
echo XML_Util::getDocTypeDeclaration("rootTag", "myDocType.dtd") . PHP_EOL . PHP_EOL;
$uri = array(
'uri' => 'http://pear.php.net/dtd/package-1.0',
'id' => '-//PHP//PEAR/DTD PACKAGE 0.1'
);
$dtdEntry = '<!ELEMENT additionalInfo (#PCDATA)>';
echo "TEST: using root and an array URI" . PHP_EOL;
echo XML_Util::getDocTypeDeclaration("rootTag", $uri) . PHP_EOL . PHP_EOL;
echo "TEST: using root and an array URI and an internal DTD entry" . PHP_EOL;
echo XML_Util::getDocTypeDeclaration("rootTag", $uri, $dtdEntry) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::getDocTypeDeclaration() basic tests=====
TEST: using root only
<!DOCTYPE rootTag>
TEST: using root and a string URI
<!DOCTYPE rootTag SYSTEM "myDocType.dtd">
TEST: using root and an array URI
<!DOCTYPE rootTag PUBLIC "-//PHP//PEAR/DTD PACKAGE 0.1" "http://pear.php.net/dtd/package-1.0">
TEST: using root and an array URI and an internal DTD entry
<!DOCTYPE rootTag PUBLIC "-//PHP//PEAR/DTD PACKAGE 0.1" "http://pear.php.net/dtd/package-1.0" [
<!ELEMENT additionalInfo (#PCDATA)>
]>

View File

@@ -0,0 +1,36 @@
--TEST--
XML_Util::getXmlDeclaration() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::getXmlDeclaration() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: using version only" . PHP_EOL;
echo XML_Util::getXMLDeclaration("1.0") . PHP_EOL . PHP_EOL;
echo "TEST: using version and encoding" . PHP_EOL;
echo XML_Util::getXMLDeclaration("1.0", "UTF-8") . PHP_EOL . PHP_EOL;
echo "TEST: using version, encoding, and standalone flag" . PHP_EOL;
echo XML_Util::getXMLDeclaration("1.0", "UTF-8", true) . PHP_EOL . PHP_EOL;
echo "TEST: using version and standalone flag" . PHP_EOL;
echo XML_Util::getXMLDeclaration("1.0", null, true) . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::getXmlDeclaration() basic tests=====
TEST: using version only
<?xml version="1.0"?>
TEST: using version and encoding
<?xml version="1.0" encoding="UTF-8"?>
TEST: using version, encoding, and standalone flag
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
TEST: using version and standalone flag
<?xml version="1.0" standalone="yes"?>

View File

@@ -0,0 +1,46 @@
--TEST--
XML_Util::isValidName() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::isValidName() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: valid tag" . PHP_EOL;
$result = XML_Util::isValidName("alpha-x_y_z.123");
if (is_a($result, 'PEAR_Error')) {
print "Invalid XML name: " . $result->getMessage() . PHP_EOL . PHP_EOL;
} else {
print "Valid XML name." . PHP_EOL . PHP_EOL;
}
echo "TEST: invalid tag" . PHP_EOL;
$result = XML_Util::isValidName("invalidTag?");
if (is_a($result, 'PEAR_Error')) {
print "Invalid XML name: " . $result->getMessage() . PHP_EOL . PHP_EOL;
} else {
print "Valid XML name." . PHP_EOL . PHP_EOL;
}
echo "TEST: invalid tag that doesn't start with a letter" . PHP_EOL;
$result = XML_Util::isValidName("1234five");
if (is_a($result, 'PEAR_Error')) {
print "Invalid XML name: " . $result->getMessage() . PHP_EOL . PHP_EOL;
} else {
print "Valid XML name." . PHP_EOL . PHP_EOL;
}
?>
--EXPECT--
=====XML_Util::isValidName() basic tests=====
TEST: valid tag
Valid XML name.
TEST: invalid tag
Invalid XML name: XML names may only contain alphanumeric chars, period, hyphen, colon and underscores
TEST: invalid tag that doesn't start with a letter
Invalid XML name: XML names may only start with letter or underscore

View File

@@ -0,0 +1,19 @@
--TEST--
XML_Util::raiseError() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::raiseError() basic tests=====' . PHP_EOL . PHP_EOL;
$error = XML_Util::raiseError("I am an error", 12345);
if (is_a($error, 'PEAR_Error')) {
print "PEAR Error: " . $error->getMessage() . PHP_EOL;
}
?>
--EXPECT--
=====XML_Util::raiseError() basic tests=====
PEAR Error: I am an error

View File

@@ -0,0 +1,82 @@
--TEST--
XML_Util::replaceEntities() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::replaceEntities() basic tests=====' . PHP_EOL . PHP_EOL;
$data = 'This string contains < & >.';
$utf8 = 'This data contains special chars like <, >, & and " as well as ä, ö, ß, à and ê';
echo "TEST: basic usage" . PHP_EOL;
echo XML_Util::replaceEntities($data) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage but with bogus \$replaceEntities arg" . PHP_EOL;
echo XML_Util::replaceEntities($data, 'I_AM_BOGUS') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML" . PHP_EOL;
echo XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_XML) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML and UTF-8" . PHP_EOL;
echo XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_XML, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: utf8 usage with ENTITIES_XML and UTF-8" . PHP_EOL;
echo XML_Util::replaceEntities($utf8, XML_UTIL_ENTITIES_XML, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML_REQUIRED" . PHP_EOL;
echo XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_XML_REQUIRED) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML_REQUIRED and UTF-8" . PHP_EOL;
echo XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_XML_REQUIRED, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: utf8 usage with ENTITIES_XML_REQUIRED and UTF-8" . PHP_EOL;
echo XML_Util::replaceEntities($utf8, XML_UTIL_ENTITIES_XML_REQUIRED, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_HTML" . PHP_EOL;
echo XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_HTML) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_HTML and UTF-8" . PHP_EOL;
echo XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_HTML, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: utf8 usage with ENTITIES_HTML and UTF-8" . PHP_EOL;
echo XML_Util::replaceEntities($utf8, XML_UTIL_ENTITIES_HTML, 'UTF-8') . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::replaceEntities() basic tests=====
TEST: basic usage
This string contains &lt; &amp; &gt;.
TEST: basic usage but with bogus $replaceEntities arg
This string contains < & >.
TEST: basic usage with ENTITIES_XML
This string contains &lt; &amp; &gt;.
TEST: basic usage with ENTITIES_XML and UTF-8
This string contains &lt; &amp; &gt;.
TEST: utf8 usage with ENTITIES_XML and UTF-8
This data contains special chars like &lt;, &gt;, &amp; and &quot; as well as ä, ö, ß, à and ê
TEST: basic usage with ENTITIES_XML_REQUIRED
This string contains &lt; &amp; >.
TEST: basic usage with ENTITIES_XML_REQUIRED and UTF-8
This string contains &lt; &amp; >.
TEST: utf8 usage with ENTITIES_XML_REQUIRED and UTF-8
This data contains special chars like &lt;, >, &amp; and &quot; as well as ä, ö, ß, à and ê
TEST: basic usage with ENTITIES_HTML
This string contains &lt; &amp; &gt;.
TEST: basic usage with ENTITIES_HTML and UTF-8
This string contains &lt; &amp; &gt;.
TEST: utf8 usage with ENTITIES_HTML and UTF-8
This data contains special chars like &lt;, &gt;, &amp; and &quot; as well as &auml;, &ouml;, &szlig;, &agrave; and &ecirc;

View File

@@ -0,0 +1,81 @@
--TEST--
XML_Util::reverseEntities() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::reverseEntities() basic tests=====' . PHP_EOL . PHP_EOL;
$data = 'This string contains &lt; &amp; &gt;.';
$utf8 = 'This data contains special chars like &lt;, &gt;, &amp; and &quot; as well as &auml;, &ouml;, &szlig;, &agrave; and &ecirc;';
echo "TEST: basic usage" . PHP_EOL;
echo XML_Util::reverseEntities($data) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage but with bogus \$replaceEntities arg" . PHP_EOL;
echo XML_Util::reverseEntities($data, 'I_AM_BOGUS') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML" . PHP_EOL;
echo XML_Util::reverseEntities($data, XML_UTIL_ENTITIES_XML) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML and UTF-8" . PHP_EOL;
echo XML_Util::reverseEntities($data, XML_UTIL_ENTITIES_XML, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: utf8 usage with ENTITIES_XML and UTF-8" . PHP_EOL;
echo XML_Util::reverseEntities($utf8, XML_UTIL_ENTITIES_XML, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML_REQUIRED" . PHP_EOL;
echo XML_Util::reverseEntities($data, XML_UTIL_ENTITIES_XML_REQUIRED) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_XML_REQUIRED and UTF-8" . PHP_EOL;
echo XML_Util::reverseEntities($data, XML_UTIL_ENTITIES_XML_REQUIRED, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: utf8 usage with ENTITIES_XML_REQUIRED and UTF-8" . PHP_EOL;
echo XML_Util::reverseEntities($utf8, XML_UTIL_ENTITIES_XML_REQUIRED, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_HTML" . PHP_EOL;
echo XML_Util::reverseEntities($data, XML_UTIL_ENTITIES_HTML) . PHP_EOL . PHP_EOL;
echo "TEST: basic usage with ENTITIES_HTML and UTF-8" . PHP_EOL;
echo XML_Util::reverseEntities($data, XML_UTIL_ENTITIES_HTML, 'UTF-8') . PHP_EOL . PHP_EOL;
echo "TEST: utf8 usage with ENTITIES_HTML and UTF-8" . PHP_EOL;
echo XML_Util::reverseEntities($utf8, XML_UTIL_ENTITIES_HTML, 'UTF-8') . PHP_EOL . PHP_EOL;
?>
--EXPECT--
=====XML_Util::reverseEntities() basic tests=====
TEST: basic usage
This string contains < & >.
TEST: basic usage but with bogus $replaceEntities arg
This string contains &lt; &amp; &gt;.
TEST: basic usage with ENTITIES_XML
This string contains < & >.
TEST: basic usage with ENTITIES_XML and UTF-8
This string contains < & >.
TEST: utf8 usage with ENTITIES_XML and UTF-8
This data contains special chars like <, >, & and " as well as &auml;, &ouml;, &szlig;, &agrave; and &ecirc;
TEST: basic usage with ENTITIES_XML_REQUIRED
This string contains < & &gt;.
TEST: basic usage with ENTITIES_XML_REQUIRED and UTF-8
This string contains < & &gt;.
TEST: utf8 usage with ENTITIES_XML_REQUIRED and UTF-8
This data contains special chars like <, &gt;, & and " as well as &auml;, &ouml;, &szlig;, &agrave; and &ecirc;
TEST: basic usage with ENTITIES_HTML
This string contains < & >.
TEST: basic usage with ENTITIES_HTML and UTF-8
This string contains < & >.
TEST: utf8 usage with ENTITIES_HTML and UTF-8
This data contains special chars like <, >, & and " as well as ä, ö, ß, à and ê

View File

@@ -0,0 +1,32 @@
--TEST--
XML_Util::splitQualifiedName() basic tests
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util::splitQualifiedName() basic tests=====' . PHP_EOL . PHP_EOL;
echo "TEST: basic usage without namespace" . PHP_EOL;
$return = XML_Util::splitQualifiedName("xslt:stylesheet");
echo "namespace => " . $return['namespace'] . PHP_EOL;
echo "localPart => " . $return['localPart'] . PHP_EOL;
echo PHP_EOL;
echo "TEST: basic usage with namespace" . PHP_EOL;
$return = XML_Util::splitQualifiedName("stylesheet", "myNs");
echo "namespace => " . $return['namespace'] . PHP_EOL;
echo "localPart => " . $return['localPart'] . PHP_EOL;
echo PHP_EOL;
?>
--EXPECT--
=====XML_Util::splitQualifiedName() basic tests=====
TEST: basic usage without namespace
namespace => xslt
localPart => stylesheet
TEST: basic usage with namespace
namespace => myNs
localPart => stylesheet

View File

@@ -0,0 +1,62 @@
--TEST--
XML_Util tests for Bug #18343 Entities in file names decoded during packaging
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.2a1 2014-06-03
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util tests for Bug #18343 "Entities in file names decoded during packaging"=====' . PHP_EOL . PHP_EOL;
echo "TEST: test case provided in bug report" . PHP_EOL;
$array = array(
"qname" => "install",
"attributes" => array(
"as" => "Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&s=Newsweek",
"name" => "test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&s=Newsweek",
)
);
echo "No matter what flags are given to createTagFromArray(), an attribute must *always* be at least ENTITIES_XML encoded..." . PHP_EOL . PHP_EOL;
$flags = array(
'no flag' => null,
'false' => false,
'ENTITIES_NONE' => XML_UTIL_ENTITIES_NONE,
'ENTITIES_XML' => XML_UTIL_ENTITIES_XML,
'ENTITIES_XML_REQUIRED' => XML_UTIL_ENTITIES_XML_REQUIRED,
'ENTITIES_HTML' => XML_UTIL_ENTITIES_HTML,
'REPLACE_ENTITIES' => XML_UTIL_REPLACE_ENTITIES,
);
foreach ($flags as $flagKey => $flagValue) {
echo "Testing with $flagKey:" . PHP_EOL;
echo XML_Util::createTagFromArray($array, $flagValue) . PHP_EOL . PHP_EOL;
}
?>
--EXPECT--
=====XML_Util tests for Bug #18343 "Entities in file names decoded during packaging"=====
TEST: test case provided in bug report
No matter what flags are given to createTagFromArray(), an attribute must *always* be at least ENTITIES_XML encoded...
Testing with no flag:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />
Testing with false:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />
Testing with ENTITIES_NONE:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />
Testing with ENTITIES_XML:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />
Testing with ENTITIES_XML_REQUIRED:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />
Testing with ENTITIES_HTML:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />
Testing with REPLACE_ENTITIES:
<install as="Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" name="test/Horde/Feed/fixtures/lexicon/http-p.moreover.com-cgi-local-page%2Fo=rss&amp;s=Newsweek" />

View File

@@ -0,0 +1,21 @@
--TEST--
XML_Util tests for Bug #4950 "Incorrect CDATA serializing"
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util tests for Bug #4950 "Incorrect CDATA serializing"=====' . PHP_EOL . PHP_EOL;
echo "TEST: test case provided in bug report" . PHP_EOL;
echo XML_Util::createTag("test", array(), "Content ]]></test> here!",
null, XML_UTIL_CDATA_SECTION) . PHP_EOL;
?>
--EXPECT--
=====XML_Util tests for Bug #4950 "Incorrect CDATA serializing"=====
TEST: test case provided in bug report
<test><![CDATA[Content ]]]]><![CDATA[></test> here!]]></test>

View File

@@ -0,0 +1,27 @@
--TEST--
XML_Util tests for Bug #5392 "encoding of ISO-8859-1 is the only supported encoding"
--CREDITS--
Chuck Burgess <ashnazg@php.net>
# created for v1.2.0a1 2008-05-04
--FILE--
<?php
require_once 'XML' . DIRECTORY_SEPARATOR . 'Util.php';
echo '=====XML_Util tests for Bug #5392 "encoding of ISO-8859-1 is the only supported encoding"=====' . PHP_EOL . PHP_EOL;
echo "TEST: test case provided in bug report" . PHP_EOL;
$data = 'This data contains special chars like <, >, & and " as well as ä, ö, ß, à and ê';
$replaced = XML_Util::replaceEntities($data, XML_UTIL_ENTITIES_HTML, 'UTF-8');
$reversed = XML_Util::reverseEntities($replaced, XML_UTIL_ENTITIES_HTML, 'UTF-8');
echo $replaced . PHP_EOL;
echo $reversed . PHP_EOL;
?>
--EXPECT--
=====XML_Util tests for Bug #5392 "encoding of ISO-8859-1 is the only supported encoding"=====
TEST: test case provided in bug report
This data contains special chars like &lt;, &gt;, &amp; and &quot; as well as &auml;, &ouml;, &szlig;, &agrave; and &ecirc;
This data contains special chars like <, >, & and " as well as ä, ö, ß, à and ê