cvs: php-src /ext/zip/tests oo_extract.phpt oo_getcomment.phpt oo_getnameindex.phpt oo_setcomment.phpt oo_stream.phpt utils.inc zip_entry_read.phpt
| From: | Pierre-Alain Joye | Date: | Mon, 30 Oct 2006 17:43:22 +0000 |
| Subject: | cvs: php-src /ext/zip/tests oo_extract.phpt oo_getcomment.phpt oo_getnameindex.phpt oo_setcomment.phpt oo_stream.phpt utils.inc zip_entry_read.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-41251@lists.php.net to get a copy of this message | ||
pajoye Mon Oct 30 17:43:22 2006 UTC
Added files:
/php-src/ext/zip/tests oo_extract.phpt oo_getcomment.phpt
oo_getnameindex.phpt oo_setcomment.phpt
oo_stream.phpt
Modified files:
/php-src/ext/zip/tests utils.inc zip_entry_read.phpt
Log:
- add tests for extractTo, set/getComment and stream and zip_entry_close
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/utils.inc?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/zip/tests/utils.inc diff -u php-src/ext/zip/tests/utils.inc:1.1 php-src/ext/zip/tests/utils.inc:1.2 --- php-src/ext/zip/tests/utils.inc:1.1 Mon Oct 2 14:17:42 2006 +++ php-src/ext/zip/tests/utils.inc Mon Oct 30 17:43:21 2006 @@ -1,8 +1,25 @@ <?php -/* $Id: utils.inc,v 1.1 2006/10/02 14:17:42 bjori Exp $ */ +/* $Id: utils.inc,v 1.2 2006/10/30 17:43:21 pajoye Exp $ */ function dump_entries_name($z) { for($i=0; $i<$z->numFiles; $i++) { $sb = $z->statIndex($i); echo $i . ' ' . $sb['name'] . "\n"; } } + +/* recursively remove a directoryy */ +function rmdir_rf($dir) { + if ($handle = opendir($dir)) { + while (false !== ($item = readdir($handle))) { + if ($item != "." && $item != "..") { + if (is_dir($dir . '/' . $item)) { + rmdir_rf($dir . '/' . $item); + } else { + unlink($dir . '/' . $item); + } + } + } + closedir($handle); + rmdir($dir); + } +} http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/zip_entry_read.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/zip/tests/zip_entry_read.phpt diff -u php-src/ext/zip/tests/zip_entry_read.phpt:1.1 php-src/ext/zip/tests/zip_entry_read.phpt:1.2 --- php-src/ext/zip/tests/zip_entry_read.phpt:1.1 Mon Jul 24 16:58:58 2006 +++ php-src/ext/zip/tests/zip_entry_read.phpt Mon Oct 30 17:43:21 2006 @@ -2,7 +2,7 @@ zip_entry_read() function --SKIPIF-- <?php -/* $Id: zip_entry_read.phpt,v 1.1 2006/07/24 16:58:58 pajoye Exp $ */ +/* $Id: zip_entry_read.phpt,v 1.2 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- @@ -11,6 +11,7 @@ $entry = zip_read($zip); if (!zip_entry_open($zip, $entry, "r")) die("Failure"); echo zip_entry_read($entry); +zip_entry_close($entry); zip_close($zip); ?> http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_extract.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_extract.phpt +++ php-src/ext/zip/tests/oo_extract.phpt --TEST-- extractTo --SKIPIF-- <?php /* $Id: oo_extract.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; $file = $dirname . 'test_with_comment.zip'; include $dirname . 'utils.inc'; $zip = new ZipArchive; if (!$zip->open($file)) { exit('failed'); } $zip->extractTo($dirname . '__oo_extract_tmp'); if (!is_dir($dirname . '__oo_extract_tmp')) { echo "failed. mkdir\n"; } if (!is_dir($dirname .'__oo_extract_tmp/foobar')) { echo "failed. mkdir foobar\n"; } if (!file_exists($dirname . '__oo_extract_tmp/foobar/baz')) { echo "failed. mkdir foobar\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/foobar/baz') . "\n"; } if (!file_exists($dirname . '__oo_extract_tmp/bar')) { echo "failed. bar file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n"; } if (!file_exists($dirname . '__oo_extract_tmp/foo')) { echo "failed. foo file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n"; } /* extract one file */ $zip->extractTo($dirname . '__oo_extract_tmp', 'bar'); if (!file_exists($dirname . '__oo_extract_tmp/bar')) { echo "failed. extract bar file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n"; } /* extract two files */ $zip->extractTo($dirname . '__oo_extract_tmp', array('bar','foo')); if (!file_exists($dirname . '__oo_extract_tmp/bar')) { echo "failed. extract bar file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n"; } if (!file_exists($dirname . '__oo_extract_tmp/foo')) { echo "failed. extract foo file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n"; } rmdir_rf($dirname . '__oo_extract_tmp'); ?> --EXPECTF-- blabla laber rababer sülz bar foo bar bar foo http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_getcomment.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_getcomment.phpt +++ php-src/ext/zip/tests/oo_getcomment.phpt --TEST-- getComment --SKIPIF-- <?php /* $Id: oo_getcomment.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; $file = $dirname . 'test_with_comment.zip'; include $dirname . 'utils.inc'; $zip = new ZipArchive; if (!$zip->open($file)) { exit('failed'); } echo $zip->getArchiveComment() . "\n"; $idx = $zip->locateName('foo'); echo $zip->getCommentName('foo') . "\n"; echo $zip->getCommentIndex($idx); echo $zip->getCommentName('') . "\n"; echo $zip->getCommentName() . "\n"; $zip->close(); ?> --EXPECTF-- Zip archive comment foo comment foo comment Notice: ZipArchive::getCommentName(): Empty string as entry name in %s on line %d Warning: ZipArchive::getCommentName() expects at least 1 parameter, 0 given in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_getnameindex.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_getnameindex.phpt +++ php-src/ext/zip/tests/oo_getnameindex.phpt --TEST-- getNameIndex --SKIPIF-- <?php /* $Id: oo_getnameindex.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; include $dirname . 'utils.inc'; $file = $dirname . '__tmp_oo_rename.zip'; @unlink($file); $zip = new ZipArchive; if (!$zip->open($file, ZIPARCHIVE::CREATE)) { exit('failed'); } $zip->addFromString('entry1.txt', 'entry #1'); $zip->addFromString('entry2.txt', 'entry #2'); $zip->addFromString('dir/entry2d.txt', 'entry #2'); if (!$zip->status == ZIPARCHIVE::ER_OK) { echo "failed to write zip\n"; } $zip->close(); if (!$zip->open($file)) { exit('failed'); } var_dump($zip->getNameIndex(0)); var_dump($zip->getNameIndex(1)); var_dump($zip->getNameIndex(2)); var_dump($zip->getNameIndex(3)); $zip->close(); ?> --EXPECTF-- string(10) "entry1.txt" string(10) "entry2.txt" string(15) "dir/entry2d.txt" bool(false) http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_setcomment.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_setcomment.phpt +++ php-src/ext/zip/tests/oo_setcomment.phpt --TEST-- setComment --SKIPIF-- <?php /* $Id: oo_setcomment.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; include $dirname . 'utils.inc'; $file = $dirname . '__tmp_oo_set_comment.zip'; @unlink($file); $zip = new ZipArchive; if (!$zip->open($file, ZIPARCHIVE::CREATE)) { exit('failed'); } $zip->addFromString('entry1.txt', 'entry #1'); $zip->addFromString('entry2.txt', 'entry #2'); $zip->addFromString('dir/entry2d.txt', 'entry #2'); $zip->addFromString('entry4.txt', 'entry #1'); $zip->addFromString('entry5.txt', 'entry #2'); var_dump($zip->setCommentName('entry1.txt', 'entry1.txt')); var_dump($zip->setCommentName('entry2.txt', 'entry2.txt')); var_dump($zip->setCommentName('dir/entry2d.txt', 'dir/entry2d.txt')); var_dump($zip->setArchiveComment('archive')); var_dump($zip->setCommentIndex(3, 'entry4.txt')); var_dump($zip->setCommentIndex(4, 'entry5.txt')); var_dump($zip->setArchiveComment('archive')); if (!$zip->status == ZIPARCHIVE::ER_OK) { echo "failed to write zip\n"; } $zip->close(); if (!$zip->open($file)) { @unlink($file); exit('failed'); } var_dump($zip->getCommentIndex(0)); var_dump($zip->getCommentIndex(1)); var_dump($zip->getCommentIndex(2)); var_dump($zip->getCommentIndex(3)); var_dump($zip->getCommentIndex(4)); var_dump($zip->getArchiveComment()); $zip->close(); @unlink($file); ?> --EXPECTF-- bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) string(10) "entry1.txt" string(10) "entry2.txt" string(15) "dir/entry2d.txt" string(10) "entry4.txt" string(10) "entry5.txt" string(7) "archive" http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_stream.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_stream.phpt +++ php-src/ext/zip/tests/oo_stream.phpt --TEST-- getStream --SKIPIF-- <?php /* $Id: oo_stream.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; $file = $dirname . 'test_with_comment.zip'; include $dirname . 'utils.inc'; $zip = new ZipArchive; if (!$zip->open($file)) { exit('failed'); } $fp = $zip->getStream('foo'); var_dump($fp); if(!$fp) exit("\n"); $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 255); } fclose($fp); $zip->close(); var_dump($contents); $fp = fopen('zip://' . dirname(__FILE__) . '/test_with_comment.zip#foo', 'rb'); if (!$fp) { exit("cannot open\n"); } $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 2); } var_dump($contents); fclose($fp); ?> --EXPECTF-- resource(%d) of type (stream) string(5) "foo " string(5) "foo "
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/utils.inc?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/zip/tests/utils.inc diff -u php-src/ext/zip/tests/utils.inc:1.1 php-src/ext/zip/tests/utils.inc:1.2 --- php-src/ext/zip/tests/utils.inc:1.1 Mon Oct 2 14:17:42 2006 +++ php-src/ext/zip/tests/utils.inc Mon Oct 30 17:43:21 2006 @@ -1,8 +1,25 @@ <?php -/* $Id: utils.inc,v 1.1 2006/10/02 14:17:42 bjori Exp $ */ +/* $Id: utils.inc,v 1.2 2006/10/30 17:43:21 pajoye Exp $ */ function dump_entries_name($z) { for($i=0; $i<$z->numFiles; $i++) { $sb = $z->statIndex($i); echo $i . ' ' . $sb['name'] . "\n"; } } + +/* recursively remove a directoryy */ +function rmdir_rf($dir) { + if ($handle = opendir($dir)) { + while (false !== ($item = readdir($handle))) { + if ($item != "." && $item != "..") { + if (is_dir($dir . '/' . $item)) { + rmdir_rf($dir . '/' . $item); + } else { + unlink($dir . '/' . $item); + } + } + } + closedir($handle); + rmdir($dir); + } +} http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/zip_entry_read.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/zip/tests/zip_entry_read.phpt diff -u php-src/ext/zip/tests/zip_entry_read.phpt:1.1 php-src/ext/zip/tests/zip_entry_read.phpt:1.2 --- php-src/ext/zip/tests/zip_entry_read.phpt:1.1 Mon Jul 24 16:58:58 2006 +++ php-src/ext/zip/tests/zip_entry_read.phpt Mon Oct 30 17:43:21 2006 @@ -2,7 +2,7 @@ zip_entry_read() function --SKIPIF-- <?php -/* $Id: zip_entry_read.phpt,v 1.1 2006/07/24 16:58:58 pajoye Exp $ */ +/* $Id: zip_entry_read.phpt,v 1.2 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- @@ -11,6 +11,7 @@ $entry = zip_read($zip); if (!zip_entry_open($zip, $entry, "r")) die("Failure"); echo zip_entry_read($entry); +zip_entry_close($entry); zip_close($zip); ?> http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_extract.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_extract.phpt +++ php-src/ext/zip/tests/oo_extract.phpt --TEST-- extractTo --SKIPIF-- <?php /* $Id: oo_extract.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; $file = $dirname . 'test_with_comment.zip'; include $dirname . 'utils.inc'; $zip = new ZipArchive; if (!$zip->open($file)) { exit('failed'); } $zip->extractTo($dirname . '__oo_extract_tmp'); if (!is_dir($dirname . '__oo_extract_tmp')) { echo "failed. mkdir\n"; } if (!is_dir($dirname .'__oo_extract_tmp/foobar')) { echo "failed. mkdir foobar\n"; } if (!file_exists($dirname . '__oo_extract_tmp/foobar/baz')) { echo "failed. mkdir foobar\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/foobar/baz') . "\n"; } if (!file_exists($dirname . '__oo_extract_tmp/bar')) { echo "failed. bar file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n"; } if (!file_exists($dirname . '__oo_extract_tmp/foo')) { echo "failed. foo file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n"; } /* extract one file */ $zip->extractTo($dirname . '__oo_extract_tmp', 'bar'); if (!file_exists($dirname . '__oo_extract_tmp/bar')) { echo "failed. extract bar file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n"; } /* extract two files */ $zip->extractTo($dirname . '__oo_extract_tmp', array('bar','foo')); if (!file_exists($dirname . '__oo_extract_tmp/bar')) { echo "failed. extract bar file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n"; } if (!file_exists($dirname . '__oo_extract_tmp/foo')) { echo "failed. extract foo file\n"; } else { echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n"; } rmdir_rf($dirname . '__oo_extract_tmp'); ?> --EXPECTF-- blabla laber rababer sülz bar foo bar bar foo http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_getcomment.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_getcomment.phpt +++ php-src/ext/zip/tests/oo_getcomment.phpt --TEST-- getComment --SKIPIF-- <?php /* $Id: oo_getcomment.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; $file = $dirname . 'test_with_comment.zip'; include $dirname . 'utils.inc'; $zip = new ZipArchive; if (!$zip->open($file)) { exit('failed'); } echo $zip->getArchiveComment() . "\n"; $idx = $zip->locateName('foo'); echo $zip->getCommentName('foo') . "\n"; echo $zip->getCommentIndex($idx); echo $zip->getCommentName('') . "\n"; echo $zip->getCommentName() . "\n"; $zip->close(); ?> --EXPECTF-- Zip archive comment foo comment foo comment Notice: ZipArchive::getCommentName(): Empty string as entry name in %s on line %d Warning: ZipArchive::getCommentName() expects at least 1 parameter, 0 given in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_getnameindex.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_getnameindex.phpt +++ php-src/ext/zip/tests/oo_getnameindex.phpt --TEST-- getNameIndex --SKIPIF-- <?php /* $Id: oo_getnameindex.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; include $dirname . 'utils.inc'; $file = $dirname . '__tmp_oo_rename.zip'; @unlink($file); $zip = new ZipArchive; if (!$zip->open($file, ZIPARCHIVE::CREATE)) { exit('failed'); } $zip->addFromString('entry1.txt', 'entry #1'); $zip->addFromString('entry2.txt', 'entry #2'); $zip->addFromString('dir/entry2d.txt', 'entry #2'); if (!$zip->status == ZIPARCHIVE::ER_OK) { echo "failed to write zip\n"; } $zip->close(); if (!$zip->open($file)) { exit('failed'); } var_dump($zip->getNameIndex(0)); var_dump($zip->getNameIndex(1)); var_dump($zip->getNameIndex(2)); var_dump($zip->getNameIndex(3)); $zip->close(); ?> --EXPECTF-- string(10) "entry1.txt" string(10) "entry2.txt" string(15) "dir/entry2d.txt" bool(false) http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_setcomment.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_setcomment.phpt +++ php-src/ext/zip/tests/oo_setcomment.phpt --TEST-- setComment --SKIPIF-- <?php /* $Id: oo_setcomment.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; include $dirname . 'utils.inc'; $file = $dirname . '__tmp_oo_set_comment.zip'; @unlink($file); $zip = new ZipArchive; if (!$zip->open($file, ZIPARCHIVE::CREATE)) { exit('failed'); } $zip->addFromString('entry1.txt', 'entry #1'); $zip->addFromString('entry2.txt', 'entry #2'); $zip->addFromString('dir/entry2d.txt', 'entry #2'); $zip->addFromString('entry4.txt', 'entry #1'); $zip->addFromString('entry5.txt', 'entry #2'); var_dump($zip->setCommentName('entry1.txt', 'entry1.txt')); var_dump($zip->setCommentName('entry2.txt', 'entry2.txt')); var_dump($zip->setCommentName('dir/entry2d.txt', 'dir/entry2d.txt')); var_dump($zip->setArchiveComment('archive')); var_dump($zip->setCommentIndex(3, 'entry4.txt')); var_dump($zip->setCommentIndex(4, 'entry5.txt')); var_dump($zip->setArchiveComment('archive')); if (!$zip->status == ZIPARCHIVE::ER_OK) { echo "failed to write zip\n"; } $zip->close(); if (!$zip->open($file)) { @unlink($file); exit('failed'); } var_dump($zip->getCommentIndex(0)); var_dump($zip->getCommentIndex(1)); var_dump($zip->getCommentIndex(2)); var_dump($zip->getCommentIndex(3)); var_dump($zip->getCommentIndex(4)); var_dump($zip->getArchiveComment()); $zip->close(); @unlink($file); ?> --EXPECTF-- bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) string(10) "entry1.txt" string(10) "entry2.txt" string(15) "dir/entry2d.txt" string(10) "entry4.txt" string(10) "entry5.txt" string(7) "archive" http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/oo_stream.phpt?view=markup&rev=1.1 Index: php-src/ext/zip/tests/oo_stream.phpt +++ php-src/ext/zip/tests/oo_stream.phpt --TEST-- getStream --SKIPIF-- <?php /* $Id: oo_stream.phpt,v 1.1 2006/10/30 17:43:21 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- <?php $dirname = dirname(__FILE__) . '/'; $file = $dirname . 'test_with_comment.zip'; include $dirname . 'utils.inc'; $zip = new ZipArchive; if (!$zip->open($file)) { exit('failed'); } $fp = $zip->getStream('foo'); var_dump($fp); if(!$fp) exit("\n"); $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 255); } fclose($fp); $zip->close(); var_dump($contents); $fp = fopen('zip://' . dirname(__FILE__) . '/test_with_comment.zip#foo', 'rb'); if (!$fp) { exit("cannot open\n"); } $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 2); } var_dump($contents); fclose($fp); ?> --EXPECTF-- resource(%d) of type (stream) string(5) "foo " string(5) "foo "