Annotation of embedaddon/php/ext/standard/tests/file/file_put_contents_variation8-win32.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test file_put_contents() function : usage variation - obscure filenames
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --SKIPIF--
6: <?php
7: if(substr(PHP_OS, 0, 3) != "WIN")
8: die("skip Only run on Windows");
9: ?>
10: --FILE--
11: <?php
12: /* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
13: * Description: Write/Create a file with contents data and return the number of bytes written
14: * Source code: ext/standard/file.c
15: * Alias to functions:
16: */
17:
18: echo "*** Testing file_put_contents() : usage variation ***\n";
19:
20: /* An array of filenames */
21: $names_arr = array(
22: "-1" => -1,
23: "TRUE" => TRUE,
24: "FALSE" => FALSE,
25: "NULL" => NULL,
26: "\"\"" => "",
27: "\" \"" => " ",
28: "\\0" => "\0",
29: "array()" => array(),
30:
31: /* prefix with path separator of a non existing directory*/
32: "/no/such/file/dir" => "/no/such/file/dir",
33: "php/php"=> "php/php"
34:
35: );
36:
37: foreach($names_arr as $key =>$value) {
38: echo "\n-- Filename: $key --\n";
39: $res = file_put_contents($value, "Some data");
40: if ($res !== false && $res != null) {
41: echo "$res bytes written to: $value\n";
42: unlink($value);
43: } else {
44: echo "Failed to write data to: $key\n";
45: }
46: };
47:
48: ?>
49: ===Done===
50: --EXPECTF--
51: *** Testing file_put_contents() : usage variation ***
52:
53: -- Filename: -1 --
54: 9 bytes written to: -1
55:
56: -- Filename: TRUE --
57: 9 bytes written to: 1
58:
59: -- Filename: FALSE --
60:
61: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
62: Failed to write data to: FALSE
63:
64: -- Filename: NULL --
65:
66: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
67: Failed to write data to: NULL
68:
69: -- Filename: "" --
70:
71: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
72: Failed to write data to: ""
73:
74: -- Filename: " " --
75:
76: Warning: file_put_contents( ): failed to open stream: Permission denied in %s on line %d
77: Failed to write data to: " "
78:
79: -- Filename: \0 --
80:
81: Warning: file_put_contents(): Filename cannot be empty in %s on line %d
82: Failed to write data to: \0
83:
84: -- Filename: array() --
85:
86: Warning: file_put_contents() expects parameter 1 to be string, array given in %s on line %d
87: Failed to write data to: array()
88:
89: -- Filename: /no/such/file/dir --
90:
91: Warning: file_put_contents(/no/such/file/dir): failed to open stream: %s in %s on line %d
92: Failed to write data to: /no/such/file/dir
93:
94: -- Filename: php/php --
95:
96: Warning: file_put_contents(php/php): failed to open stream: %s in %s on line %d
97: Failed to write data to: php/php
98: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>