dir_variation3.phpt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. --TEST--
  2. Test dir() 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. * Providing various permissions to the directory to be opened and checking
  14. * to see if dir() function opens the directory successfully.
  15. */
  16. echo "*** Testing dir() : different directory permissions ***";
  17. // create the temporary directory
  18. $file_path = __DIR__;
  19. $dir_path = $file_path."/dir_variation3";
  20. @mkdir($dir_path);
  21. /* different values for directory permissions */
  22. $permission_values = array(
  23. /*1*/ 0477, // owner has read only, other and group has rwx
  24. 0677, // owner has rw only, other and group has rwx
  25. /*3*/ 0444, // all have read only
  26. 0666, // all have rw only
  27. /*5*/ 0400, // owner has read only, group and others have no permission
  28. 0600, // owner has rw only, group and others have no permission
  29. /*7*/ 0470, // owner has read only, group has rwx & others have no permission
  30. 0407, // owner has read only, other has rwx & group has no permission
  31. /*9*/ 0670, // owner has rw only, group has rwx & others have no permission
  32. /*10*/ 0607 // owner has rw only, group has no permission and others have rwx
  33. );
  34. // Open directory with different permission values, read and close, expected: none of them to succeed.
  35. for($count = 0; $count < count($permission_values); $count++) {
  36. echo "\n-- Iteration ".($count + 1)." --\n";
  37. // try to remove the dir if exists & create
  38. $file_path = __DIR__;
  39. $dir_path = $file_path."/dir_variation3";
  40. @chmod ($dir_path, 0777); // change dir permission to allow all operation
  41. @rmdir ($dir_path); // try n delete the dir
  42. // create the dir now
  43. @mkdir($dir_path);
  44. // change the dir permission to test dir on it
  45. var_dump( chmod($dir_path, $permission_values[$count]) );
  46. // try to get dir handle
  47. $d = dir($dir_path);
  48. var_dump($d); // dump the handle
  49. // try read directory, expected : false
  50. echo "-- reading contents --\n";
  51. var_dump($d->read());
  52. // close directory
  53. $d->close();
  54. }
  55. echo "Done";
  56. ?>
  57. --CLEAN--
  58. <?php
  59. // deleting temporary directory
  60. $file_path = __DIR__;
  61. $dir_path = $file_path."/dir_variation3";
  62. rmdir($dir_path);
  63. ?>
  64. --EXPECTF--
  65. *** Testing dir() : different directory permissions ***
  66. -- Iteration 1 --
  67. bool(true)
  68. object(Directory)#%d (2) {
  69. ["path"]=>
  70. string(%d) "%s/dir_variation3"
  71. ["handle"]=>
  72. resource(%d) of type (stream)
  73. }
  74. -- reading contents --
  75. string(%d) "%s"
  76. -- Iteration 2 --
  77. bool(true)
  78. object(Directory)#%d (2) {
  79. ["path"]=>
  80. string(%d) "%s/dir_variation3"
  81. ["handle"]=>
  82. resource(%d) of type (stream)
  83. }
  84. -- reading contents --
  85. string(%d) "%s"
  86. -- Iteration 3 --
  87. bool(true)
  88. object(Directory)#%d (2) {
  89. ["path"]=>
  90. string(%d) "%s/dir_variation3"
  91. ["handle"]=>
  92. resource(%d) of type (stream)
  93. }
  94. -- reading contents --
  95. string(%d) "%s"
  96. -- Iteration 4 --
  97. bool(true)
  98. object(Directory)#%d (2) {
  99. ["path"]=>
  100. string(%d) "%s/dir_variation3"
  101. ["handle"]=>
  102. resource(%d) of type (stream)
  103. }
  104. -- reading contents --
  105. string(%d) "%s"
  106. -- Iteration 5 --
  107. bool(true)
  108. object(Directory)#%d (2) {
  109. ["path"]=>
  110. string(%d) "%s/dir_variation3"
  111. ["handle"]=>
  112. resource(%d) of type (stream)
  113. }
  114. -- reading contents --
  115. string(%d) "%s"
  116. -- Iteration 6 --
  117. bool(true)
  118. object(Directory)#%d (2) {
  119. ["path"]=>
  120. string(%d) "%s/dir_variation3"
  121. ["handle"]=>
  122. resource(%d) of type (stream)
  123. }
  124. -- reading contents --
  125. string(%d) "%s"
  126. -- Iteration 7 --
  127. bool(true)
  128. object(Directory)#%d (2) {
  129. ["path"]=>
  130. string(%d) "%s/dir_variation3"
  131. ["handle"]=>
  132. resource(%d) of type (stream)
  133. }
  134. -- reading contents --
  135. string(%d) "%s"
  136. -- Iteration 8 --
  137. bool(true)
  138. object(Directory)#%d (2) {
  139. ["path"]=>
  140. string(%d) "%s/dir_variation3"
  141. ["handle"]=>
  142. resource(%d) of type (stream)
  143. }
  144. -- reading contents --
  145. string(%d) "%s"
  146. -- Iteration 9 --
  147. bool(true)
  148. object(Directory)#%d (2) {
  149. ["path"]=>
  150. string(%d) "%s/dir_variation3"
  151. ["handle"]=>
  152. resource(%d) of type (stream)
  153. }
  154. -- reading contents --
  155. string(%d) "%s"
  156. -- Iteration 10 --
  157. bool(true)
  158. object(Directory)#%d (2) {
  159. ["path"]=>
  160. string(%d) "%s/dir_variation3"
  161. ["handle"]=>
  162. resource(%d) of type (stream)
  163. }
  164. -- reading contents --
  165. string(%d) "%s"
  166. Done