summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/touch_basic-win32-mb.phpt
blob: 9a87ac60a6d9e35f40f110725b189b0eed53c7df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
--TEST--
Test touch() function : basic functionality
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
    die('skip.. only for Windows');
}
?>
--FILE--
<?php
/* Prototype  : proto bool touch(string filename [, int time [, int atime]])
 * Description: Set modification time of file
 * Source code: ext/standard/filestat.c
 * Alias to functions:
 */

echo "*** Testing touch() : basic functionality ***\n";

$filename = dirname(__FILE__)."/touch_私はガラスを食べられます.dat";

echo "\n--- testing touch creates a file ---\n";
@unlink($filename);
if (file_exists($filename)) {
   die("touch_basic failed");
}
var_dump( touch($filename) );
if (file_exists($filename) == false) {
   die("touch_basic failed");
}

echo "\n --- testing touch doesn't alter file contents ---\n";
$testln = "Here is a test line";
$h = fopen($filename, "wb");
fwrite($h, $testln);
fclose($h);
touch($filename);
$h = fopen($filename, "rb");
echo fgets($h);
fclose($h);

echo "\n\n --- testing touch alters the correct file metadata ---\n";
$init_meta = stat($filename);
clearstatcache();
sleep(1);
touch($filename);
$next_meta = stat($filename);
$type = array("dev", "ino", "mode", "nlink", "uid", "gid",
              "rdev", "size", "atime", "mtime", "ctime",
              "blksize", "blocks");

for ($i = 0; $i < count($type); $i++) {
   if ($init_meta[$i] != $next_meta[$i]) {
      echo "stat data differs at $type[$i]\n";
   }
}


// Initialise all required variables
$time = 10000;
$atime = 20470;

// Calling touch() with all possible arguments
echo "\n --- testing touch using all parameters ---\n";
var_dump( touch($filename, $time, $atime) );
clearstatcache();
$init_meta = stat($filename);
echo "ctime=".$init_meta['ctime']."\n";
echo "mtime=".$init_meta['mtime']."\n";
echo "atime=".$init_meta['atime']."\n";

unlink($filename);

echo "Done";
?>
--EXPECTF--
*** Testing touch() : basic functionality ***

--- testing touch creates a file ---
bool(true)

 --- testing touch doesn't alter file contents ---
Here is a test line

 --- testing touch alters the correct file metadata ---
stat data differs at atime
stat data differs at mtime

 --- testing touch using all parameters ---
bool(true)
ctime=%d
mtime=10000
atime=20470
Done