xref: /PHP-8.0/ext/zip/tests/oo_addpattern.phpt (revision 682e2f6c)
1--TEST--
2ZipArchive::addPattern() method
3--CREDITS--
4Sammy Kaye Powers <sammyk@sammykmedia.com>
5w/Kenzo over the shoulder
6#phptek Chicago 2014
7--SKIPIF--
8<?php
9if(!extension_loaded('zip')) die('skip');
10?>
11--FILE--
12<?php
13include __DIR__ . '/utils.inc';
14
15$dirname = __DIR__ . '/oo_addpattern_dir/';
16$file = $dirname . 'tmp.zip';
17
18@mkdir($dirname);
19copy(__DIR__ . '/test.zip', $file);
20touch($dirname . 'foo.txt');
21touch($dirname . 'bar.txt');
22
23$zip = new ZipArchive();
24if (!$zip->open($file)) {
25        exit('failed');
26}
27$dir = realpath($dirname);
28$options = array('add_path' => 'baz/', 'remove_path' => $dir);
29if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
30    echo "failed 1\n";
31}
32$options['flags'] = 0; // clean FL_OVERWRITE
33if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
34    var_dump($zip->getStatusString());
35}
36$options['flags'] = ZipArchive::FL_OVERWRITE;
37if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
38    echo "failed 2\n";
39}
40
41if ($zip->status == ZIPARCHIVE::ER_OK) {
42        if (!verify_entries($zip, [
43            "bar",
44            "foobar/",
45            "foobar/baz",
46            "entry1.txt",
47            "baz/foo.txt",
48            "baz/bar.txt"
49        ])) {
50            echo "failed\n";
51        } else {
52            echo "OK";
53        }
54        $zip->close();
55} else {
56        echo "failed3\n";
57}
58?>
59--CLEAN--
60<?php
61$dirname = __DIR__ . '/oo_addpattern_dir/';
62unlink($dirname . 'tmp.zip');
63unlink($dirname . 'foo.txt');
64unlink($dirname . 'bar.txt');
65rmdir($dirname);
66?>
67--EXPECT--
68string(19) "File already exists"
69OK
70