xref: /PHP-8.0/ext/zip/tests/oo_addglob2.phpt (revision 0dda242b)
1--TEST--
2ZipArchive::addGlob() method with more compression and encryption
3--SKIPIF--
4<?php
5if(!extension_loaded('zip')) die('skip');
6if (!method_exists('ZipArchive', 'setEncryptionName')) die('skip encrytion not supported');
7if(!defined("GLOB_BRACE")) die ('skip requires GLOB_BRACE');
8?>
9--FILE--
10<?php
11$dirname = __DIR__ . '/';
12include $dirname . 'utils.inc';
13
14$dirname = __DIR__ . '/__tmp_oo_addglob2/';
15$file = $dirname . 'test.zip';
16
17@mkdir($dirname);
18copy(__FILE__, $dirname . 'foo.txt');
19copy(__FILE__, $dirname . 'bar.txt');
20
21$zip = new ZipArchive();
22if (!$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
23        exit('failed');
24}
25$options = [
26    'remove_all_path' => true,
27];
28if (!$zip->addGlob($dirname . 'foo.*', GLOB_BRACE, $options)) {
29        echo "failed 1\n";
30}
31
32$options = [
33    'remove_all_path' => true,
34    'comp_method' => ZipArchive::CM_STORE,
35    'comp_flags' => 5,
36    'enc_method' => ZipArchive::EM_AES_256,
37    'enc_password' => 'secret',
38];
39if (!$zip->addGlob($dirname . 'bar.*', GLOB_BRACE, $options)) {
40        echo "failed 2\n";
41}
42if ($zip->status == ZIPARCHIVE::ER_OK) {
43        $zip->close();
44
45        $zip = new ZipArchive();
46        $zip->open($file);
47        for($i=0; $i<$zip->numFiles; $i++) {
48            $sb = $zip->statIndex($i);
49            echo "$i: " . $sb['name'] .
50                ", comp=" . $sb['comp_method'] .
51                ", enc="  . $sb['encryption_method'] . "\n";
52        }
53} else {
54        echo "failed 3\n";
55}
56?>
57--CLEAN--
58<?php
59$dirname = __DIR__ . '/';
60include $dirname . 'utils.inc';
61rmdir_rf(__DIR__ . '/__tmp_oo_addglob2/');
62?>
63--EXPECT--
640: foo.txt, comp=8, enc=0
651: bar.txt, comp=0, enc=259
66