xref: /PHP-8.0/ext/zip/tests/oo_addfile.phpt (revision 682e2f6c)
1--TEST--
2ziparchive::addFile() function
3--SKIPIF--
4<?php
5if(!extension_loaded('zip')) die('skip');
6?>
7--FILE--
8<?php
9
10$dirname = __DIR__ . '/';
11include $dirname . 'utils.inc';
12$file = $dirname . 'oo_addfile.zip';
13
14copy($dirname . 'test.zip', $file);
15
16$zip = new ZipArchive;
17if (!$zip->open($file)) {
18    exit('failed');
19}
20var_dump($zip->lastId);
21if (!$zip->addFile($dirname . 'utils.inc', 'test.php')) {
22    echo "failed\n";
23}
24var_dump($zip->lastId);
25if (!$zip->addFile($dirname . 'utils.inc', 'mini.txt', 12, 34)) {
26    echo "failed\n";
27}
28var_dump($zip->lastId);
29if ($zip->status == ZIPARCHIVE::ER_OK) {
30    if (!verify_entries($zip, [
31        "bar",
32        "foobar/",
33        "foobar/baz",
34        "entry1.txt",
35        "test.php",
36        "mini.txt"
37    ])) {
38        echo "failed\n";
39    } else {
40        echo "OK\n";
41    }
42    $zip->close();
43} else {
44    echo "failed\n";
45}
46if (!$zip->open($file)) {
47    exit('failed');
48}
49var_dump(strlen($zip->getFromName('test.php')) == filesize($dirname . 'utils.inc'));
50var_dump(strlen($zip->getFromName('mini.txt')) == 34);
51@unlink($file);
52?>
53--EXPECT--
54int(-1)
55int(4)
56int(5)
57OK
58bool(true)
59bool(true)
60