006_variation2.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. --TEST--
  2. Test fileperms() & chmod() functions: usage variation - misc. perms
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip Not on Windows');
  7. }
  8. // Skip if being run by root
  9. $filename = dirname(__FILE__)."/006_root_check.tmp";
  10. $fp = fopen($filename, 'w');
  11. fclose($fp);
  12. if(fileowner($filename) == 0) {
  13. unlink ($filename);
  14. die('skip cannot be run as root');
  15. }
  16. unlink($filename);
  17. ?>
  18. --FILE--
  19. <?php
  20. /*
  21. Prototype: int fileperms ( string $filename );
  22. Description: Returns the permissions on the file, or FALSE in case of an error
  23. Prototype: bool chmod ( string $filename, int $mode );
  24. Description: Attempts to change the mode of the file specified by
  25. filename to that given in mode
  26. */
  27. /* Testing with miscellaneous Permission */
  28. echo "*** Testing fileperms() & chmod() : usage variations ***\n";
  29. $file_name = dirname(__FILE__)."/006_variation2.tmp";
  30. $file_handle = fopen($file_name, "w");
  31. fclose($file_handle);
  32. $dir_name = dirname(__FILE__)."/006_variation2";
  33. mkdir($dir_name);
  34. echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
  35. $perms_array = array(
  36. /* testing sticky bit */
  37. 07777,
  38. 00000,
  39. 01000,
  40. 011111,
  41. /* negative values as permission */
  42. -0777, // permissions will be given as 2's complement form of -0777
  43. -07777, // permissions will be given as 2's complement form of -07777
  44. /* decimal values as permission */
  45. 777, // permissions will be given as octal equivalent value of 777
  46. 7777, // permissions will be given as octal equivalent value of 7777
  47. -7777, // permissions are given as 2's complement of octal equivalent of 7777
  48. /* hex value as permission */
  49. 0x777, // permissions will be given as ocatal equivalent value of 0x777
  50. 0x7777,
  51. /* strings notation of permission, wont work properly */
  52. "r+w",
  53. "r+w+x",
  54. "u+rwx",
  55. "u+rwx, g+rw, o+wx"
  56. );
  57. $count = 1;
  58. foreach($perms_array as $permission) {
  59. echo "-- Iteration $count --\n";
  60. var_dump( chmod($file_name, $permission) );
  61. printf("%o", fileperms($file_name) );
  62. echo "\n";
  63. clearstatcache();
  64. var_dump( chmod($dir_name, $permission) );
  65. printf("%o", fileperms($dir_name) );
  66. echo "\n";
  67. clearstatcache();
  68. $count++;
  69. }
  70. echo "*** Done ***\n";
  71. ?>
  72. --CLEAN--
  73. <?php
  74. chmod(dirname(__FILE__)."/006_variation2.tmp", 0777);
  75. chmod(dirname(__FILE__)."/006_variation2", 0777);
  76. unlink(dirname(__FILE__)."/006_variation2.tmp");
  77. rmdir(dirname(__FILE__)."/006_variation2");
  78. ?>
  79. --EXPECTF--
  80. *** Testing fileperms() & chmod() : usage variations ***
  81. *** Testing fileperms(), chmod() with miscellaneous permissions ***
  82. -- Iteration 1 --
  83. bool(true)
  84. 107777
  85. bool(true)
  86. 47777
  87. -- Iteration 2 --
  88. bool(true)
  89. 100000
  90. bool(true)
  91. 40000
  92. -- Iteration 3 --
  93. bool(true)
  94. 101000
  95. bool(true)
  96. 41000
  97. -- Iteration 4 --
  98. bool(true)
  99. 101111
  100. bool(true)
  101. 41111
  102. -- Iteration 5 --
  103. bool(true)
  104. 107001
  105. bool(true)
  106. 47001
  107. -- Iteration 6 --
  108. bool(true)
  109. 100001
  110. bool(true)
  111. 40001
  112. -- Iteration 7 --
  113. bool(true)
  114. 101411
  115. bool(true)
  116. 41411
  117. -- Iteration 8 --
  118. bool(true)
  119. 107141
  120. bool(true)
  121. 47141
  122. -- Iteration 9 --
  123. bool(true)
  124. 100637
  125. bool(true)
  126. 40637
  127. -- Iteration 10 --
  128. bool(true)
  129. 103567
  130. bool(true)
  131. 43567
  132. -- Iteration 11 --
  133. bool(true)
  134. 103567
  135. bool(true)
  136. 43567
  137. -- Iteration 12 --
  138. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  139. NULL
  140. 103567
  141. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  142. NULL
  143. 43567
  144. -- Iteration 13 --
  145. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  146. NULL
  147. 103567
  148. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  149. NULL
  150. 43567
  151. -- Iteration 14 --
  152. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  153. NULL
  154. 103567
  155. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  156. NULL
  157. 43567
  158. -- Iteration 15 --
  159. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  160. NULL
  161. 103567
  162. Warning: chmod() expects parameter 2 to be long, string given in %s on line %d
  163. NULL
  164. 43567
  165. *** Done ***