1--TEST--
2Test touch() function : variation: various valid and invalid paths
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$workDir = "touchVar5.tmp";
14$subDirOrFile = "aSubDirOrFile";
15chdir(__DIR__);
16mkdir($workDir);
17$cwd = getcwd();
18
19$unixifiedDirOrFile = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$subDirOrFile, 3);
20
21$paths = array(
22             // relative
23             $workDir.'\\'.$subDirOrFile,
24             '.\\'.$workDir.'\\'.$subDirOrFile,
25             $workDir.'\\..\\'.$workDir.'\\'.$subDirOrFile,
26
27             // relative bad path (note p8 msgs differ)
28             $workDir.'\\..\\BADDIR\\'.$subDirOrFile,
29             'BADDIR\\'.$subDirOrFile,
30
31             //absolute
32             $cwd.'\\'.$workDir.'\\'.$subDirOrFile,
33             $cwd.'\\.\\'.$workDir.'\\'.$subDirOrFile,
34             $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$subDirOrFile,
35
36             //absolute bad path (note p8 msgs differ)
37             $cwd.'\\BADDIR\\'.$subDirOrFile,
38
39             //trailing separators
40             $workDir.'\\'.$subDirOrFile.'\\',
41             $cwd.'\\'.$workDir.'\\'.$subDirOrFile.'\\',
42
43             // multiple separators
44             $workDir.'\\\\'.$subDirOrFile,
45             $cwd.'\\\\'.$workDir.'\\\\'.$subDirOrFile,
46
47             // Unixified Dir Or File
48             $unixifiedDirOrFile,
49
50             );
51
52echo "*** Testing touch() : variation ***\n";
53
54echo "\n*** testing nonexisting paths ***\n";
55test_nonexisting($paths);
56
57echo "\n*** testing existing files ***\n";
58test_existing($paths, false);
59
60echo "\n*** testing existing directories ***\n";
61test_existing($paths, true);
62
63
64rmdir($workDir);
65
66
67
68function test_nonexisting($paths) {
69    foreach($paths as $path) {
70       echo "--- testing $path ---\n";
71
72       if (is_dir($path) || is_file($path)) {
73          echo "FAILED: $path - exists\n";
74       }
75       else {
76          $res = touch($path);
77          if ($res === true) {
78             // something was created
79             if (file_exists($path)) {
80                  // something found
81                  if (is_dir($path)) {
82                     echo "FAILED: $path - unexpected directory\n";
83                  }
84                  else {
85                     echo "PASSED: $path - created\n";
86                     unlink($path);
87                  }
88             }
89             else {
90                // nothing found
91                echo "FAILED: $path - touch returned true, nothing there\n";
92             }
93          }
94          else {
95             // nothing created
96             if (file_exists($path)) {
97                  //something found
98                  echo "FAILED: $path - touch returned false, something there\n";
99                  if (is_dir($path)) {
100                     rmdir($path);
101                  }
102                  else {
103                     unlink($path);
104                  }
105             }
106          }
107       }
108    }
109}
110
111function test_existing($paths, $are_dirs) {
112    foreach($paths as $path) {
113       if ($are_dirs) {
114          $res = @mkdir($path);
115          if ($res == true) {
116             test_path($path);
117             rmdir($path);
118          }
119       }
120       else {
121          $h = @fopen($path,"w");
122          if ($h !== false) {
123             fclose($h);
124             test_path($path);
125             unlink($path);
126          }
127       }
128    }
129}
130
131
132function test_path($path) {
133   echo "--- testing $path ---\n";
134   $org_atime = get_atime($path);
135   clearstatcache();
136   $res = touch($path,0,0);
137   $next_atime = get_atime($path);
138   if ($next_atime == $org_atime) {
139      echo "FAILED: $path - access time not changed\n";
140   }
141   else {
142      echo "PASSED: $path - touched\n";
143   }
144}
145
146function get_atime($path) {
147   $temp = stat($path);
148   return $temp['atime'];
149}
150
151
152?>
153--EXPECTF--
154*** Testing touch() : variation ***
155
156*** testing nonexisting paths ***
157--- testing touchVar5.tmp\aSubDirOrFile ---
158PASSED: touchVar5.tmp\aSubDirOrFile - created
159--- testing .\touchVar5.tmp\aSubDirOrFile ---
160PASSED: .\touchVar5.tmp\aSubDirOrFile - created
161--- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
162PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - created
163--- testing touchVar5.tmp\..\BADDIR\aSubDirOrFile ---
164
165Warning: touch(): Unable to create file touchVar5.tmp\..\BADDIR\aSubDirOrFile because %s in %s on line %d
166--- testing BADDIR\aSubDirOrFile ---
167
168Warning: touch(): Unable to create file BADDIR\aSubDirOrFile because %s in %s on line %d
169--- testing %s\touchVar5.tmp\aSubDirOrFile ---
170PASSED: %s\touchVar5.tmp\aSubDirOrFile - created
171--- testing %s\.\touchVar5.tmp\aSubDirOrFile ---
172PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - created
173--- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
174PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - created
175--- testing %s\BADDIR\aSubDirOrFile ---
176
177Warning: touch(): Unable to create file %s\BADDIR\aSubDirOrFile because %s in %s on line %d
178--- testing touchVar5.tmp\aSubDirOrFile\ ---
179
180Warning: touch(): Unable to create file touchVar5.tmp\aSubDirOrFile\ because %s in %s on line %d
181--- testing %s\touchVar5.tmp\aSubDirOrFile\ ---
182
183Warning: touch(): Unable to create file %s\touchVar5.tmp\aSubDirOrFile\ because %s in %s on line %d
184--- testing touchVar5.tmp\\aSubDirOrFile ---
185PASSED: touchVar5.tmp\\aSubDirOrFile - created
186--- testing %s\\touchVar5.tmp\\aSubDirOrFile ---
187PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - created
188--- testing /%s/touchVar5.tmp/aSubDirOrFile ---
189PASSED: /%s/touchVar5.tmp/aSubDirOrFile - created
190
191*** testing existing files ***
192--- testing touchVar5.tmp\aSubDirOrFile ---
193PASSED: touchVar5.tmp\aSubDirOrFile - touched
194--- testing .\touchVar5.tmp\aSubDirOrFile ---
195PASSED: .\touchVar5.tmp\aSubDirOrFile - touched
196--- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
197PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
198--- testing %s\touchVar5.tmp\aSubDirOrFile ---
199PASSED: %s\touchVar5.tmp\aSubDirOrFile - touched
200--- testing %s\.\touchVar5.tmp\aSubDirOrFile ---
201PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - touched
202--- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
203PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
204--- testing touchVar5.tmp\\aSubDirOrFile ---
205PASSED: touchVar5.tmp\\aSubDirOrFile - touched
206--- testing %s\\touchVar5.tmp\\aSubDirOrFile ---
207PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - touched
208--- testing /%s/touchVar5.tmp/aSubDirOrFile ---
209PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched
210
211*** testing existing directories ***
212--- testing touchVar5.tmp\aSubDirOrFile ---
213PASSED: touchVar5.tmp\aSubDirOrFile - touched
214--- testing .\touchVar5.tmp\aSubDirOrFile ---
215PASSED: .\touchVar5.tmp\aSubDirOrFile - touched
216--- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
217PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
218--- testing %s\touchVar5.tmp\aSubDirOrFile ---
219PASSED: %s\touchVar5.tmp\aSubDirOrFile - touched
220--- testing %s\.\touchVar5.tmp\aSubDirOrFile ---
221PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - touched
222--- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile ---
223PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched
224--- testing touchVar5.tmp\aSubDirOrFile\ ---
225PASSED: touchVar5.tmp\aSubDirOrFile\ - touched
226--- testing %s\touchVar5.tmp\aSubDirOrFile\ ---
227PASSED: %s\touchVar5.tmp\aSubDirOrFile\ - touched
228--- testing touchVar5.tmp\\aSubDirOrFile ---
229PASSED: touchVar5.tmp\\aSubDirOrFile - touched
230--- testing %s\\touchVar5.tmp\\aSubDirOrFile ---
231PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - touched
232--- testing /%s/touchVar5.tmp/aSubDirOrFile ---
233PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched
234