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