xref: /PHP-8.0/ext/zip/tests/oo_addglob.phpt (revision 682e2f6c)
1--TEST--
2ZipArchive::addGlob() 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');
10if(!defined("GLOB_BRACE")) die ('skip');
11?>
12--FILE--
13<?php
14include __DIR__ . '/utils.inc';
15$dirname = __DIR__ . '/oo_addglob_dir/';
16$file = $dirname . 'tmp.zip';
17
18@mkdir($dirname);
19copy(__DIR__ . '/test.zip', $file);
20touch($dirname . 'foo.txt');
21touch($dirname . 'bar.baz');
22
23$zip = new ZipArchive();
24if (!$zip->open($file)) {
25        exit('failed');
26}
27$options = array('add_path' => 'baz/', 'remove_all_path' => TRUE);
28if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) {
29    echo "failed 1\n";
30}
31if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) {
32    echo "failed 2\n";
33}
34$options['flags'] = 0; // clean FL_OVERWRITE
35if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) {
36    var_dump($zip->getStatusString());
37}
38$options['flags'] = ZipArchive::FL_OVERWRITE;
39if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) {
40    echo "failed 3\n";
41}
42if ($zip->status == ZIPARCHIVE::ER_OK) {
43        if (!verify_entries($zip, [
44            "bar",
45            "foobar/",
46            "foobar/baz",
47            "entry1.txt",
48            "baz/foo.txt",
49            "baz/bar.baz"
50        ])) {
51            echo "failed\n";
52        } else {
53            echo "OK";
54        }
55        $zip->close();
56} else {
57        echo "failed 4\n";
58}
59?>
60--CLEAN--
61<?php
62$dirname = __DIR__ . '/oo_addglob_dir/';
63unlink($dirname . 'tmp.zip');
64unlink($dirname . 'foo.txt');
65unlink($dirname . 'bar.baz');
66rmdir($dirname);
67?>
68--EXPECT--
69string(19) "File already exists"
70OK
71