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