tempnam_variation3-win32.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. --FILE--
  9. <?php
  10. /* Prototype: string tempnam ( string $dir, string $prefix );
  11. Description: Create file with unique file name.
  12. */
  13. /* Passing invalid/non-existing args for $prefix */
  14. echo "*** Testing tempnam() with obscure prefixes ***\n";
  15. $file_path = dirname(__FILE__)."/tempnamVar3";
  16. if (!mkdir($file_path)) {
  17. echo "Failed, cannot create temp dir $filepath\n";
  18. exit(1);
  19. }
  20. $file_path = realpath($file_path);
  21. /* An array of prefixes */
  22. $names_arr = array(
  23. /* Valid args (casting)*/
  24. -1,
  25. TRUE,
  26. FALSE,
  27. NULL,
  28. "",
  29. " ",
  30. "\0",
  31. /* Invalid args */
  32. array(),
  33. /* Valid args*/
  34. /* prefix with path separator of a non existing directory*/
  35. "/no/such/file/dir",
  36. "php/php"
  37. );
  38. $res_arr = array(
  39. /* Invalid args */
  40. true,
  41. true,
  42. true,
  43. true,
  44. true,
  45. true,
  46. true,
  47. false,
  48. /* prefix with path separator of a non existing directory*/
  49. true,
  50. true
  51. );
  52. for( $i=0; $i<count($names_arr); $i++ ) {
  53. echo "-- Iteration $i --\n";
  54. $file_name = tempnam($file_path, $names_arr[$i]);
  55. /* creating the files in existing dir */
  56. if (file_exists($file_name) && !$res_arr[$i]) {
  57. echo "Failed\n";
  58. }
  59. if ($res_arr[$i]) {
  60. $file_dir = dirname($file_name);
  61. if (realpath($file_dir) == $file_path || realpath($file_dir . "\\") == $file_path) {
  62. echo "OK\n";
  63. } else {
  64. echo "Failed, not created in the correct directory " . realpath($file_dir) . ' vs ' . $file_path ."\n";
  65. }
  66. if (!is_writable($file_name)) {
  67. printf("%o\n", fileperms($file_name) );
  68. }
  69. } else {
  70. echo "OK\n";
  71. }
  72. @unlink($file_name);
  73. }
  74. rmdir($file_path);
  75. echo "\n*** Done. ***\n";
  76. ?>
  77. --EXPECTF--
  78. *** Testing tempnam() with obscure prefixes ***
  79. -- Iteration 0 --
  80. OK
  81. -- Iteration 1 --
  82. OK
  83. -- Iteration 2 --
  84. OK
  85. -- Iteration 3 --
  86. OK
  87. -- Iteration 4 --
  88. OK
  89. -- Iteration 5 --
  90. Failed, not created in the correct directory %s vs %s
  91. 0
  92. -- Iteration 6 --
  93. Warning: tempnam() expects parameter 2 to be a valid path, string given in %stempnam_variation3-win32.php on line %d
  94. Failed, not created in the correct directory %s vs %stempnamVar3
  95. 0
  96. -- Iteration 7 --
  97. Warning: tempnam() expects parameter 2 to be a valid path, array given in %s\ext\standard\tests\file\tempnam_variation3-win32.php on line %d
  98. OK
  99. -- Iteration 8 --
  100. OK
  101. -- Iteration 9 --
  102. OK
  103. *** Done. ***