opendir_variation7.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --TEST--
  2. Test opendir() 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. * Open a directory using opendir() with different directory permissions
  14. */
  15. echo "*** Testing opendir() : usage variations ***\n";
  16. // create the temporary directory
  17. $file_path = __DIR__;
  18. $dir_path = $file_path . "/opendir_variation7";
  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. // try to remove the dir if exists & create
  38. if (is_dir($dir_path)){
  39. chmod ($dir_path, 0777); // change dir permission to allow all operation
  40. rmdir ($dir_path);
  41. }
  42. mkdir($dir_path);
  43. // change the dir permission to test dir on it
  44. var_dump( chmod($dir_path, $perm) );
  45. var_dump($dh = opendir($dir_path));
  46. if (is_resource($dh)) {
  47. closedir($dh);
  48. }
  49. $iterator++;
  50. }
  51. ?>
  52. --CLEAN--
  53. <?php
  54. // deleting temporary directory
  55. $dir_path = __DIR__ . "/opendir_variation7";
  56. rmdir($dir_path);
  57. ?>
  58. --EXPECTF--
  59. *** Testing opendir() : usage variations ***
  60. -- Iteration 1 --
  61. bool(true)
  62. resource(%d) of type (stream)
  63. -- Iteration 2 --
  64. bool(true)
  65. resource(%d) of type (stream)
  66. -- Iteration 3 --
  67. bool(true)
  68. resource(%d) of type (stream)
  69. -- Iteration 4 --
  70. bool(true)
  71. resource(%d) of type (stream)
  72. -- Iteration 5 --
  73. bool(true)
  74. resource(%d) of type (stream)
  75. -- Iteration 6 --
  76. bool(true)
  77. resource(%d) of type (stream)
  78. -- Iteration 7 --
  79. bool(true)
  80. resource(%d) of type (stream)
  81. -- Iteration 8 --
  82. bool(true)
  83. resource(%d) of type (stream)
  84. -- Iteration 9 --
  85. bool(true)
  86. resource(%d) of type (stream)
  87. -- Iteration 10 --
  88. bool(true)
  89. resource(%d) of type (stream)