Skip to content

Commit 1358b43

Browse files
committed
more tests for zip with libzip 1.10
1 parent 961e57e commit 1358b43

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

ext/zip/tests/oo_close_empty.phpt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
Close empty file behavior
3+
--EXTENSIONS--
4+
zip
5+
--SKIPIF--
6+
<?php
7+
if (version_compare(ZipArchive::LIBZIP_VERSION, '1.10.0', '<')) die('skip libzip < 1.10.0');
8+
?>
9+
--FILE--
10+
<?php
11+
$name = __DIR__ . '/oo_close_empty.zip';
12+
13+
function run($name, $keep) {
14+
copy(__DIR__ . '/test.zip', $name);
15+
16+
$zip = new ZipArchive();
17+
$zip->open($name, ZIPARCHIVE::CREATE);
18+
if ($keep) {
19+
echo "\nClose and keep\n";
20+
var_dump($zip->setArchiveFlag(ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE, 1), $zip->status === ZipArchive::ER_OK);
21+
} else {
22+
echo "Close and delete\n";
23+
}
24+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE));
25+
for($i=$zip->numFiles ; $i ;) {
26+
$zip->deleteIndex(--$i);
27+
}
28+
$zip->close();
29+
var_dump(file_exists($name));
30+
}
31+
run($name, false);
32+
run($name, true);
33+
?>
34+
--CLEAN--
35+
<?php
36+
$name = __DIR__ . '/oo_close_empty.zip';
37+
@unlink($name);
38+
?>
39+
--EXPECTF--
40+
Close and delete
41+
int(0)
42+
bool(false)
43+
44+
Close and keep
45+
bool(true)
46+
bool(true)
47+
int(1)
48+
bool(true)

ext/zip/tests/oo_torrentzip.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
torrentzip format support
3+
--EXTENSIONS--
4+
zip
5+
--SKIPIF--
6+
<?php
7+
if (version_compare(ZipArchive::LIBZIP_VERSION, '1.10.0', '<')) die('skip libzip < 1.10.0');
8+
?>
9+
--FILE--
10+
<?php
11+
$name = __DIR__ . '/torrent.zip';
12+
13+
$zip = new ZipArchive();
14+
15+
echo "Open write\n";
16+
$zip->open($name, ZIPARCHIVE::CREATE);
17+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_IS_TORRENTZIP));
18+
var_dump($zip->setArchiveFlag(ZipArchive::AFL_WANT_TORRENTZIP, 1), $zip->status === ZipArchive::ER_OK);
19+
var_dump($zip->addFile(__FILE__, "test.php"));
20+
$zip->close();
21+
22+
echo "\nOpen read\n";
23+
$zip->open($name, ZipArchive::RDONLY);
24+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_IS_TORRENTZIP));
25+
$zip->close();
26+
?>
27+
--CLEAN--
28+
<?php
29+
$name = __DIR__ . '/torrent.zip';
30+
@unlink($name);
31+
?>
32+
--EXPECTF--
33+
Open write
34+
int(0)
35+
bool(true)
36+
bool(true)
37+
bool(true)
38+
39+
Open read
40+
int(1)

0 commit comments

Comments
 (0)