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