Return to unlink_variation8.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test unlink() function : variation: various valid and invalid paths 3: --CREDITS-- 4: Dave Kelsey <d_kelsey@uk.ibm.com> 5: --SKIPIF-- 6: <?php 7: if (substr(PHP_OS, 0, 3) == 'WIN') { 8: die('skip.. Not 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: 19: echo "*** Testing unlink() : variation ***\n"; 20: 21: $workDir = "unlinkVar8.tmp"; 22: $tmpFile = "file.tmp"; 23: $fileToLinkTo = $workDir.'/'."linkme.tmp"; 24: 25: mkdir($workDir); 26: $cwd = getcwd(); 27: touch($fileToLinkTo); 28: 29: $files = array( 30: // relative 31: $workDir.'/'.$tmpFile, 32: './'.$workDir.'/'.$tmpFile, 33: $workDir.'/../'.$workDir.'/'.$tmpFile, 34: 35: // relative bad path 36: $workDir.'/../BADDIR/'.$tmpFile, 37: 'BADDIR/'.$tmpFile, 38: 39: //absolute 40: $cwd.'/'.$workDir.'/'.$tmpFile, 41: $cwd.'/./'.$workDir.'/'.$tmpFile, 42: $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpFile, 43: 44: //absolute bad path 45: $cwd.'/BADDIR/'.$tmpFile, 46: 47: //trailing separators 48: $workDir.'/'.$tmpFile.'/', 49: $cwd.'/'.$workDir.'/'.$tmpFile.'/', 50: 51: // multiple separators 52: $workDir.'//'.$tmpFile, 53: $cwd.'//'.$workDir.'//'.$tmpFile, 54: 55: ); 56: 57: 58: foreach($files as $fileToUnlink) { 59: test_realfile($workDir.'/'.$tmpFile, $fileToUnlink); 60: test_link($workDir.'/'.$tmpFile, $fileToLinkTo, $fileToUnlink, true); //soft link 61: test_link($workDir.'/'.$tmpFile, $fileToLinkTo, $fileToUnlink, false); //hard link 62: } 63: 64: unlink($fileToLinkTo); 65: rmdir($workDir); 66: 67: function test_realfile($file, $tounlink) { 68: touch($file); 69: echo "-- removing $tounlink --\n"; 70: $res = unlink($tounlink); 71: if ($res === true) { 72: if (file_exists($tounlink) === false) { 73: echo "file removed\n"; 74: } 75: else { 76: echo "FAILED: file not removed\n"; 77: } 78: } 79: else { 80: unlink($file); 81: } 82: } 83: 84: function test_link($linkedfile, $toLinkTo, $tounlink, $softlink) { 85: if ($softlink == true) { 86: symlink($toLinkTo, $linkedfile); 87: $msg = "soft link"; 88: } 89: else { 90: link($toLinkTo, $linkedfile); 91: $msg = "hard link"; 92: } 93: echo "-- unlinking $msg $tounlink --\n"; 94: $res = unlink($tounlink); 95: if ($res === true) { 96: if (file_exists($tounlink) === false) { 97: echo "file unlinked\n"; 98: } 99: else { 100: echo "FAILED: file not unlinked\n"; 101: } 102: } 103: else { 104: unlink($linkedfile); 105: } 106: } 107: 108: 109: ?> 110: ===DONE=== 111: --EXPECTF-- 112: *** Testing unlink() : variation *** 113: -- removing unlinkVar8.tmp/file.tmp -- 114: file removed 115: -- unlinking soft link unlinkVar8.tmp/file.tmp -- 116: file unlinked 117: -- unlinking hard link unlinkVar8.tmp/file.tmp -- 118: file unlinked 119: -- removing ./unlinkVar8.tmp/file.tmp -- 120: file removed 121: -- unlinking soft link ./unlinkVar8.tmp/file.tmp -- 122: file unlinked 123: -- unlinking hard link ./unlinkVar8.tmp/file.tmp -- 124: file unlinked 125: -- removing unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 126: file removed 127: -- unlinking soft link unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 128: file unlinked 129: -- unlinking hard link unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 130: file unlinked 131: -- removing unlinkVar8.tmp/../BADDIR/file.tmp -- 132: 133: Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d 134: -- unlinking soft link unlinkVar8.tmp/../BADDIR/file.tmp -- 135: 136: Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d 137: -- unlinking hard link unlinkVar8.tmp/../BADDIR/file.tmp -- 138: 139: Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d 140: -- removing BADDIR/file.tmp -- 141: 142: Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d 143: -- unlinking soft link BADDIR/file.tmp -- 144: 145: Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d 146: -- unlinking hard link BADDIR/file.tmp -- 147: 148: Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d 149: -- removing /%s/unlinkVar8.tmp/file.tmp -- 150: file removed 151: -- unlinking soft link /%s/unlinkVar8.tmp/file.tmp -- 152: file unlinked 153: -- unlinking hard link /%s/unlinkVar8.tmp/file.tmp -- 154: file unlinked 155: -- removing /%s/./unlinkVar8.tmp/file.tmp -- 156: file removed 157: -- unlinking soft link /%s/./unlinkVar8.tmp/file.tmp -- 158: file unlinked 159: -- unlinking hard link /%s/./unlinkVar8.tmp/file.tmp -- 160: file unlinked 161: -- removing /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 162: file removed 163: -- unlinking soft link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 164: file unlinked 165: -- unlinking hard link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- 166: file unlinked 167: -- removing /%s/BADDIR/file.tmp -- 168: 169: Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d 170: -- unlinking soft link /%s/BADDIR/file.tmp -- 171: 172: Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d 173: -- unlinking hard link /%s/BADDIR/file.tmp -- 174: 175: Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d 176: -- removing unlinkVar8.tmp/file.tmp/ -- 177: 178: Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d 179: -- unlinking soft link unlinkVar8.tmp/file.tmp/ -- 180: 181: Warning: unlink(unlinkVar8.tmp/file.tmp/): %s directory in %s on line %d 182: -- unlinking hard link unlinkVar8.tmp/file.tmp/ -- 183: 184: Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d 185: -- removing /%s/unlinkVar8.tmp/file.tmp/ -- 186: 187: Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d 188: -- unlinking soft link /%s/unlinkVar8.tmp/file.tmp/ -- 189: 190: Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): %s directory in %s on line %d 191: -- unlinking hard link /%s/unlinkVar8.tmp/file.tmp/ -- 192: 193: Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d 194: -- removing unlinkVar8.tmp//file.tmp -- 195: file removed 196: -- unlinking soft link unlinkVar8.tmp//file.tmp -- 197: file unlinked 198: -- unlinking hard link unlinkVar8.tmp//file.tmp -- 199: file unlinked 200: -- removing /%s//unlinkVar8.tmp//file.tmp -- 201: file removed 202: -- unlinking soft link /%s//unlinkVar8.tmp//file.tmp -- 203: file unlinked 204: -- unlinking hard link /%s//unlinkVar8.tmp//file.tmp -- 205: file unlinked 206: ===DONE===