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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
--TEST--
Test touch() function : variation: various valid and invalid paths
--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 : bool touch(string filename [, int time [, int atime]])
* Description: Set modification time of file
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
$workDir = "touchVar5.tmp";
$subDirOrFile = "aSubDirOrFile";
$cwd = __DIR__;
chdir($cwd);
if (!mkdir($cwd . '/' . $workDir)) die("cannot create directory $workDir");
$paths = array(
// relative
$workDir.'/'.$subDirOrFile,
'./'.$workDir.'/'.$subDirOrFile,
$workDir.'/../'.$workDir.'/'.$subDirOrFile,
// relative bad path (note p8 msgs differ)
$workDir.'/../BADDIR/'.$subDirOrFile,
'BADDIR/'.$subDirOrFile,
//absolute
$cwd.'/'.$workDir.'/'.$subDirOrFile,
$cwd.'/./'.$workDir.'/'.$subDirOrFile,
$cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDirOrFile,
//absolute bad path (note p8 msgs differ)
$cwd.'/BADDIR/'.$subDirOrFile,
//trailing separators
$workDir.'/'.$subDirOrFile.'/',
$cwd.'/'.$workDir.'/'.$subDirOrFile.'/',
// multiple separators
$workDir.'//'.$subDirOrFile,
$cwd.'//'.$workDir.'//'.$subDirOrFile,
);
echo "*** Testing touch() : variation ***\n";
echo "\n*** testing nonexisting paths ***\n";
test_nonexisting($paths);
echo "\n*** testing existing files ***\n";
test_existing($paths, false);
echo "\n*** testing existing directories ***\n";
test_existing($paths, true);
rmdir($workDir);
function test_nonexisting($paths) {
foreach($paths as $path) {
echo "--- testing $path ---\n";
if (is_dir($path) || is_file($path)) {
echo "FAILED: $path - exists\n";
}
else {
$res = touch($path);
if ($res === true) {
// something was created
if (file_exists($path)) {
// something found
if (is_dir($path)) {
echo "FAILED: $path - unexpected directory\n";
}
else {
echo "PASSED: $path - created\n";
unlink($path);
}
}
else {
// nothing found
echo "FAILED: $path - touch returned true, nothing there\n";
}
}
else {
// nothing created
if (file_exists($path)) {
//something found
echo "FAILED: $path - touch returned false, something there\n";
if (is_dir($path)) {
rmdir($path);
}
else {
unlink($path);
}
}
}
}
}
}
function test_existing($paths, $are_dirs) {
foreach($paths as $path) {
if ($are_dirs) {
$res = @mkdir($path);
if ($res == true) {
test_path($path);
rmdir($path);
}
}
else {
$h = @fopen($path,"w");
if ($h !== false) {
fclose($h);
test_path($path);
unlink($path);
}
}
}
}
function test_path($path) {
echo "--- testing $path ---\n";
$org_atime = get_atime($path);
clearstatcache();
$res = touch($path,0,0);
$next_atime = get_atime($path);
if ($next_atime == $org_atime) {
echo "FAILED: $path - access time not changed\n";
}
else {
echo "PASSED: $path - touched\n";
}
}
function get_atime($path) {
$temp = stat($path);
return $temp['atime'];
}
?>
===DONE===
--EXPECTF--
*** Testing touch() : variation ***
*** testing nonexisting paths ***
--- testing touchVar5.tmp/aSubDirOrFile ---
PASSED: touchVar5.tmp/aSubDirOrFile - created
--- testing ./touchVar5.tmp/aSubDirOrFile ---
PASSED: ./touchVar5.tmp/aSubDirOrFile - created
--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile ---
PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created
--- testing touchVar5.tmp/../BADDIR/aSubDirOrFile ---
Warning: touch(): Unable to create file touchVar5.tmp/../BADDIR/aSubDirOrFile because %s in %s on line %d
--- testing BADDIR/aSubDirOrFile ---
Warning: touch(): Unable to create file BADDIR/aSubDirOrFile because %s in %s on line %d
--- testing %s/touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/touchVar5.tmp/aSubDirOrFile - created
--- testing %s/./touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/./touchVar5.tmp/aSubDirOrFile - created
--- testing %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created
--- testing %s/BADDIR/aSubDirOrFile ---
Warning: touch(): Unable to create file %s/BADDIR/aSubDirOrFile because %s in %s on line %d
--- testing touchVar5.tmp/aSubDirOrFile/ ---
Warning: touch(): Unable to create file touchVar5.tmp/aSubDirOrFile/ because Invalid argument in %s on line %d
--- testing %s/touchVar5.tmp/aSubDirOrFile/ ---
Warning: touch(): Unable to create file %s/touchVar5.tmp/aSubDirOrFile/ because Invalid argument in %s on line %d
--- testing touchVar5.tmp//aSubDirOrFile ---
PASSED: touchVar5.tmp//aSubDirOrFile - created
--- testing %s//touchVar5.tmp//aSubDirOrFile ---
PASSED: %s//touchVar5.tmp//aSubDirOrFile - created
*** testing existing files ***
--- testing touchVar5.tmp/aSubDirOrFile ---
PASSED: touchVar5.tmp/aSubDirOrFile - touched
--- testing ./touchVar5.tmp/aSubDirOrFile ---
PASSED: ./touchVar5.tmp/aSubDirOrFile - touched
--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile ---
PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched
--- testing %s/touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/touchVar5.tmp/aSubDirOrFile - touched
--- testing %s/./touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/./touchVar5.tmp/aSubDirOrFile - touched
--- testing %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched
--- testing touchVar5.tmp//aSubDirOrFile ---
PASSED: touchVar5.tmp//aSubDirOrFile - touched
--- testing %s//touchVar5.tmp//aSubDirOrFile ---
PASSED: %s//touchVar5.tmp//aSubDirOrFile - touched
*** testing existing directories ***
--- testing touchVar5.tmp/aSubDirOrFile ---
PASSED: touchVar5.tmp/aSubDirOrFile - touched
--- testing ./touchVar5.tmp/aSubDirOrFile ---
PASSED: ./touchVar5.tmp/aSubDirOrFile - touched
--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile ---
PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched
--- testing %s/touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/touchVar5.tmp/aSubDirOrFile - touched
--- testing %s/./touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/./touchVar5.tmp/aSubDirOrFile - touched
--- testing %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile ---
PASSED: %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched
--- testing touchVar5.tmp/aSubDirOrFile/ ---
PASSED: touchVar5.tmp/aSubDirOrFile/ - touched
--- testing %s/touchVar5.tmp/aSubDirOrFile/ ---
PASSED: %s/touchVar5.tmp/aSubDirOrFile/ - touched
--- testing touchVar5.tmp//aSubDirOrFile ---
PASSED: touchVar5.tmp//aSubDirOrFile - touched
--- testing %s//touchVar5.tmp//aSubDirOrFile ---
PASSED: %s//touchVar5.tmp//aSubDirOrFile - touched
===DONE===
|