xref: /PHP-8.2/ext/zip/tests/oo_namelocate.phpt (revision 74859783)
1--TEST--
2Locate entries by name
3--EXTENSIONS--
4zip
5--FILE--
6<?php
7$dirname = __DIR__ . '/';
8include $dirname . 'utils.inc';
9$file = $dirname . 'oo_namelocate.zip';
10
11@unlink($file);
12
13$zip = new ZipArchive;
14if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
15    exit('failed');
16}
17
18$zip->addFromString('entry1.txt', 'entry #1');
19$zip->addFromString('entry2.txt', 'entry #2');
20$zip->addFromString('dir/entry2d.txt', 'entry #2');
21
22if (!$zip->status == ZIPARCHIVE::ER_OK) {
23    echo "failed to write zip\n";
24}
25$zip->close();
26
27if (!$zip->open($file)) {
28    exit('failed');
29}
30
31
32var_dump($zip->locateName('entry1.txt'));
33var_dump($zip->locateName('eNtry2.txt'));
34var_dump($zip->locateName('eNtry2.txt', ZIPARCHIVE::FL_NOCASE));
35var_dump($zip->locateName('enTRy2d.txt', ZIPARCHIVE::FL_NOCASE|ZIPARCHIVE::FL_NODIR));
36$zip->close();
37
38?>
39--EXPECT--
40int(0)
41bool(false)
42int(1)
43int(2)
44--CLEAN--
45<?php
46unlink(__DIR__ . '/oo_namelocate.zip');
47?>
48