scandir_variation7.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. --TEST--
  2. Test scandir() function : usage variations - different directory permissions
  3. --SKIPIF--
  4. <?php
  5. if( substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip Not for Windows');
  7. }
  8. require __DIR__ . '/../skipif_root.inc';
  9. ?>
  10. --FILE--
  11. <?php
  12. /*
  13. * Create directories with different permissions to test whether scandir() can access them
  14. */
  15. echo "*** Testing scandir() : usage variations ***\n";
  16. // create the temporary directory
  17. $dir_path = __DIR__ . "/scandir_variation7";
  18. mkdir($dir_path);
  19. // different values for directory permissions
  20. $permission_values = array(
  21. /*1*/ 0477, // owner has read only, other and group has rwx
  22. 0677, // owner has rw only, other and group has rwx
  23. /*3*/ 0444, // all have read only
  24. 0666, // all have rw only
  25. /*5*/ 0400, // owner has read only, group and others have no permission
  26. 0600, // owner has rw only, group and others have no permission
  27. /*7*/ 0470, // owner has read only, group has rwx & others have no permission
  28. 0407, // owner has read only, other has rwx & group has no permission
  29. /*9*/ 0670, // owner has rw only, group has rwx & others have no permission
  30. /*10*/ 0607 // owner has rw only, group has no permission and others have rwx
  31. );
  32. $iterator = 1;
  33. foreach ($permission_values as $perm) {
  34. echo "\n-- Iteration $iterator --\n";
  35. // Remove the directory if already exists
  36. if (is_dir($dir_path)){
  37. chmod ($dir_path, 0777); // change dir permission to allow all operation
  38. rmdir ($dir_path);
  39. }
  40. mkdir($dir_path);
  41. // change the dir permission to test dir on it
  42. var_dump( chmod($dir_path, $perm) );
  43. var_dump(scandir($dir_path));
  44. $iterator++;
  45. }
  46. ?>
  47. --CLEAN--
  48. <?php
  49. $dir_path = __DIR__ . "/scandir_variation7";
  50. rmdir($dir_path);
  51. ?>
  52. --EXPECT--
  53. *** Testing scandir() : usage variations ***
  54. -- Iteration 1 --
  55. bool(true)
  56. array(2) {
  57. [0]=>
  58. string(1) "."
  59. [1]=>
  60. string(2) ".."
  61. }
  62. -- Iteration 2 --
  63. bool(true)
  64. array(2) {
  65. [0]=>
  66. string(1) "."
  67. [1]=>
  68. string(2) ".."
  69. }
  70. -- Iteration 3 --
  71. bool(true)
  72. array(2) {
  73. [0]=>
  74. string(1) "."
  75. [1]=>
  76. string(2) ".."
  77. }
  78. -- Iteration 4 --
  79. bool(true)
  80. array(2) {
  81. [0]=>
  82. string(1) "."
  83. [1]=>
  84. string(2) ".."
  85. }
  86. -- Iteration 5 --
  87. bool(true)
  88. array(2) {
  89. [0]=>
  90. string(1) "."
  91. [1]=>
  92. string(2) ".."
  93. }
  94. -- Iteration 6 --
  95. bool(true)
  96. array(2) {
  97. [0]=>
  98. string(1) "."
  99. [1]=>
  100. string(2) ".."
  101. }
  102. -- Iteration 7 --
  103. bool(true)
  104. array(2) {
  105. [0]=>
  106. string(1) "."
  107. [1]=>
  108. string(2) ".."
  109. }
  110. -- Iteration 8 --
  111. bool(true)
  112. array(2) {
  113. [0]=>
  114. string(1) "."
  115. [1]=>
  116. string(2) ".."
  117. }
  118. -- Iteration 9 --
  119. bool(true)
  120. array(2) {
  121. [0]=>
  122. string(1) "."
  123. [1]=>
  124. string(2) ".."
  125. }
  126. -- Iteration 10 --
  127. bool(true)
  128. array(2) {
  129. [0]=>
  130. string(1) "."
  131. [1]=>
  132. string(2) ".."
  133. }