xref: /PHP-8.1/ext/zip/tests/oo_setcomment.phpt (revision 74859783)
1--TEST--
2setComment
3--EXTENSIONS--
4zip
5--FILE--
6<?php
7$dirname = __DIR__ . '/';
8include $dirname . 'utils.inc';
9$file = $dirname . 'oo_setcomment.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$zip->addFromString('entry4.txt', 'entry #1');
22var_dump($zip->setCommentIndex($zip->lastId, 'entry4.txt'));
23$zip->addFromString('entry5.txt', 'entry #2');
24var_dump($zip->setCommentIndex($zip->lastId, 'entry5.txt'));
25
26
27var_dump($zip->setCommentName('entry1.txt', 'entry1.txt'));
28var_dump($zip->setCommentName('entry2.txt', 'entry2.txt'));
29var_dump($zip->setCommentName('dir/entry2d.txt', 'dir/entry2d.txt'));
30var_dump($zip->setArchiveComment('archive'));
31
32var_dump($zip->setArchiveComment('archive'));
33
34if (!$zip->status == ZIPARCHIVE::ER_OK) {
35    echo "failed to write zip\n";
36}
37$zip->close();
38
39if (!$zip->open($file)) {
40    @unlink($file);
41    exit('failed');
42}
43
44var_dump($zip->getCommentIndex(0));
45var_dump($zip->getCommentIndex(1));
46var_dump($zip->getCommentIndex(2));
47var_dump($zip->getCommentIndex(3));
48var_dump($zip->getCommentIndex(4));
49var_dump($zip->getArchiveComment());
50
51$zip->close();
52@unlink($file);
53
54?>
55--EXPECT--
56bool(true)
57bool(true)
58bool(true)
59bool(true)
60bool(true)
61bool(true)
62bool(true)
63string(10) "entry1.txt"
64string(10) "entry2.txt"
65string(15) "dir/entry2d.txt"
66string(10) "entry4.txt"
67string(10) "entry5.txt"
68string(7) "archive"
69