unlink_variation1-win32.phpt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. Test unlink() function : usage variations - unlinking file in a directory
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) != 'WIN') {
  6. die('skip only on Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Delete file having default permission but its dir having readonly permission
  12. Delete file having readonly permission but dir having default permission
  13. */
  14. $file_path = __DIR__;
  15. // temp dir name used here
  16. $dirname = "$file_path/unlink_variation1";
  17. // temp filename used here
  18. $filename = "$dirname/unlink_variation1-win32.tmp";
  19. echo "\n*** Testing unlink() on file inside a directory ***\n";
  20. // create temp dir
  21. mkdir($dirname);
  22. // create temp file inside $dirname
  23. $fp = fopen($filename, "w");
  24. fclose($fp);
  25. echo "-- Unlink file having default permission and its dir having read only permission --\n";
  26. // remove write permission of $dirname
  27. // on windows dir permission is not respected
  28. var_dump( chmod($dirname, 0444) );
  29. // now try deleting $filename
  30. var_dump( unlink($filename) ); // expected: true
  31. var_dump( file_exists($filename) ); // confirm file is deleted
  32. // remove the dir
  33. var_dump( chmod($dirname, 0777) );
  34. rmdir($dirname);
  35. echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
  36. // create the temp dir
  37. mkdir($dirname);
  38. // create the temp file
  39. $fp = fopen($filename, "w");
  40. fclose($fp);
  41. // remove write permission from file
  42. var_dump( chmod($filename, 0444) );
  43. // now try deleting temp file inside $dirname
  44. var_dump( unlink($filename) ); // expected: false
  45. // reassign write permission to temp file
  46. chmod($filename, 0777);
  47. // delete temp file
  48. var_dump( unlink($filename) );
  49. var_dump( file_exists($filename) ); // confirm file is deleted
  50. // remove temp dir
  51. rmdir($dirname);
  52. echo "Done\n";
  53. ?>
  54. --EXPECTF--
  55. *** Testing unlink() on file inside a directory ***
  56. -- Unlink file having default permission and its dir having read only permission --
  57. bool(true)
  58. bool(true)
  59. bool(false)
  60. bool(true)
  61. -- Unlinking file without write permission, its dir having default permission --
  62. bool(true)
  63. Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d
  64. bool(false)
  65. bool(true)
  66. bool(false)
  67. Done