xref: /PHP-8.0/ext/zip/tests/oo_replacefile.phpt (revision 682e2f6c)
1--TEST--
2ziparchive::replaceFile() 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_replacefile.zip';
13
14copy($dirname . 'test.zip', $file);
15
16$zip = new ZipArchive;
17if (!$zip->open($file)) {
18    exit('open failed');
19}
20if ($zip->replaceFile($dirname . 'utils.inc', 5)) {
21    echo "replace 5 succeed\n";
22}
23if (!$zip->replaceFile($dirname . 'utils.inc', 0)) {
24    echo "replace 0 failed\n";
25}
26if (!$zip->replaceFile($dirname . 'utils.inc', 2, 12, 42)) {
27    echo "replace 2 failed\n";
28}
29if ($zip->status == ZIPARCHIVE::ER_OK) {
30    if (!verify_entries($zip, [
31        "bar",
32        "foobar/",
33        "foobar/baz",
34        "entry1.txt",
35    ])) {
36        echo "verify failed\n";
37    } else {
38        echo "OK\n";
39    }
40    $zip->close();
41} else {
42    echo "failed\n";
43}
44if (!$zip->open($file)) {
45    exit('re-open failed');
46}
47var_dump(strlen($zip->getFromName('bar')) == filesize($dirname . 'utils.inc'));
48var_dump(strlen($zip->getFromName('foobar/baz')) == 42);
49@unlink($file);
50?>
51--EXPECT--
52OK
53bool(true)
54bool(true)
55