1--TEST-- 2Test unlink() 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/* Prototype : bool unlink(string filename[, context context]) 14 * Description: Delete a file 15 * Source code: ext/standard/file.c 16 * Alias to functions: 17 */ 18 19echo "*** Testing unlink() : variation ***\n"; 20 21$workDir = "unlinkVar8.tmp"; 22$tmpFile = "file.tmp"; 23chdir(__DIR__); 24mkdir($workDir); 25$cwd = __DIR__; 26 27$files = array( 28 // relative 29 $workDir.'/'.$tmpFile, 30 './'.$workDir.'/'.$tmpFile, 31 $workDir.'/../'.$workDir.'/'.$tmpFile, 32 33 // relative bad path 34 $workDir.'/../BADDIR/'.$tmpFile, 35 'BADDIR/'.$tmpFile, 36 37 //absolute 38 $cwd.'/'.$workDir.'/'.$tmpFile, 39 $cwd.'/./'.$workDir.'/'.$tmpFile, 40 $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpFile, 41 42 //absolute bad path 43 $cwd.'/BADDIR/'.$tmpFile, 44 45 //trailing separators 46 $workDir.'/'.$tmpFile.'/', 47 $cwd.'/'.$workDir.'/'.$tmpFile.'/', 48 49 // multiple separators 50 $workDir.'//'.$tmpFile, 51 $cwd.'//'.$workDir.'//'.$tmpFile, 52 53 ); 54 55 56foreach($files as $fileToUnlink) { 57 test_realfile($workDir.'/'.$tmpFile, $fileToUnlink); 58} 59 60rmdir($workDir); 61 62function test_realfile($file, $tounlink) { 63 touch($file); 64 echo "-- removing $tounlink --\n"; 65 $res = unlink($tounlink); 66 if ($res === true) { 67 if (file_exists($tounlink) === false) { 68 echo "file removed\n"; 69 } 70 else { 71 echo "FAILED: file not removed\n"; 72 } 73 } 74 else { 75 unlink($file); 76 } 77} 78?> 79===DONE=== 80--EXPECTF-- 81*** Testing unlink() : variation *** 82-- removing unlinkVar8.tmp/file.tmp -- 83file removed 84-- removing ./unlinkVar8.tmp/file.tmp -- 85file removed 86-- removing unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 87file removed 88-- removing unlinkVar8.tmp/../BADDIR/file.tmp -- 89 90Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d 91-- removing BADDIR/file.tmp -- 92 93Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d 94-- removing %s/unlinkVar8.tmp/file.tmp -- 95file removed 96-- removing %s/./unlinkVar8.tmp/file.tmp -- 97file removed 98-- removing %s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 99file removed 100-- removing %s/BADDIR/file.tmp -- 101 102Warning: unlink(%s/BADDIR/file.tmp): No such file or directory in %s on line %d 103-- removing unlinkVar8.tmp/file.tmp/ -- 104 105Warning: unlink(unlinkVar8.tmp/file.tmp/): Invalid argument in %s on line %d 106-- removing %s/unlinkVar8.tmp/file.tmp/ -- 107 108Warning: unlink(%s/unlinkVar8.tmp/file.tmp/): Invalid argument in %s on line %d 109-- removing unlinkVar8.tmp//file.tmp -- 110file removed 111-- removing %s//unlinkVar8.tmp//file.tmp -- 112file removed 113===DONE=== 114