tempnam_variation7-win32.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. --TEST--
  2. Test tempnam() function: usage variations - invalid/non-existing dir
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) != "WIN")
  6. die("skip Only run 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 $dir,
  14. hence the unique files will be created in temporary dir */
  15. echo "*** Testing tempnam() with invalid/non-existing directory names ***\n";
  16. /* An array of names, which will be passed as a dir name */
  17. $names_arr = array(
  18. /* Invalid args */
  19. -1,
  20. TRUE,
  21. FALSE,
  22. NULL,
  23. "",
  24. " ",
  25. "\0",
  26. array(),
  27. /* Non-existing dirs */
  28. "/no/such/file/dir",
  29. "php"
  30. );
  31. for( $i=0; $i<count($names_arr); $i++ ) {
  32. echo "-- Iteration $i --\n";
  33. $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp");
  34. if( file_exists($file_name) ){
  35. echo "File name is => ";
  36. print($file_name);
  37. echo "\n";
  38. echo "File permissions are => ";
  39. printf("%o", fileperms($file_name) );
  40. echo "\n";
  41. echo "File created in => ";
  42. $file_dir = dirname($file_name);
  43. if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
  44. echo "temp dir\n";
  45. } else {
  46. echo "unknown location\n";
  47. }
  48. } else {
  49. echo "-- File is not created --\n";
  50. }
  51. unlink($file_name);
  52. }
  53. echo "\n*** Done ***\n";
  54. ?>
  55. --EXPECTF--
  56. *** Testing tempnam() with invalid/non-existing directory names ***
  57. -- Iteration 0 --
  58. File name is => %s%et%s
  59. File permissions are => 100666
  60. File created in => temp dir
  61. -- Iteration 1 --
  62. File name is => %s%et%s
  63. File permissions are => 100666
  64. File created in => temp dir
  65. -- Iteration 2 --
  66. File name is => %s%et%s
  67. File permissions are => 100666
  68. File created in => temp dir
  69. -- Iteration 3 --
  70. File name is => %s%et%s
  71. File permissions are => 100666
  72. File created in => temp dir
  73. -- Iteration 4 --
  74. File name is => %s%et%s
  75. File permissions are => 100666
  76. File created in => temp dir
  77. -- Iteration 5 --
  78. File name is => %s%et%s
  79. File permissions are => 100666
  80. File created in => temp dir
  81. -- Iteration 6 --
  82. Warning: tempnam() expects parameter 1 to be a valid path, string given in %stempnam_variation7-win32.php on line %d
  83. -- File is not created --
  84. Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d
  85. -- Iteration 7 --
  86. Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d
  87. -- File is not created --
  88. Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d
  89. -- Iteration 8 --
  90. File name is => %s%et%s
  91. File permissions are => 100666
  92. File created in => temp dir
  93. -- Iteration 9 --
  94. File name is => %s%et%s
  95. File permissions are => 100666
  96. File created in => temp dir
  97. *** Done ***