Skip to content

Commit

Permalink
more tests for zip with libzip 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Jun 27, 2023
1 parent 961e57e commit 1358b43
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ext/zip/tests/oo_close_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
Close empty file behavior
--EXTENSIONS--
zip
--SKIPIF--
<?php
if (version_compare(ZipArchive::LIBZIP_VERSION, '1.10.0', '<')) die('skip libzip < 1.10.0');
?>
--FILE--
<?php
$name = __DIR__ . '/oo_close_empty.zip';

function run($name, $keep) {
copy(__DIR__ . '/test.zip', $name);

$zip = new ZipArchive();
$zip->open($name, ZIPARCHIVE::CREATE);
if ($keep) {
echo "\nClose and keep\n";
var_dump($zip->setArchiveFlag(ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE, 1), $zip->status === ZipArchive::ER_OK);
} else {
echo "Close and delete\n";
}
var_dump($zip->getArchiveFlag(ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE));
for($i=$zip->numFiles ; $i ;) {
$zip->deleteIndex(--$i);
}
$zip->close();
var_dump(file_exists($name));
}
run($name, false);
run($name, true);
?>
--CLEAN--
<?php
$name = __DIR__ . '/oo_close_empty.zip';
@unlink($name);
?>
--EXPECTF--
Close and delete
int(0)
bool(false)

Close and keep
bool(true)
bool(true)
int(1)
bool(true)
40 changes: 40 additions & 0 deletions ext/zip/tests/oo_torrentzip.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
torrentzip format support
--EXTENSIONS--
zip
--SKIPIF--
<?php
if (version_compare(ZipArchive::LIBZIP_VERSION, '1.10.0', '<')) die('skip libzip < 1.10.0');
?>
--FILE--
<?php
$name = __DIR__ . '/torrent.zip';

$zip = new ZipArchive();

echo "Open write\n";
$zip->open($name, ZIPARCHIVE::CREATE);
var_dump($zip->getArchiveFlag(ZipArchive::AFL_IS_TORRENTZIP));
var_dump($zip->setArchiveFlag(ZipArchive::AFL_WANT_TORRENTZIP, 1), $zip->status === ZipArchive::ER_OK);
var_dump($zip->addFile(__FILE__, "test.php"));
$zip->close();

echo "\nOpen read\n";
$zip->open($name, ZipArchive::RDONLY);
var_dump($zip->getArchiveFlag(ZipArchive::AFL_IS_TORRENTZIP));
$zip->close();
?>
--CLEAN--
<?php
$name = __DIR__ . '/torrent.zip';
@unlink($name);
?>
--EXPECTF--
Open write
int(0)
bool(true)
bool(true)
bool(true)

Open read
int(1)

0 comments on commit 1358b43

Please sign in to comment.