readdir_variation5.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. --TEST--
  2. Test readdir() function : usage variations - different 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. * Open a directory with different premissions then try to read it
  14. * to test behaviour of readdir()
  15. */
  16. echo "*** Testing readdir() : usage variations ***\n";
  17. // create the temporary directory
  18. $dir_path = __DIR__ . "/readdir_variation5";
  19. mkdir($dir_path);
  20. /* different values for directory permissions */
  21. $permission_values = array(
  22. /*1*/ 0477, // owner has read only, other and group has rwx
  23. 0677, // owner has rw only, other and group has rwx
  24. /*3*/ 0444, // all have read only
  25. 0666, // all have rw only
  26. /*5*/ 0400, // owner has read only, group and others have no permission
  27. 0600, // owner has rw only, group and others have no permission
  28. /*7*/ 0470, // owner has read only, group has rwx & others have no permission
  29. 0407, // owner has read only, other has rwx & group has no permission
  30. /*9*/ 0670, // owner has rw only, group has rwx & others have no permission
  31. /*10*/ 0607 // owner has rw only, group has no permission and others have rwx
  32. );
  33. // Open directory with different permission values, read and close, expected: none of them to succeed.
  34. $iterator = 1;
  35. foreach($permission_values as $perm) {
  36. echo "\n-- Iteration $iterator --\n";
  37. if (is_dir($dir_path)) {
  38. chmod ($dir_path, 0777); // change dir permission to allow all operation
  39. rmdir ($dir_path);
  40. }
  41. mkdir($dir_path);
  42. // change the dir permission to test dir on it
  43. var_dump( chmod($dir_path, $perm) );
  44. var_dump($dh = opendir($dir_path));
  45. echo "-- Calling readdir() --\n";
  46. var_dump(readdir($dh));
  47. closedir($dh);
  48. $iterator++;
  49. }
  50. ?>
  51. --CLEAN--
  52. <?php
  53. $dir_path = __DIR__ . "/readdir_variation5";
  54. rmdir($dir_path);
  55. ?>
  56. --EXPECTF--
  57. *** Testing readdir() : usage variations ***
  58. -- Iteration 1 --
  59. bool(true)
  60. resource(%d) of type (stream)
  61. -- Calling readdir() --
  62. string(%d) "%s"
  63. -- Iteration 2 --
  64. bool(true)
  65. resource(%d) of type (stream)
  66. -- Calling readdir() --
  67. string(%d) "%s"
  68. -- Iteration 3 --
  69. bool(true)
  70. resource(%d) of type (stream)
  71. -- Calling readdir() --
  72. string(%d) "%s"
  73. -- Iteration 4 --
  74. bool(true)
  75. resource(%d) of type (stream)
  76. -- Calling readdir() --
  77. string(%d) "%s"
  78. -- Iteration 5 --
  79. bool(true)
  80. resource(%d) of type (stream)
  81. -- Calling readdir() --
  82. string(%d) "%s"
  83. -- Iteration 6 --
  84. bool(true)
  85. resource(%d) of type (stream)
  86. -- Calling readdir() --
  87. string(%d) "%s"
  88. -- Iteration 7 --
  89. bool(true)
  90. resource(%d) of type (stream)
  91. -- Calling readdir() --
  92. string(%d) "%s"
  93. -- Iteration 8 --
  94. bool(true)
  95. resource(%d) of type (stream)
  96. -- Calling readdir() --
  97. string(%d) "%s"
  98. -- Iteration 9 --
  99. bool(true)
  100. resource(%d) of type (stream)
  101. -- Calling readdir() --
  102. string(%d) "%s"
  103. -- Iteration 10 --
  104. bool(true)
  105. resource(%d) of type (stream)
  106. -- Calling readdir() --
  107. string(%d) "%s"