xref: /PHP-8.3/ext/zip/tests/oo_delete.phpt (revision 74859783)
1--TEST--
2Delete entries
3--EXTENSIONS--
4zip
5--FILE--
6<?php
7$dirname = __DIR__ . '/';
8$file = $dirname . 'oo_delete.zip';
9if (file_exists($file)) {
10    unlink($file);
11}
12
13$zip = new ZipArchive;
14if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
15    exit('failed');
16}
17$zip->addFromString('entry1.txt', 'entry #1');
18$zip->addFromString('entry2.txt', 'entry #2');
19$zip->addFromString('dir/entry2.txt', 'entry #2');
20
21if ($zip->status == ZIPARCHIVE::ER_OK) {
22    $zip->close();
23    echo "ok\n";
24} else {
25    var_dump($zip);
26    echo "failed\n";
27}
28
29if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
30    exit('failed');
31}
32
33if ($zip->deleteIndex(0)) {
34    echo "ok\n";
35}
36
37if ($zip->deleteName('entry2.txt')) {
38    echo "ok\n";
39} else {
40    echo "failed 3\n";
41}
42
43if ($zip->deleteName('dir/entry2.txt')) {
44    echo "ok\n";
45} else {
46    echo "failed 3\n";
47}
48
49if (!$zip->deleteIndex(123)) {
50    echo "ok\n";
51} else {
52    print_r($zip);
53    echo "failed\n";
54}
55
56
57$sb = $zip->statIndex(0);
58var_dump($sb);
59$sb = $zip->statIndex(1);
60var_dump($sb);
61$sb = $zip->statIndex(2);
62var_dump($sb);
63// suppress irrelevant error message:
64@$zip->close();
65unset($zip);
66
67if (file_exists($file)) {
68    unlink($file);
69}
70?>
71--EXPECT--
72ok
73ok
74ok
75ok
76ok
77bool(false)
78bool(false)
79bool(false)
80