summaryrefslogtreecommitdiff
path: root/ext/zip/tests/oo_addemptydir.phpt
blob: 901af852010c7c89ff360297e1c550d895486d35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--TEST--
ziparchive::addEmptyDir
--SKIPIF--
<?php
if(!extension_loaded('zip')) die('skip');
?>
--FILE--
<?php

$dirname = __DIR__ . '/';
include $dirname . 'utils.inc';
$file = $dirname . 'oo_addemptydir.zip';

copy($dirname . 'test.zip', $file);

$zip = new ZipArchive;
if (!$zip->open($file)) {
    exit('failed');
}

var_dump($zip->lastId); // -1 (nothing added)
$zip->addEmptyDir('emptydir');
var_dump($zip->lastId); // 4
$zip->addEmptyDir('emptydir');
var_dump($zip->lastId); // -1 (already exists)
$zip->addEmptyDir('emptydir', ZipArchive::FL_OVERWRITE);
var_dump($zip->lastId); // 4
if ($zip->status == ZIPARCHIVE::ER_OK) {
    if (!verify_entries($zip, [
        "bar",
        "foobar/",
        "foobar/baz",
        "entry1.txt",
        "emptydir/"
    ])) {
        echo "failed\n";
    } else {
        echo "OK";
    }
    $zip->close();
} else {
    echo "failed3\n";
}
@unlink($file);
?>
--EXPECT--
int(-1)
int(4)
int(-1)
int(4)
OK