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