xref: /PHP-7.3/ext/zip/tests/oo_addpattern.phpt (revision 0eabd523)
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
13$dirname = dirname(__FILE__) . '/';
14include $dirname . 'utils.inc';
15$file = $dirname . '__tmp_oo_addpattern.zip';
16
17copy($dirname . '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\n";
29}
30if ($zip->status == ZIPARCHIVE::ER_OK) {
31        dump_entries_name($zip);
32        $zip->close();
33} else {
34        echo "failed\n";
35}
36?>
37--CLEAN--
38<?php
39$dirname = dirname(__FILE__) . '/';
40unlink($dirname . '__tmp_oo_addpattern.zip');
41unlink($dirname . 'foo.txt');
42unlink($dirname . 'bar.txt');
43?>
44--EXPECT--
450 bar
461 foobar/
472 foobar/baz
483 entry1.txt
494 baz/bar.txt
505 baz/foo.txt
51