diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /ext/zip/tests | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'ext/zip/tests')
| -rw-r--r-- | ext/zip/tests/bug40228.phpt | 23 | ||||
| -rw-r--r-- | ext/zip/tests/bug40228.zip | bin | 0 -> 274 bytes | |||
| -rw-r--r-- | ext/zip/tests/oo_addemptydir.phpt | 36 | ||||
| -rw-r--r-- | ext/zip/tests/oo_extract.phpt | 95 | ||||
| -rw-r--r-- | ext/zip/tests/oo_getcomment.phpt | 36 | ||||
| -rw-r--r-- | ext/zip/tests/oo_getnameindex.phpt | 47 | ||||
| -rw-r--r-- | ext/zip/tests/oo_setcomment.phpt | 71 | ||||
| -rw-r--r-- | ext/zip/tests/oo_stream.phpt | 50 | ||||
| -rw-r--r-- | ext/zip/tests/test_with_comment.zip | bin | 0 -> 571 bytes | |||
| -rw-r--r-- | ext/zip/tests/utils.inc | 18 | ||||
| -rw-r--r-- | ext/zip/tests/zip_entry_open.phpt | 3 | ||||
| -rw-r--r-- | ext/zip/tests/zip_entry_read.phpt | 3 |
12 files changed, 379 insertions, 3 deletions
diff --git a/ext/zip/tests/bug40228.phpt b/ext/zip/tests/bug40228.phpt new file mode 100644 index 000000000..fec296363 --- /dev/null +++ b/ext/zip/tests/bug40228.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #40228 (extractTo does not create recursive empty path) +--SKIPIF-- +<?php if (!extension_loaded("zip")) print "skip"; ?> +--FILE-- +<?php +$dest = dirname(__FILE__); +$arc_name = $dest . "/bug40228.zip"; +$zip = new ZipArchive; +$zip->open($arc_name, ZIPARCHIVE::CREATE);; +$zip->extractTo($dest); +if (is_dir($dest . '/test/empty')) { + echo "Ok\n"; + rmdir($dest . '/test/empty'); + rmdir($dest . '/test'); +} else { + echo "Failed.\n"; +} +echo "Done\n"; +?> +--EXPECT-- +Ok +Done diff --git a/ext/zip/tests/bug40228.zip b/ext/zip/tests/bug40228.zip Binary files differnew file mode 100644 index 000000000..bbcd9515f --- /dev/null +++ b/ext/zip/tests/bug40228.zip diff --git a/ext/zip/tests/oo_addemptydir.phpt b/ext/zip/tests/oo_addemptydir.phpt new file mode 100644 index 000000000..0252c6dc8 --- /dev/null +++ b/ext/zip/tests/oo_addemptydir.phpt @@ -0,0 +1,36 @@ +--TEST-- +ziparchive::addEmptyDir +--SKIPIF-- +<?php +/* $Id: oo_addemptydir.phpt,v 1.1.2.2 2006/11/03 16:46:19 pajoye Exp $ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +$dirname = dirname(__FILE__) . '/'; +include $dirname . 'utils.inc'; +$file = $dirname . '__tmp_oo_addfile.zip'; + +copy($dirname . 'test.zip', $file); + +$zip = new ZipArchive; +if (!$zip->open($file)) { + exit('failed'); +} + +$zip->addEmptyDir('emptydir'); +if ($zip->status == ZIPARCHIVE::ER_OK) { + dump_entries_name($zip); + $zip->close(); +} else { + echo "failed\n"; +} +@unlink($file); +?> +--EXPECTF-- +0 bar +1 foobar/ +2 foobar/baz +3 entry1.txt +4 emptydir/ diff --git a/ext/zip/tests/oo_extract.phpt b/ext/zip/tests/oo_extract.phpt new file mode 100644 index 000000000..56f288248 --- /dev/null +++ b/ext/zip/tests/oo_extract.phpt @@ -0,0 +1,95 @@ +--TEST-- +extractTo +--SKIPIF-- +<?php +/* $Id: oo_extract.phpt,v 1.2.2.2 2006/11/03 16:46:19 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) !== TRUE) { + echo "open failed.\n"; + 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. extract foobar/baz\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 +--UEXPECTF-- +blabla laber rababer sülz + +bar + +foo + + +bar + +bar + +foo diff --git a/ext/zip/tests/oo_getcomment.phpt b/ext/zip/tests/oo_getcomment.phpt new file mode 100644 index 000000000..b9bc28933 --- /dev/null +++ b/ext/zip/tests/oo_getcomment.phpt @@ -0,0 +1,36 @@ +--TEST-- +getComment +--SKIPIF-- +<?php +/* $Id: oo_getcomment.phpt,v 1.1.2.3 2007/03/14 11:02:29 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 diff --git a/ext/zip/tests/oo_getnameindex.phpt b/ext/zip/tests/oo_getnameindex.phpt new file mode 100644 index 000000000..bf2d4c67a --- /dev/null +++ b/ext/zip/tests/oo_getnameindex.phpt @@ -0,0 +1,47 @@ +--TEST-- +getNameIndex +--SKIPIF-- +<?php +/* $Id: oo_getnameindex.phpt,v 1.1.2.2 2006/11/03 16:46:19 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) diff --git a/ext/zip/tests/oo_setcomment.phpt b/ext/zip/tests/oo_setcomment.phpt new file mode 100644 index 000000000..f0dcf35c3 --- /dev/null +++ b/ext/zip/tests/oo_setcomment.phpt @@ -0,0 +1,71 @@ +--TEST-- +setComment +--SKIPIF-- +<?php +/* $Id: oo_setcomment.phpt,v 1.1.2.2 2006/11/03 16:46:19 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" diff --git a/ext/zip/tests/oo_stream.phpt b/ext/zip/tests/oo_stream.phpt new file mode 100644 index 000000000..c7f5b0d82 --- /dev/null +++ b/ext/zip/tests/oo_stream.phpt @@ -0,0 +1,50 @@ +--TEST-- +getStream +--SKIPIF-- +<?php +/* $Id: oo_stream.phpt,v 1.2.2.2 2006/11/03 16:46:19 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 + +" diff --git a/ext/zip/tests/test_with_comment.zip b/ext/zip/tests/test_with_comment.zip Binary files differnew file mode 100644 index 000000000..d68f76157 --- /dev/null +++ b/ext/zip/tests/test_with_comment.zip diff --git a/ext/zip/tests/utils.inc b/ext/zip/tests/utils.inc index 7a8b5a122..a03db17ae 100644 --- a/ext/zip/tests/utils.inc +++ b/ext/zip/tests/utils.inc @@ -1,8 +1,24 @@ <?php -/* $Id: utils.inc,v 1.1.2.2 2006/10/02 14:17:47 bjori Exp $ */ +/* $Id: utils.inc,v 1.1.2.3 2006/11/03 16:46:19 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); + } +} diff --git a/ext/zip/tests/zip_entry_open.phpt b/ext/zip/tests/zip_entry_open.phpt index 4e0100357..280cb1557 100644 --- a/ext/zip/tests/zip_entry_open.phpt +++ b/ext/zip/tests/zip_entry_open.phpt @@ -2,7 +2,7 @@ zip_entry_open() function --SKIPIF-- <?php -/* $Id: zip_entry_open.phpt,v 1.1 2006/07/24 16:58:58 pajoye Exp $ */ +/* $Id: zip_entry_open.phpt,v 1.1.2.1 2006/11/03 16:46:19 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- @@ -10,6 +10,7 @@ if(!extension_loaded('zip')) die('skip'); $zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); $entry = zip_read($zip); echo zip_entry_open($zip, $entry, "r") ? "OK" : "Failure"; +zip_entry_close($entry); zip_close($zip); ?> diff --git a/ext/zip/tests/zip_entry_read.phpt b/ext/zip/tests/zip_entry_read.phpt index f72b5e2cb..1dc1eeb45 100644 --- a/ext/zip/tests/zip_entry_read.phpt +++ b/ext/zip/tests/zip_entry_read.phpt @@ -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.1.2.1 2006/11/03 16:46:19 pajoye Exp $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- @@ -11,6 +11,7 @@ $zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); $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); ?> |
