xref: /PHP-7.4/ext/zip/tests/oo_rename.phpt (revision e2e3ddac)
1--TEST--
2Rename entries
3--SKIPIF--
4<?php
5if(!extension_loaded('zip')) die('skip');
6?>
7--FILE--
8<?php
9$dirname = __DIR__ . '/';
10include $dirname . 'utils.inc';
11$file = $dirname . 'oo_rename.zip';
12
13@unlink($file);
14
15$zip = new ZipArchive;
16if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
17	exit('failed');
18}
19
20$zip->addFromString('entry1.txt', 'entry #1');
21$zip->addFromString('entry2.txt', 'entry #2');
22$zip->addFromString('dir/entry2.txt', 'entry #2');
23
24if (!$zip->status == ZIPARCHIVE::ER_OK) {
25	var_dump($zip);
26	echo "failed2\n";
27}
28
29$zip->close();
30
31if (!$zip->open($file)) {
32	exit('failed3');
33}
34
35if (!verify_entries($zip, [
36	"entry1.txt",
37    "entry2.txt",
38    "dir/entry2.txt"
39])) {
40	exit("failed4");
41} else {
42	echo "OK\n";
43}
44
45if (!$zip->renameIndex(0, 'ren_entry1.txt')) {
46	echo "failed index 0\n";
47}
48
49if (!$zip->renameName('dir/entry2.txt', 'dir3/ren_entry2.txt')) {
50	echo "failed name dir/entry2.txt\n";
51}
52
53if (!verify_entries($zip, [
54	"ren_entry1.txt",
55    "entry2.txt",
56    "dir3/ren_entry2.txt"
57])) {
58	exit("failed5");
59} else {
60	echo "OK\n";
61}
62$zip->close();
63
64@unlink($file);
65?>
66--EXPECT--
67OK
68OK
69