diff options
Diffstat (limited to 'ext/zip/tests')
55 files changed, 1681 insertions, 0 deletions
diff --git a/ext/zip/tests/001.phpt b/ext/zip/tests/001.phpt new file mode 100644 index 0000000..37dccc0 --- /dev/null +++ b/ext/zip/tests/001.phpt @@ -0,0 +1,12 @@ +--TEST-- +Check for zip presence +--SKIPIF-- +<?php if (!extension_loaded("zip")) print "skip"; ?> +--POST-- +--GET-- +--FILE-- +<?php +echo "zip extension is available"; +?> +--EXPECT-- +zip extension is available diff --git a/ext/zip/tests/binarynull.zip b/ext/zip/tests/binarynull.zip Binary files differnew file mode 100644 index 0000000..9da004e --- /dev/null +++ b/ext/zip/tests/binarynull.zip diff --git a/ext/zip/tests/bug11216.phpt b/ext/zip/tests/bug11216.phpt new file mode 100644 index 0000000..7601e6a --- /dev/null +++ b/ext/zip/tests/bug11216.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #11216 (::addEmptyDir() crashes when the directory already exists) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); + ?> +--FILE-- +<?php +$archive = new ZipArchive(); +$archive->open('__test.zip', ZIPARCHIVE::CREATE); +var_dump($archive->addEmptyDir('test')); +print_r($archive); +var_dump($archive->addEmptyDir('test')); +$archive->close(); +unlink('__test.zip'); +?> +--EXPECTF-- +bool(true) +ZipArchive Object +( + [status] => 0 + [statusSys] => 0 + [numFiles] => 1 + [filename] => %s + [comment] => +) +bool(false) diff --git a/ext/zip/tests/bug14962.phpt b/ext/zip/tests/bug14962.phpt new file mode 100644 index 0000000..0006fd4 --- /dev/null +++ b/ext/zip/tests/bug14962.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #14962 (::extractTo second argument is not really optional) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +$dir = dirname(__FILE__); +$file = '__tmp14962.txt'; +$fullpath = $dir . '/' . $file; +$za = new ZipArchive; +$za->open($dir . '/__14962.zip', ZIPARCHIVE::CREATE); +$za->addFromString($file, '1234'); +$za->close(); + +if (!is_file($dir . "/__14962.zip")) { + die('failed to create the archive'); +} +$za = new ZipArchive; +$za->open($dir . '/__14962.zip'); +$za->extractTo($dir, NULL); +$za->close(); + +if (is_file($fullpath)) { + unlink($fullpath); + echo "Ok"; +} +unlink($dir . '/' . '__14962.zip'); +?> +--EXPECT-- +Ok diff --git a/ext/zip/tests/bug38943.phpt b/ext/zip/tests/bug38943.phpt new file mode 100644 index 0000000..c5e2284 --- /dev/null +++ b/ext/zip/tests/bug38943.phpt @@ -0,0 +1,50 @@ +--TEST-- +#38943, properties in extended class cannot be set (5.3+) +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +class myZip extends ZipArchive { + private $test = 0; + public $testp = 1; + private $testarray = array(); + + public function __construct() { + $this->testarray[] = 1; + var_dump($this->testarray); + } +} + +$z = new myZip; +$z->testp = "foobar"; +var_dump($z); + +?> +--EXPECTF-- +array(1) { + [0]=> + int(1) +} +object(myZip)#1 (%d) { + ["test":"myZip":private]=> + int(0) + ["testp"]=> + string(6) "foobar" + ["testarray":"myZip":private]=> + array(1) { + [0]=> + int(1) + } + ["status"]=> + int(0) + ["statusSys"]=> + int(0) + ["numFiles"]=> + int(0) + ["filename"]=> + string(0) "" + ["comment"]=> + string(0) "" +} diff --git a/ext/zip/tests/bug38944.phpt b/ext/zip/tests/bug38944.phpt new file mode 100644 index 0000000..7cff60c --- /dev/null +++ b/ext/zip/tests/bug38944.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #38944 (newly created ZipArchive segfaults when accessing comment property) +--SKIPIF-- +<?php if (!extension_loaded("zip")) print "skip"; ?> +--FILE-- +<?php + +$arc_name = dirname(__FILE__)."/bug38944.zip"; +$foo = new ZipArchive; +$foo->open($arc_name, ZIPARCHIVE::CREATE);; + +var_dump($foo->status); +var_dump($foo->statusSys); +var_dump($foo->numFiles); +var_dump($foo->filename); +var_dump($foo->comment); + +var_dump($foo); + +echo "Done\n"; +?> +--EXPECTF-- +int(0) +int(0) +int(0) +string(%d) "%s" +string(0) "" +object(ZipArchive)#%d (5) { + ["status"]=> + int(0) + ["statusSys"]=> + int(0) + ["numFiles"]=> + int(0) + ["filename"]=> + string(%d) "%s" + ["comment"]=> + string(0) "" +} +Done diff --git a/ext/zip/tests/bug40228.phpt b/ext/zip/tests/bug40228.phpt new file mode 100644 index 0000000..fec2963 --- /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 0000000..bbcd951 --- /dev/null +++ b/ext/zip/tests/bug40228.zip diff --git a/ext/zip/tests/bug47667.phpt b/ext/zip/tests/bug47667.phpt new file mode 100644 index 0000000..9c17de6 --- /dev/null +++ b/ext/zip/tests/bug47667.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug #47667 (ZipArchive::OVERWRITE seems to have no effect) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$thisdir = dirname(__FILE__); +$filename = $thisdir . "/bug47667.zip"; + +$zip = new ZipArchive(); +if ($zip->open($filename, ZipArchive::CREATE) !== true) { + exit("Unable to open the zip file"); +} else { + $zip->addFromString('foo.txt', 'foo bar foobar'); + $zip->close(); +} + +for ($i = 0; $i < 10; $i++) { + $zip = new ZipArchive(); + if ($zip->open($filename, ZipArchive::OVERWRITE) !== true) { + exit("Unable to open the zip file"); + } + $zip->addFromString("foo_{$i}.txt", 'foo bar foobar'); + $zip->close(); +} + +$zip = new ZipArchive(); +if ($zip->open($filename, ZipArchive::CREATE) !== true) { + exit("Unable to open the zip file"); +} + +echo "files: " , $zip->numFiles; +$zip->close(); + +unlink($filename); + +--EXPECT-- +files: 1 diff --git a/ext/zip/tests/bug49072.phpt b/ext/zip/tests/bug49072.phpt new file mode 100644 index 0000000..04bd06e --- /dev/null +++ b/ext/zip/tests/bug49072.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #49072 (feof never returns true for damaged file in zip) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$f = dirname(__FILE__) . '/bug49072.zip'; +$o = new ZipArchive(); +if (! $o->open($f, ZipArchive::CHECKCONS)) { + exit ('error can\'t open'); +} +$r = $o->getStream('file1'); // this file has a wrong crc +if (!$r)die('failed to open a stream for file1'); +$s = ''; +while (! feof($r)) { + $s .= fread($r,1024); +} +?> +--EXPECTF-- + +Warning: fread(): Zip stream error: CRC error in %s on line %d diff --git a/ext/zip/tests/bug49072.zip b/ext/zip/tests/bug49072.zip Binary files differnew file mode 100644 index 0000000..16bbcd0 --- /dev/null +++ b/ext/zip/tests/bug49072.zip diff --git a/ext/zip/tests/bug51353.phpt b/ext/zip/tests/bug51353.phpt new file mode 100644 index 0000000..560945f --- /dev/null +++ b/ext/zip/tests/bug51353.phpt @@ -0,0 +1,54 @@ +--TEST-- +Bug #51353 ZIP64 problem, archive with 100000 items +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +die('skip the test might get very long, activate it manually'); +--FILE-- +<?php +/* This test might get very long depending on the mashine it's running on. Therefore +adding an explicit skip, remove it to run this test. */ +set_time_limit(0); + +$base_path = dirname(__FILE__); + +/* Either we ship a file with 100000 entries which would be >12M big, + or create it dynamically. */ +$zip = new ZipArchive; +$r = $zip->open("$base_path/51353.zip", ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); +if ($r) { + for ($i = 0; $i < 100000; $i++) { + $zip->addFromString("$i.txt", '1'); + } + $zip->close(); +} else { + die("failed"); +} + +$zip = new ZipArchive; +$r = $zip->open("$base_path/51353.zip"); +if ($r) { + $zip->extractTo("$base_path/51353_unpack"); + $zip->close(); + + $a = glob("$base_path/51353_unpack/*.txt"); + echo count($a) . "\n"; +} else { + die("failed"); +} + +echo "OK"; +--CLEAN-- +<?php +$base_path = dirname(__FILE__); + +unlink("$base_path/51353.zip"); + +$a = glob("$base_path/51353_unpack/*.txt"); +foreach($a as $f) { + unlink($f); +} +rmdir("$base_path/51353_unpack"); +--EXPECT-- +100000 +OK diff --git a/ext/zip/tests/bug53579.phpt b/ext/zip/tests/bug53579.phpt new file mode 100644 index 0000000..1d53330 --- /dev/null +++ b/ext/zip/tests/bug53579.phpt @@ -0,0 +1,44 @@ +--TEST-- +Bug #53579 (stream_get_contents() segfaults on ziparchive streams) +--SKIPIF-- +<?php +/* $Id: oo_stream.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ +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 = stream_get_contents($fp); + +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 = stream_get_contents($fp); +var_dump($contents); +fclose($fp); + +?> +--EXPECTF-- +resource(%d) of type (stream) +string(5) "foo + +" +string(5) "foo + +" diff --git a/ext/zip/tests/bug53603.phpt b/ext/zip/tests/bug53603.phpt new file mode 100644 index 0000000..f8ff1b4 --- /dev/null +++ b/ext/zip/tests/bug53603.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #53603 (ZipArchive should quiet stat errors) +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +class TestStream { + function url_stat($path, $flags) { + if (!($flags & STREAM_URL_STAT_QUIET)) + trigger_error("not quiet"); + return array(); + } +} + +stream_wrapper_register("teststream", "TestStream"); + +$dirname = dirname(__FILE__) . '/'; +$file = $dirname . 'test_with_comment.zip'; +$zip = new ZipArchive; +if ($zip->open($file) !== TRUE) { + echo "open failed.\n"; + exit('failed'); +} + +$a = $zip->extractTo('teststream://test'); +var_dump($a); + +--EXPECTF-- + +Warning: ZipArchive::extractTo(teststream://test/foo): failed to open stream: "TestStream::stream_open" call failed in %s on line %d +bool(false) + diff --git a/ext/zip/tests/bug53854.phpt b/ext/zip/tests/bug53854.phpt new file mode 100644 index 0000000..cd8ae7e --- /dev/null +++ b/ext/zip/tests/bug53854.phpt @@ -0,0 +1,44 @@ +--TEST-- +Bug #53854 (Missing constants for compression type) +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +var_dump(ZipArchive::CM_DEFAULT); +var_dump(ZipArchive::CM_STORE); +var_dump(ZipArchive::CM_SHRINK); +var_dump(ZipArchive::CM_REDUCE_1); +var_dump(ZipArchive::CM_REDUCE_2); +var_dump(ZipArchive::CM_REDUCE_3); +var_dump(ZipArchive::CM_REDUCE_4); +var_dump(ZipArchive::CM_IMPLODE); +var_dump(ZipArchive::CM_DEFLATE); +var_dump(ZipArchive::CM_DEFLATE64); +var_dump(ZipArchive::CM_PKWARE_IMPLODE); +var_dump(ZipArchive::CM_BZIP2); +var_dump(ZipArchive::CM_LZMA); +var_dump(ZipArchive::CM_TERSE); +var_dump(ZipArchive::CM_LZ77); +var_dump(ZipArchive::CM_WAVPACK); +var_dump(ZipArchive::CM_PPMD); +--EXPECT-- +int(-1) +int(0) +int(1) +int(2) +int(3) +int(4) +int(5) +int(6) +int(8) +int(9) +int(10) +int(12) +int(14) +int(18) +int(19) +int(97) +int(98) diff --git a/ext/zip/tests/bug53885.phpt b/ext/zip/tests/bug53885.phpt new file mode 100644 index 0000000..1b3fcb9 --- /dev/null +++ b/ext/zip/tests/bug53885.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #53885 (ZipArchive segfault with FL_UNCHANGED on empty archive) +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$fname = dirname(__FILE__)."/test53885.zip"; +if(file_exists($fname)) unlink($fname); +touch($fname); +$nx=new ZipArchive(); +$nx->open($fname); +$nx->locateName("a",ZIPARCHIVE::FL_UNCHANGED); +$nx->statName("a",ZIPARCHIVE::FL_UNCHANGED); +?> +==DONE== +--CLEAN-- +<?php +$fname = dirname(__FILE__)."/test53885.zip"; +unlink($fname); +?> +--EXPECTF-- +==DONE== diff --git a/ext/zip/tests/bug7214.phpt b/ext/zip/tests/bug7214.phpt new file mode 100644 index 0000000..f791b79 --- /dev/null +++ b/ext/zip/tests/bug7214.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #7214 (zip_entry_read() binary safe) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); + ?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/binarynull.zip"); +if (!is_resource($zip)) die("Failure"); +$entries = 0; +$entry = zip_read($zip); +$contents = zip_entry_read($entry, zip_entry_filesize($entry)); +if (strlen($contents) == zip_entry_filesize($entry)) { + echo "Ok"; +} else { + echo "failed"; +} + +?> +--EXPECT-- +Ok diff --git a/ext/zip/tests/bug7658.odt b/ext/zip/tests/bug7658.odt Binary files differnew file mode 100644 index 0000000..527e09f --- /dev/null +++ b/ext/zip/tests/bug7658.odt diff --git a/ext/zip/tests/bug7658.phpt b/ext/zip/tests/bug7658.phpt new file mode 100644 index 0000000..56fd00f --- /dev/null +++ b/ext/zip/tests/bug7658.phpt @@ -0,0 +1,55 @@ +--TEST-- +Bug #7658 (modify archive with general bit flag 3 set) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$expect = array( + "mimetype", + "Configurations2/statusbar/", + "Configurations2/accelerator/current.xml", + "Configurations2/floater/", + "Configurations2/popupmenu/", + "Configurations2/progressbar/", + "Configurations2/menubar/", + "Configurations2/toolbar/", + "Configurations2/images/Bitmaps/", + "content.xml", + "styles.xml", + "meta.xml", + "Thumbnails/thumbnail.png", + "settings.xml", + "META-INF/manifest.xml", +); +$dirname = dirname(__FILE__) . '/'; +include $dirname . 'utils.inc'; +$file = $dirname . '__tmp_bug7658.odt'; +$zip = new ZipArchive(); +copy($dirname . 'bug7658.odt', $file); +if(!$zip->open($file)) { + echo 'failed'; +} + + +$zip->deleteName('content.xml'); +$zip->addFile($dirname . "bug7658.xml","content.xml"); +$zip->close(); +echo "\n"; +$zip->open($file); + +for($i=0; $i < $zip->numFiles; $i++) { + $sb = $zip->statIndex($i); + $found[] = $sb['name']; +} +$ar = array_diff($found, $expect); + +var_dump($ar); +unset($zip); +unlink($file); +?> +--EXPECTF-- +array(0) { +} diff --git a/ext/zip/tests/bug7658.xml b/ext/zip/tests/bug7658.xml new file mode 100644 index 0000000..98076f1 --- /dev/null +++ b/ext/zip/tests/bug7658.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0"><office:scripts/><office:font-face-decls><style:font-face style:name="Tahoma1" svg:font-family="Tahoma"/><style:font-face style:name="Arial Unicode MS" svg:font-family="'Arial Unicode MS'" style:font-pitch="variable"/><style:font-face style:name="Estrangelo Edessa" svg:font-family="'Estrangelo Edessa'" style:font-pitch="variable"/><style:font-face style:name="MS Mincho" svg:font-family="'MS Mincho'" style:font-pitch="variable"/><style:font-face style:name="Miriam CLM" svg:font-family="'Miriam CLM'" style:font-pitch="variable"/><style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-pitch="variable"/><style:font-face style:name="Times New Roman" svg:font-family="'Times New Roman'" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="Tabella1" style:family="table"><style:table-properties style:width="6.6924in" table:align="margins"/></style:style><style:style style:name="Tabella1.A" style:family="table-column"><style:table-column-properties style:column-width="4.8556in" style:rel-column-width="47546*"/></style:style><style:style style:name="Tabella1.B" style:family="table-column"><style:table-column-properties style:column-width="1.8368in" style:rel-column-width="17989*"/></style:style><style:style style:name="Tabella1.A1" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border-left="0.0007in solid #000000" fo:border-right="none" fo:border-top="0.0007in solid #000000" fo:border-bottom="0.0007in solid #000000"/></style:style><style:style style:name="Tabella1.B1" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border="0.0007in solid #000000"/></style:style><style:style style:name="Tabella1.A2" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border-left="0.0007in solid #000000" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.0007in solid #000000"/></style:style><style:style style:name="Tabella1.B2" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border-left="0.0007in solid #000000" fo:border-right="0.0007in solid #000000" fo:border-top="none" fo:border-bottom="0.0007in solid #000000"/></style:style><style:style style:name="Tabella2" style:family="table"><style:table-properties style:width="6.6924in" table:align="margins"/></style:style><style:style style:name="Tabella2.A" style:family="table-column"><style:table-column-properties style:column-width="2.584in" style:rel-column-width="25303*"/></style:style><style:style style:name="Tabella2.C" style:family="table-column"><style:table-column-properties style:column-width="1.5243in" style:rel-column-width="14929*"/></style:style><style:style style:name="Tabella2.A1" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border-left="0.0007in solid #000000" fo:border-right="none" fo:border-top="0.0007in solid #000000" fo:border-bottom="0.0007in solid #000000"/></style:style><style:style style:name="Tabella2.C1" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border="0.0007in solid #000000"/></style:style><style:style style:name="Tabella2.A2" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border-left="0.0007in solid #000000" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.0007in solid #000000"/></style:style><style:style style:name="Tabella2.C2" style:family="table-cell"><style:table-cell-properties fo:padding="0.0382in" fo:border-left="0.0007in solid #000000" fo:border-right="0.0007in solid #000000" fo:border-top="none" fo:border-bottom="0.0007in solid #000000"/></style:style><style:style style:name="P1" style:family="paragraph" style:parent-style-name="Table_20_Heading"><style:text-properties style:font-name="Estrangelo Edessa" fo:font-style="italic" fo:font-weight="bold" style:font-style-asian="italic" style:font-weight-asian="bold" style:font-style-complex="italic" style:font-weight-complex="bold"/></style:style><style:style style:name="P2" style:family="paragraph" style:parent-style-name="Table_20_Heading"><style:paragraph-properties fo:padding="0.0193in" fo:border="0.0008in solid #000000" style:shadow="none"/><style:text-properties style:font-name="Estrangelo Edessa" fo:font-style="italic" fo:font-weight="bold" style:font-style-asian="italic" style:font-weight-asian="bold" style:font-style-complex="italic" style:font-weight-complex="bold"/></style:style><style:style style:name="P3" style:family="paragraph" style:parent-style-name="Table_20_Contents"><style:text-properties fo:color="#ff0000" style:font-name="Miriam CLM" fo:font-style="italic" fo:font-weight="bold" style:font-style-asian="italic" style:font-weight-asian="bold" style:font-style-complex="italic" style:font-weight-complex="bold"/></style:style></office:automatic-styles><office:body><office:text><office:forms form:automatic-focus="false" form:apply-design-mode="false"/><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:p text:style-name="Standard"/><text:p text:style-name="Standard"/><text:p text:style-name="Standard">Other text Silvio Berlusconi, le ricordo che ha in prestito i seguenti libri</text:p><text:p text:style-name="Standard"/><table:table table:name="Tabella1" table:style-name="Tabella1"><table:table-column table:style-name="Tabella1.A"/><table:table-column table:style-name="Tabella1.B"/><table:table-header-rows><table:table-row><table:table-cell table:style-name="Tabella1.A1" office:value-type="string"><text:p text:style-name="P1">Titolo</text:p></table:table-cell><table:table-cell table:style-name="Tabella1.B1" office:value-type="string"><text:p text:style-name="P1">Inventario</text:p></table:table-cell></table:table-row></table:table-header-rows><table:table-row><table:table-cell table:style-name="Tabella1.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">Codice Da Vinci</text:p></table:table-cell><table:table-cell table:style-name="Tabella1.B2" office:value-type="string"><text:p text:style-name="Table_20_Contents">112345678</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella1.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">Lo Zen e il tiro con l'arco</text:p></table:table-cell><table:table-cell table:style-name="Tabella1.B2" office:value-type="string"><text:p text:style-name="Table_20_Contents">1020304</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella1.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">Lo Zen e l'arte della manutenzione della motocicletta</text:p></table:table-cell><table:table-cell table:style-name="Tabella1.B2" office:value-type="string"><text:p text:style-name="Table_20_Contents">1020305</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella1.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">101 Storie Zen</text:p></table:table-cell><table:table-cell table:style-name="Tabella1.B2" office:value-type="string"><text:p text:style-name="Table_20_Contents">1020306</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella1.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">Antani di Blinda come fosse di Cappotto</text:p></table:table-cell><table:table-cell table:style-name="Tabella1.B2" office:value-type="string"><text:p text:style-name="Table_20_Contents">4112345</text:p></table:table-cell></table:table-row></table:table><text:p text:style-name="Standard"/><text:p text:style-name="Standard">peraltro, sottolineiamo la perentorietà della restituzione anche dei vieppiù interessanti testi:</text:p><text:p text:style-name="Standard"/><table:table table:name="Tabella2" table:style-name="Tabella2"><table:table-column table:style-name="Tabella2.A" table:number-columns-repeated="2"/><table:table-column table:style-name="Tabella2.C"/><table:table-header-rows><table:table-row><table:table-cell table:style-name="Tabella2.A1" office:value-type="string"><text:p text:style-name="P2">Titolo</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.A1" office:value-type="string"><text:p text:style-name="P2">Autore</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.C1" office:value-type="string"><text:p text:style-name="P2">Inventario</text:p></table:table-cell></table:table-row></table:table-header-rows><table:table-row><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">Angeli e Demoni</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="P3">Dan Brown</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.C2" office:value-type="string"><text:p text:style-name="Table_20_Contents">12131415</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">La versione di Barney</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="P3">Mordecai Richler</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.C2" office:value-type="string"><text:p text:style-name="Table_20_Contents">2010322</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">Manuale PHP</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="P3">Varii</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.C2" office:value-type="string"><text:p text:style-name="Table_20_Contents">32413543</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">La prematurata supercazzola negli anni a venire</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="P3">Ugo Tognazzi</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.C2" office:value-type="string"><text:p text:style-name="Table_20_Contents">31213243</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="Table_20_Contents">La sbiriguda in vicesindaco</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.A2" office:value-type="string"><text:p text:style-name="P3">Ugo Tognazzi</text:p></table:table-cell><table:table-cell table:style-name="Tabella2.C2" office:value-type="string"><text:p text:style-name="Table_20_Contents">1324354654</text:p></table:table-cell></table:table-row></table:table><text:p text:style-name="Standard"/><text:p text:style-name="Standard"/><text:p text:style-name="Standard">Gentili saluti, la sua biblioteca</text:p></office:text></office:body></office:document-content> diff --git a/ext/zip/tests/bug8009.phpt b/ext/zip/tests/bug8009.phpt new file mode 100644 index 0000000..5dd363d --- /dev/null +++ b/ext/zip/tests/bug8009.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #8009 (cannot add again same entry to an archive) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$thisdir = dirname(__FILE__); +$src = $thisdir . "/bug8009.zip"; +$filename = $thisdir . "/tmp8009.zip"; +copy($src, $filename); + +$zip = new ZipArchive(); + +if (!$zip->open($filename)) { + exit("cannot open $filename\n"); +} +$zip->addFromString("2.txt", "=)"); +$zip->close(); +unlink($filename); +echo "status: " . $zip->status . "\n"; +echo "\n"; + +--EXPECT-- +status: 0 diff --git a/ext/zip/tests/bug8009.zip b/ext/zip/tests/bug8009.zip Binary files differnew file mode 100644 index 0000000..45bedcb --- /dev/null +++ b/ext/zip/tests/bug8009.zip diff --git a/ext/zip/tests/bug8700.phpt b/ext/zip/tests/bug8700.phpt new file mode 100644 index 0000000..c394cf0 --- /dev/null +++ b/ext/zip/tests/bug8700.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #8700 (getFromIndex(0) fails) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$thisdir = dirname(__FILE__); +$filename = $thisdir . "/bug8009.zip"; + +$zip = new ZipArchive(); + +if ($zip->open($filename) === FALSE) { + exit("cannot open $filename\n"); +} +$contents_from_idx = $zip->getFromIndex(0); +$contents_from_name = $zip->getFromName('1.txt'); +if ($contents_from_idx != $contents_from_name) { + echo "failed:"; + var_dump($content_from_idx, $content_from_name); +} + +$zip->close(); +echo "status: " . $zip->status . "\n"; +echo "\n"; + +--EXPECT-- +status: 0 diff --git a/ext/zip/tests/oo_addemptydir.phpt b/ext/zip/tests/oo_addemptydir.phpt new file mode 100644 index 0000000..cb57b5b --- /dev/null +++ b/ext/zip/tests/oo_addemptydir.phpt @@ -0,0 +1,36 @@ +--TEST-- +ziparchive::addEmptyDir +--SKIPIF-- +<?php +/* $Id$ */ +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_addfile.phpt b/ext/zip/tests/oo_addfile.phpt new file mode 100644 index 0000000..ab79780 --- /dev/null +++ b/ext/zip/tests/oo_addfile.phpt @@ -0,0 +1,37 @@ +--TEST-- +ziparchive::addFile() function +--SKIPIF-- +<?php +/* $Id$ */ +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'); +} +if (!$zip->addFile($dirname . 'utils.inc', 'test.php')) { + echo "failed\n"; +} +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 test.php diff --git a/ext/zip/tests/oo_close.phpt b/ext/zip/tests/oo_close.phpt new file mode 100644 index 0000000..ea67dcd --- /dev/null +++ b/ext/zip/tests/oo_close.phpt @@ -0,0 +1,25 @@ +--TEST-- +zip::close() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +$dirname = dirname(__FILE__) . '/'; +$zip = new ZipArchive; +if (!$zip->open($dirname . 'test.zip')) { + exit('failed'); +} + +if ($zip->status == ZIPARCHIVE::ER_OK) { + $zip->close(); + echo "ok\n"; +} else { + echo "failed\n"; +} +?> +--EXPECTF-- +ok diff --git a/ext/zip/tests/oo_delete.phpt b/ext/zip/tests/oo_delete.phpt new file mode 100644 index 0000000..9eac821 --- /dev/null +++ b/ext/zip/tests/oo_delete.phpt @@ -0,0 +1,81 @@ +--TEST-- +Delete entries +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$dirname = dirname(__FILE__) . '/'; +$file = $dirname . '__tmp_oo_delete.zip'; +if (file_exists($file)) { + 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/entry2.txt', 'entry #2'); + +if ($zip->status == ZIPARCHIVE::ER_OK) { + $zip->close(); + echo "ok\n"; +} else { + var_dump($zip); + echo "failed\n"; +} + +if (!$zip->open($file, ZIPARCHIVE::CREATE)) { + exit('failed'); +} + +if ($zip->deleteIndex(0)) { + echo "ok\n"; +} + +if ($zip->deleteName('entry2.txt')) { + echo "ok\n"; +} else { + echo "failed 3\n"; +} + +if ($zip->deleteName('dir/entry2.txt')) { + echo "ok\n"; +} else { + echo "failed 3\n"; +} + +if (!$zip->deleteIndex(123)) { + echo "ok\n"; +} else { + print_r($zip); + echo "failed\n"; +} + + +$sb = $zip->statIndex(0); +var_dump($sb); +$sb = $zip->statIndex(1); +var_dump($sb); +$sb = $zip->statIndex(2); +var_dump($sb); +$zip->close(); +unset($zip); + +if (file_exists($file)) { + unlink($file); +} +?> +--EXPECTF-- +ok +ok +ok +ok +ok +bool(false) +bool(false) +bool(false) diff --git a/ext/zip/tests/oo_ext_zip.phpt b/ext/zip/tests/oo_ext_zip.phpt new file mode 100644 index 0000000..739a671 --- /dev/null +++ b/ext/zip/tests/oo_ext_zip.phpt @@ -0,0 +1,27 @@ +--TEST-- +Extending Zip class and array property +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +class myZip extends ZipArchive { + private $test = 0; + public $testp = 1; + private $testarray = array(); + + public function __construct() { + $this->testarray[] = 1; + var_dump($this->testarray); + } +} + +$z = new myZip; +?> +--EXPECTF-- +array(1) { + [0]=> + int(1) +} diff --git a/ext/zip/tests/oo_extract.phpt b/ext/zip/tests/oo_extract.phpt new file mode 100644 index 0000000..7ca39ee --- /dev/null +++ b/ext/zip/tests/oo_extract.phpt @@ -0,0 +1,95 @@ +--TEST-- +extractTo +--SKIPIF-- +<?php +/* $Id$ */ +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 0000000..d05385c --- /dev/null +++ b/ext/zip/tests/oo_getcomment.phpt @@ -0,0 +1,36 @@ +--TEST-- +getComment +--SKIPIF-- +<?php +/* $Id$ */ +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 0000000..cd4c9db --- /dev/null +++ b/ext/zip/tests/oo_getnameindex.phpt @@ -0,0 +1,47 @@ +--TEST-- +getNameIndex +--SKIPIF-- +<?php +/* $Id$ */ +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_getstatusstring.phpt b/ext/zip/tests/oo_getstatusstring.phpt new file mode 100644 index 0000000..efd19e3 --- /dev/null +++ b/ext/zip/tests/oo_getstatusstring.phpt @@ -0,0 +1,28 @@ +--TEST-- +This test will test getStatusString method in ZipArchive +--CREDITS-- +Ole-Petter Wikene <olepw@redpill-linpro.com> +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- +<?php if (!extension_loaded("zip")) { echo "skip extension not available"; } ?> +--FILE-- +<?php + +$dirname = dirname(__FILE__) . '/'; +$arch = new ZipArchive; +$arch->open($dirname.'foo.zip',ZIPARCHIVE::CREATE); +var_dump($arch->getStatusString()); +//delete an index that does not exist - trigger error +$arch->deleteIndex(2); +var_dump($arch->getStatusString()); +$arch->close(); + +?> +--CLEAN-- +<?php +unlink($dirname.'foo.zip'); +?> +--EXPECT-- +string(8) "No error" +string(16) "Invalid argument" + diff --git a/ext/zip/tests/oo_namelocate.phpt b/ext/zip/tests/oo_namelocate.phpt new file mode 100644 index 0000000..bbe7ec5 --- /dev/null +++ b/ext/zip/tests/oo_namelocate.phpt @@ -0,0 +1,46 @@ +--TEST-- +Locate entries by name +--SKIPIF-- +<?php +/* $Id$ */ +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->locateName('entry1.txt')); +var_dump($zip->locateName('eNtry2.txt')); +var_dump($zip->locateName('eNtry2.txt', ZIPARCHIVE::FL_NOCASE)); +var_dump($zip->locateName('enTRy2d.txt', ZIPARCHIVE::FL_NOCASE|ZIPARCHIVE::FL_NODIR)); +$zip->close(); + +?> +--EXPECTF-- +int(0) +bool(false) +int(1) +int(2) diff --git a/ext/zip/tests/oo_open.phpt b/ext/zip/tests/oo_open.phpt new file mode 100644 index 0000000..0760db3 --- /dev/null +++ b/ext/zip/tests/oo_open.phpt @@ -0,0 +1,46 @@ +--TEST-- +zip::open() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +$dirname = dirname(__FILE__) . '/'; +$zip = new ZipArchive; +$r = $zip->open($dirname . 'nofile'); +if ($r !== TRUE) { + echo "ER_OPEN: ok\n"; +} else { + echo "ER_OPEN: FAILED\n"; +} + +$r = $zip->open($dirname . 'nofile', ZIPARCHIVE::CREATE); +if (!$r) { + echo "create: failed\n"; +} else { + echo "create: ok\n"; +} +@unlink($dirname . 'nofile'); + +$zip = new ZipArchive; +$zip->open(''); + +if (!$zip->open($dirname . 'test.zip')) { + exit("failed 1\n"); +} + +if ($zip->status == ZIPARCHIVE::ER_OK) { + echo "OK\n"; +} else { + echo "failed\n"; +} +?> +--EXPECTF-- +ER_OPEN: ok +create: ok + +Warning: ZipArchive::open(): Empty string as source in %s on line %d +OK diff --git a/ext/zip/tests/oo_properties.phpt b/ext/zip/tests/oo_properties.phpt new file mode 100644 index 0000000..886317b --- /dev/null +++ b/ext/zip/tests/oo_properties.phpt @@ -0,0 +1,60 @@ +--TEST-- +ziparchive::properties isset()/empty() checks +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php + +$dirname = dirname(__FILE__) . '/'; +$file = $dirname . '__property_test.zip'; + +copy($dirname . 'test_with_comment.zip', $file); + +$zip = new ZipArchive; +if (!$zip->open($file)) { + exit('failed'); +} + +printf("zip->status (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->status, empty($zip->status), isset($zip->status)); +printf("zip->numFiles (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->numFiles, empty($zip->numFiles), isset($zip->numFiles)); +printf("zip->bogus (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->bogus, empty($zip->bogus), isset($zip->bogus)); + + +$zip->addEmptyDir('emptydir'); + +printf("zip->status (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->status, empty($zip->status), isset($zip->status)); +printf("zip->numFiles (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->numFiles, empty($zip->numFiles), isset($zip->numFiles)); +printf("zip->filename (%d):\n\tempty(): %d\n\tisset(): %d\n", strlen($zip->filename), empty($zip->filename), isset($zip->filename)); +printf("zip->comment (%d):\n\tempty(): %d\n\tisset(): %d\n", strlen($zip->comment), empty($zip->comment), isset($zip->comment)); + +unset($zip); //close the file before unlinking +@unlink($file); +?> +--EXPECTF-- +zip->status (0): + empty(): 1 + isset(): 1 +zip->numFiles (4): + empty(): 0 + isset(): 1 + +Notice: Undefined property: ZipArchive::$bogus in %s on line %d +zip->bogus (0): + empty(): 1 + isset(): 0 +zip->status (0): + empty(): 1 + isset(): 1 +zip->numFiles (5): + empty(): 0 + isset(): 1 +zip->filename (%d): + empty(): 0 + isset(): 1 +zip->comment (19): + empty(): 0 + isset(): 1 + diff --git a/ext/zip/tests/oo_rename.phpt b/ext/zip/tests/oo_rename.phpt new file mode 100644 index 0000000..98489ae --- /dev/null +++ b/ext/zip/tests/oo_rename.phpt @@ -0,0 +1,58 @@ +--TEST-- +Rename entries +--SKIPIF-- +<?php +/* $Id$ */ +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/entry2.txt', 'entry #2'); + +if (!$zip->status == ZIPARCHIVE::ER_OK) { + var_dump($zip); + echo "failed\n"; +} + +$zip->close(); + +if (!$zip->open($file)) { + exit('failed'); +} + +dump_entries_name($zip); +echo "\n"; + +if (!$zip->renameIndex(0, 'ren_entry1.txt')) { + echo "failed index 0\n"; +} + +if (!$zip->renameName('dir/entry2.txt', 'dir3/ren_entry2.txt')) { + echo "failed name dir/entry2.txt\n"; +} +dump_entries_name($zip); +$zip->close(); + +@unlink($file); +?> +--EXPECTF-- +0 entry1.txt +1 entry2.txt +2 dir/entry2.txt + +0 ren_entry1.txt +1 entry2.txt +2 dir3/ren_entry2.txt diff --git a/ext/zip/tests/oo_setcomment.phpt b/ext/zip/tests/oo_setcomment.phpt new file mode 100644 index 0000000..89d6e8e --- /dev/null +++ b/ext/zip/tests/oo_setcomment.phpt @@ -0,0 +1,71 @@ +--TEST-- +setComment +--SKIPIF-- +<?php +/* $Id$ */ +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 0000000..126e78f --- /dev/null +++ b/ext/zip/tests/oo_stream.phpt @@ -0,0 +1,50 @@ +--TEST-- +getStream +--SKIPIF-- +<?php +/* $Id$ */ +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/pecl12414.phpt b/ext/zip/tests/pecl12414.phpt new file mode 100644 index 0000000..6154638 --- /dev/null +++ b/ext/zip/tests/pecl12414.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #12414 ( extracting files from damaged archives) +--SKIPIF-- +<?php +/*$ */ +if(!extension_loaded('zip')) die('skip'); + ?> +--FILE-- +<?php +$filename = 'MYLOGOV2.GFX'; +$zipname = dirname(__FILE__) . "/pecl12414.zip"; +$za = new ZipArchive(); +$res =$za->open($zipname); +if ($res === TRUE) { + $finfo=$za->statName($filename); + $file_size=$finfo['size']; + + if($file_size>0) { + $contents=$za->getFromName($filename); + + echo "ZIP contents size: " . strlen($contents) . "\n"; + if(strlen($contents)!=$file_size) { + echo "zip_readfile recorded data does not match unpacked size: " . $zipname . " : " . $filename; + } + } else { + $contents=false; + echo "zip_readfile could not open stream from zero length file " . $zipname . " : " .$filename; + } + + $za->close(); +} else { + echo "zip_readfile could not read from " . $zipname . " : " . $filename; +} + +?> +--DONE-- +--EXPECTF-- +zip_readfile could not read from %specl12414.zip : MYLOGOV2.GFX diff --git a/ext/zip/tests/pecl12414.zip b/ext/zip/tests/pecl12414.zip Binary files differnew file mode 100644 index 0000000..6cbc60f --- /dev/null +++ b/ext/zip/tests/pecl12414.zip diff --git a/ext/zip/tests/stream_meta_data.phpt b/ext/zip/tests/stream_meta_data.phpt new file mode 100644 index 0000000..bd08098 --- /dev/null +++ b/ext/zip/tests/stream_meta_data.phpt @@ -0,0 +1,74 @@ +--TEST-- +stream_get_meta_data() on zip stream +--SKIPIF-- +<?php +/* $Id: oo_stream.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ +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'); + +if(!$fp) exit("\n"); + +var_dump(stream_get_meta_data($fp)); + +fclose($fp); +$zip->close(); + + +$fp = fopen('zip://' . dirname(__FILE__) . '/test_with_comment.zip#foo', 'rb'); +if (!$fp) { + exit("cannot open\n"); +} + +var_dump(stream_get_meta_data($fp)); +fclose($fp); + +?> +--EXPECTF-- +array(8) { + ["stream_type"]=> + string(3) "zip" + ["mode"]=> + string(2) "rb" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["uri"]=> + string(3) "foo" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(11) "zip wrapper" + ["stream_type"]=> + string(3) "zip" + ["mode"]=> + string(2) "rb" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["uri"]=> + string(%d) "zip://%stest_with_comment.zip#foo" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/zip/tests/test.zip b/ext/zip/tests/test.zip Binary files differnew file mode 100644 index 0000000..35bd5ee --- /dev/null +++ b/ext/zip/tests/test.zip diff --git a/ext/zip/tests/test_procedural.zip b/ext/zip/tests/test_procedural.zip Binary files differnew file mode 100644 index 0000000..6b98694 --- /dev/null +++ b/ext/zip/tests/test_procedural.zip 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 0000000..d68f761 --- /dev/null +++ b/ext/zip/tests/test_with_comment.zip diff --git a/ext/zip/tests/utils.inc b/ext/zip/tests/utils.inc new file mode 100644 index 0000000..02e37f6 --- /dev/null +++ b/ext/zip/tests/utils.inc @@ -0,0 +1,24 @@ +<?php +/* $Id$ */ +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_close.phpt b/ext/zip/tests/zip_close.phpt new file mode 100644 index 0000000..7f9d09a --- /dev/null +++ b/ext/zip/tests/zip_close.phpt @@ -0,0 +1,17 @@ +--TEST-- +zip_close() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +if (!is_resource($zip)) die("Failure"); +zip_close($zip); +echo "OK"; + +?> +--EXPECT-- +OK diff --git a/ext/zip/tests/zip_entry_compressedsize.phpt b/ext/zip/tests/zip_entry_compressedsize.phpt new file mode 100644 index 0000000..fefa6e5 --- /dev/null +++ b/ext/zip/tests/zip_entry_compressedsize.phpt @@ -0,0 +1,23 @@ +--TEST-- +zip_entry_compressedsize() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +if (!is_resource($zip)) die("Failure"); +$entries = 0; +while ($entry = zip_read($zip)) { + echo zip_entry_compressedsize($entry)."\n"; +} +zip_close($zip); + +?> +--EXPECT-- +5 +4 +0 +24 diff --git a/ext/zip/tests/zip_entry_compressionmethod.phpt b/ext/zip/tests/zip_entry_compressionmethod.phpt new file mode 100644 index 0000000..cabdbb7 --- /dev/null +++ b/ext/zip/tests/zip_entry_compressionmethod.phpt @@ -0,0 +1,24 @@ +--TEST-- +zip_entry_compressionmethod() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +if (!is_resource($zip)) die("Failure"); +$entries = 0; +while ($entry = zip_read($zip)) { + echo zip_entry_compressionmethod($entry)."\n"; +} +zip_close($zip); + +?> +--EXPECT-- +stored +stored +stored +deflated + diff --git a/ext/zip/tests/zip_entry_filesize.phpt b/ext/zip/tests/zip_entry_filesize.phpt new file mode 100644 index 0000000..b8d8820 --- /dev/null +++ b/ext/zip/tests/zip_entry_filesize.phpt @@ -0,0 +1,23 @@ +--TEST-- +zip_entry_filesize() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +if (!is_resource($zip)) die("Failure"); +$entries = 0; +while ($entry = zip_read($zip)) { + echo zip_entry_filesize($entry)."\n"; +} +zip_close($zip); + +?> +--EXPECT-- +5 +4 +0 +27 diff --git a/ext/zip/tests/zip_entry_name.phpt b/ext/zip/tests/zip_entry_name.phpt new file mode 100644 index 0000000..1916e25 --- /dev/null +++ b/ext/zip/tests/zip_entry_name.phpt @@ -0,0 +1,23 @@ +--TEST-- +zip_entry_name() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +if (!is_resource($zip)) die("Failure"); +$entries = 0; +while ($entry = zip_read($zip)) { + echo zip_entry_name($entry)."\n"; +} +zip_close($zip); + +?> +--EXPECT-- +foo +bar +foobar/ +foobar/baz diff --git a/ext/zip/tests/zip_entry_open.phpt b/ext/zip/tests/zip_entry_open.phpt new file mode 100644 index 0000000..c32fe57 --- /dev/null +++ b/ext/zip/tests/zip_entry_open.phpt @@ -0,0 +1,18 @@ +--TEST-- +zip_entry_open() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$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); + +?> +--EXPECT-- +OK diff --git a/ext/zip/tests/zip_entry_read.phpt b/ext/zip/tests/zip_entry_read.phpt new file mode 100644 index 0000000..d876f03 --- /dev/null +++ b/ext/zip/tests/zip_entry_read.phpt @@ -0,0 +1,19 @@ +--TEST-- +zip_entry_read() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$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); + +?> +--EXPECT-- +foo diff --git a/ext/zip/tests/zip_open.phpt b/ext/zip/tests/zip_open.phpt new file mode 100644 index 0000000..91474bc --- /dev/null +++ b/ext/zip/tests/zip_open.phpt @@ -0,0 +1,16 @@ +--TEST-- +zip_open() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); + +echo is_resource($zip) ? "OK" : "Failure"; + +?> +--EXPECT-- +OK diff --git a/ext/zip/tests/zip_open_error.phpt b/ext/zip/tests/zip_open_error.phpt new file mode 100644 index 0000000..eaa1d97 --- /dev/null +++ b/ext/zip/tests/zip_open_error.phpt @@ -0,0 +1,28 @@ +--TEST-- +zip_open() error conditions +--CREDITS-- +Birgitte Kvarme <bitta@redpill-linpro.com> +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +echo "Test case 1:"; +$zip = zip_open(""); + +echo "Test case 2:"; +$zip = zip_open("i_dont_care_about_this_parameter", "this_is_one_to_many"); + +echo "Test case 3:\n"; +$zip = zip_open("/non_exisitng_directory/test_procedural.zip"); +echo is_resource($zip) ? "OK" : "Failure"; +?> +--EXPECTF-- +Test case 1: +Warning: zip_open(): Empty string as source in %s on line %d +Test case 2: +Warning: zip_open() expects exactly 1 parameter, 2 given in %s on line %d +Test case 3: +Failure diff --git a/ext/zip/tests/zip_read.phpt b/ext/zip/tests/zip_read.phpt new file mode 100644 index 0000000..5cadb2d --- /dev/null +++ b/ext/zip/tests/zip_read.phpt @@ -0,0 +1,21 @@ +--TEST-- +zip_read() function +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$zip = zip_open(dirname(__FILE__)."/test_procedural.zip"); +if (!is_resource($zip)) die("Failure"); +$entries = 0; +while ($entry = zip_read($zip)) { + $entries++; +} +zip_close($zip); +echo "$entries entries"; + +?> +--EXPECT-- +4 entries |