tempnam_variation3-win32.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. --TEST--
  2. Test tempnam() function: usage variations - obscure prefixes
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) != "WIN")
  6. die("skip run only on Windows");
  7. ?>
  8. --CONFLICTS--
  9. obscure_filename
  10. --FILE--
  11. <?php
  12. /* Passing invalid/non-existing args for $prefix */
  13. echo "*** Testing tempnam() with obscure prefixes ***\n";
  14. $file_path = __DIR__."/tempnamVar3";
  15. if (!mkdir($file_path)) {
  16. echo "Failed, cannot create temp dir $filepath\n";
  17. exit(1);
  18. }
  19. $file_path = realpath($file_path);
  20. /* An array of prefixes */
  21. $names_arr = array(
  22. /* Valid args (casting)*/
  23. -1,
  24. TRUE,
  25. FALSE,
  26. "",
  27. " ",
  28. "\0",
  29. /* Invalid args */
  30. array(),
  31. /* Valid args*/
  32. /* prefix with path separator of a non existing directory*/
  33. "/no/such/file/dir",
  34. "php/php"
  35. );
  36. $res_arr = array(
  37. /* Invalid args */
  38. true,
  39. true,
  40. true,
  41. true,
  42. true,
  43. true,
  44. false,
  45. /* prefix with path separator of a non existing directory*/
  46. true,
  47. true
  48. );
  49. for( $i=0; $i<count($names_arr); $i++ ) {
  50. echo "-- Iteration $i --\n";
  51. try {
  52. $file_name = tempnam($file_path, $names_arr[$i]);
  53. } catch (Error $e) {
  54. echo $e->getMessage(), "\n";
  55. continue;
  56. }
  57. /* creating the files in existing dir */
  58. if (file_exists($file_name) && !$res_arr[$i]) {
  59. echo "Failed\n";
  60. }
  61. if ($res_arr[$i]) {
  62. $file_dir = dirname($file_name);
  63. if (realpath($file_dir) == $file_path || realpath($file_dir . "\\") == $file_path) {
  64. echo "OK\n";
  65. } else {
  66. echo "Failed, not created in the correct directory " . realpath($file_dir) . ' vs ' . $file_path ."\n";
  67. }
  68. if (!is_writable($file_name)) {
  69. printf("%o\n", fileperms($file_name) );
  70. }
  71. } else {
  72. echo "OK\n";
  73. }
  74. @unlink($file_name);
  75. }
  76. rmdir($file_path);
  77. ?>
  78. --EXPECTF--
  79. *** Testing tempnam() with obscure prefixes ***
  80. -- Iteration 0 --
  81. OK
  82. -- Iteration 1 --
  83. OK
  84. -- Iteration 2 --
  85. OK
  86. -- Iteration 3 --
  87. OK
  88. -- Iteration 4 --
  89. Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation3-win32.php on line %d
  90. Failed, not created in the correct directory %s vs %s
  91. 0
  92. -- Iteration 5 --
  93. tempnam(): Argument #2 ($prefix) must not contain any null bytes
  94. -- Iteration 6 --
  95. tempnam(): Argument #2 ($prefix) must be of type string, array given
  96. -- Iteration 7 --
  97. OK
  98. -- Iteration 8 --
  99. OK