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