xref: /PHP-8.3/ext/zip/tests/oo_setmtime.phpt (revision 74859783)
1--TEST--
2setMtime
3--EXTENSIONS--
4zip
5--SKIPIF--
6<?php
7/* $Id$ */
8if (!method_exists('ZipArchive', 'setMtimeName')) die('skip libzip too old');
9?>
10--INI--
11date.timezone=UTC
12--FILE--
13<?php
14$dirname = dirname(__FILE__) . '/';
15include $dirname . 'utils.inc';
16$file = $dirname . '__tmp_oo_set_mtime.zip';
17
18@unlink($file);
19
20$zip = new ZipArchive;
21if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
22    exit('failed');
23}
24
25$zip->addFromString('foo', 'entry #1');
26$zip->addFromString('bar', 'entry #2');
27
28$t1 = mktime(0,0,0,12,25,2019);
29$t2 = mktime(0,0,0,14,7,2018);
30
31echo "Set 1\n";
32$s = $zip->statName('foo');
33var_dump($s['mtime'] > $t1);
34var_dump($zip->setMtimeName('foo', $t1));
35$s = $zip->statName('foo');
36// ONLY with 1.6.0 - var_dump($s['mtime'] ==  $t1);
37
38echo "Set 2\n";
39$s = $zip->statIndex(1);
40var_dump($s['mtime'] > $t2);
41var_dump($zip->setMtimeIndex(1, $t2));
42$s = $zip->statIndex(1);
43// ONLY with 1.6.0 - var_dump($s['mtime'] ==  $t2);
44
45if (!$zip->status == ZIPARCHIVE::ER_OK) {
46    echo "failed to write zip\n";
47}
48$zip->close();
49
50if (!$zip->open($file)) {
51    @unlink($file);
52    exit('failed');
53}
54
55echo "Get 1\n";
56$s = $zip->statIndex(0);
57var_dump($s['mtime'] ==  $t1);
58
59echo "Get 2\n";
60$s = $zip->statName('bar');
61var_dump($s['mtime'] ==  $t2);
62
63$zip->close();
64@unlink($file);
65
66?>
67--EXPECT--
68Set 1
69bool(true)
70bool(true)
71Set 2
72bool(true)
73bool(true)
74Get 1
75bool(true)
76Get 2
77bool(true)
78