006_variation2.phpt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. require __DIR__ . '/../skipif_root.inc';
  9. ?>
  10. --FILE--
  11. <?php
  12. /* Testing with miscellaneous Permission */
  13. echo "*** Testing fileperms() & chmod() : usage variations ***\n";
  14. $file_name = __DIR__."/006_variation2.tmp";
  15. $file_handle = fopen($file_name, "w");
  16. fclose($file_handle);
  17. $dir_name = __DIR__."/006_variation2";
  18. mkdir($dir_name);
  19. echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
  20. $perms_array = array(
  21. /* testing sticky bit */
  22. 07777,
  23. 00000,
  24. 01000,
  25. 011111,
  26. /* negative values as permission */
  27. -0777, // permissions will be given as 2's complement form of -0777
  28. -07777, // permissions will be given as 2's complement form of -07777
  29. /* decimal values as permission */
  30. 777, // permissions will be given as octal equivalent value of 777
  31. 7777, // permissions will be given as octal equivalent value of 7777
  32. -7777, // permissions are given as 2's complement of octal equivalent of 7777
  33. /* hex value as permission */
  34. 0x777, // permissions will be given as ocatal equivalent value of 0x777
  35. 0x7777,
  36. /* strings notation of permission, wont work properly */
  37. "r+w",
  38. "r+w+x",
  39. "u+rwx",
  40. "u+rwx, g+rw, o+wx"
  41. );
  42. $count = 1;
  43. foreach($perms_array as $permission) {
  44. echo "-- Iteration $count --\n";
  45. try {
  46. var_dump( chmod($file_name, $permission) );
  47. printf("%o", fileperms($file_name) );
  48. echo "\n";
  49. clearstatcache();
  50. } catch (TypeError $e) {
  51. echo $e->getMessage(), "\n";
  52. }
  53. try {
  54. var_dump( chmod($dir_name, $permission) );
  55. printf("%o", fileperms($dir_name) );
  56. echo "\n";
  57. clearstatcache();
  58. } catch (TypeError $e) {
  59. echo $e->getMessage(), "\n";
  60. }
  61. $count++;
  62. }
  63. echo "*** Done ***\n";
  64. ?>
  65. --CLEAN--
  66. <?php
  67. chmod(__DIR__."/006_variation2.tmp", 0777);
  68. chmod(__DIR__."/006_variation2", 0777);
  69. unlink(__DIR__."/006_variation2.tmp");
  70. rmdir(__DIR__."/006_variation2");
  71. ?>
  72. --EXPECT--
  73. *** Testing fileperms() & chmod() : usage variations ***
  74. *** Testing fileperms(), chmod() with miscellaneous permissions ***
  75. -- Iteration 1 --
  76. bool(true)
  77. 107777
  78. bool(true)
  79. 47777
  80. -- Iteration 2 --
  81. bool(true)
  82. 100000
  83. bool(true)
  84. 40000
  85. -- Iteration 3 --
  86. bool(true)
  87. 101000
  88. bool(true)
  89. 41000
  90. -- Iteration 4 --
  91. bool(true)
  92. 101111
  93. bool(true)
  94. 41111
  95. -- Iteration 5 --
  96. bool(true)
  97. 107001
  98. bool(true)
  99. 47001
  100. -- Iteration 6 --
  101. bool(true)
  102. 100001
  103. bool(true)
  104. 40001
  105. -- Iteration 7 --
  106. bool(true)
  107. 101411
  108. bool(true)
  109. 41411
  110. -- Iteration 8 --
  111. bool(true)
  112. 107141
  113. bool(true)
  114. 47141
  115. -- Iteration 9 --
  116. bool(true)
  117. 100637
  118. bool(true)
  119. 40637
  120. -- Iteration 10 --
  121. bool(true)
  122. 103567
  123. bool(true)
  124. 43567
  125. -- Iteration 11 --
  126. bool(true)
  127. 103567
  128. bool(true)
  129. 43567
  130. -- Iteration 12 --
  131. chmod(): Argument #2 ($permissions) must be of type int, string given
  132. chmod(): Argument #2 ($permissions) must be of type int, string given
  133. -- Iteration 13 --
  134. chmod(): Argument #2 ($permissions) must be of type int, string given
  135. chmod(): Argument #2 ($permissions) must be of type int, string given
  136. -- Iteration 14 --
  137. chmod(): Argument #2 ($permissions) must be of type int, string given
  138. chmod(): Argument #2 ($permissions) must be of type int, string given
  139. -- Iteration 15 --
  140. chmod(): Argument #2 ($permissions) must be of type int, string given
  141. chmod(): Argument #2 ($permissions) must be of type int, string given
  142. *** Done ***