1--TEST--
2Test touch() function : basic functionality
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if (substr(PHP_OS, 0, 3) != 'WIN') {
8    die('skip.. only for Windows');
9}
10?>
11--FILE--
12<?php
13/* Prototype  : proto bool touch(string filename [, int time [, int atime]])
14 * Description: Set modification time of file
15 * Source code: ext/standard/filestat.c
16 * Alias to functions:
17 */
18
19echo "*** Testing touch() : basic functionality ***\n";
20
21$filename = dirname(__FILE__)."/touch_私はガラスを食べられます.dat";
22
23echo "\n--- testing touch creates a file ---\n";
24@unlink($filename);
25if (file_exists($filename)) {
26   die("touch_basic failed");
27}
28var_dump( touch($filename) );
29if (file_exists($filename) == false) {
30   die("touch_basic failed");
31}
32
33echo "\n --- testing touch doesn't alter file contents ---\n";
34$testln = "Here is a test line";
35$h = fopen($filename, "wb");
36fwrite($h, $testln);
37fclose($h);
38touch($filename);
39$h = fopen($filename, "rb");
40echo fgets($h);
41fclose($h);
42
43echo "\n\n --- testing touch alters the correct file metadata ---\n";
44$init_meta = stat($filename);
45clearstatcache();
46sleep(1);
47touch($filename);
48$next_meta = stat($filename);
49$type = array("dev", "ino", "mode", "nlink", "uid", "gid",
50              "rdev", "size", "atime", "mtime", "ctime",
51              "blksize", "blocks");
52
53for ($i = 0; $i < count($type); $i++) {
54   if ($init_meta[$i] != $next_meta[$i]) {
55      echo "stat data differs at $type[$i]\n";
56   }
57}
58
59
60// Initialise all required variables
61$time = 10000;
62$atime = 20470;
63
64// Calling touch() with all possible arguments
65echo "\n --- testing touch using all parameters ---\n";
66var_dump( touch($filename, $time, $atime) );
67clearstatcache();
68$init_meta = stat($filename);
69echo "ctime=".$init_meta['ctime']."\n";
70echo "mtime=".$init_meta['mtime']."\n";
71echo "atime=".$init_meta['atime']."\n";
72
73unlink($filename);
74
75echo "Done";
76?>
77--EXPECTF--
78*** Testing touch() : basic functionality ***
79
80--- testing touch creates a file ---
81bool(true)
82
83 --- testing touch doesn't alter file contents ---
84Here is a test line
85
86 --- testing touch alters the correct file metadata ---
87stat data differs at atime
88stat data differs at mtime
89
90 --- testing touch using all parameters ---
91bool(true)
92ctime=%d
93mtime=10000
94atime=20470
95Done
96