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