diff options
| author | Ant Phillips <ant@php.net> | 2008-11-26 17:48:41 +0000 |
|---|---|---|
| committer | Ant Phillips <ant@php.net> | 2008-11-26 17:48:41 +0000 |
| commit | 977a9400feef5fea099f8eed408f329a93143120 (patch) | |
| tree | 4826fdf374bd9afad1da978dd49a5d0d40909650 | |
| parent | 3c0628375086c578062b9294f3710d6735e8f589 (diff) | |
| download | php-git-977a9400feef5fea099f8eed408f329a93143120.tar.gz | |
File system tests: checked on PHP 6.0 latest snap (Windows, Linux and Linux 64 bit) - there are quite a large number of failing test cases (all marked with an XFAIL section), they wiill have bugs raised to cover the issues real soon now...
212 files changed, 20491 insertions, 1421 deletions
diff --git a/ext/standard/tests/file/001-win32.phpt b/ext/standard/tests/file/001-win32.phpt index 09ab2b7a1b..ee520940e4 100644 --- a/ext/standard/tests/file/001-win32.phpt +++ b/ext/standard/tests/file/001-win32.phpt @@ -1,5 +1,7 @@ --TEST-- File type functions +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> --SKIPIF-- <?php if (substr(PHP_OS, 0, 3) != 'WIN') { @@ -10,7 +12,6 @@ if (substr(PHP_OS, 0, 3) != 'WIN') { <?php chdir(dirname(__FILE__)); @unlink('test.file'); -@unlink('test.link'); if (file_exists('test.file')) { echo "test.file exists\n"; } else { @@ -23,22 +24,11 @@ if (file_exists('test.file')) { } else { echo "test.file does not exist\n"; } -sleep (2); -if (file_exists('test.link')) { - echo "test.link exists\n"; -} else { - echo "test.link does not exist\n"; -} if (is_link('test.file')) { echo "test.file is a symlink\n"; } else { echo "test.file is not a symlink\n"; } -if (is_link('test.link')) { - echo "test.link is a symlink\n"; -} else { - echo "test.link is not a symlink\n"; -} if (file_exists('test.file')) { echo "test.file exists\n"; } else { @@ -52,7 +42,6 @@ for ($i = 0; $i <= 12; $i++) { } } echo "test.file is " . filetype('test.file') . "\n"; -echo "test.link is " . filetype('test.link') . "\n"; printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file')); echo "test.file size is " . filesize('test.file') . "\n"; if (is_writeable('test.file')) { @@ -70,16 +59,6 @@ if (is_file('test.file')) { } else { echo "test.file is not a regular file\n"; } -if (is_file('test.link')) { - echo "test.link is a regular file\n"; -} else { - echo "test.link is not a regular file\n"; -} -if (is_dir('test.link')) { - echo "test.link is a directory\n"; -} else { - echo "test.link is not a directory\n"; -} if (is_dir('../file')) { echo "../file is a directory\n"; } else { @@ -106,20 +85,16 @@ if (file_exists('test.file')) { --EXPECT-- test.file does not exist test.file exists -test.link does not exist test.file is not a symlink -test.link is not a symlink test.file exists test.file is file -test.link is file test.file permissions are 0666 test.file size is 0 test.file is writeable test.file is readable test.file is a regular file -test.link is not a regular file -test.link is not a directory ../file is a directory test.file is not a directory test.file does not exist test.file does not exist + diff --git a/ext/standard/tests/file/005_variation2-win32.phpt b/ext/standard/tests/file/005_variation2-win32.phpt new file mode 100644 index 0000000000..caed7e62fa --- /dev/null +++ b/ext/standard/tests/file/005_variation2-win32.phpt @@ -0,0 +1,125 @@ +--TEST-- +Test fileatime(), filemtime(), filectime() & touch() functions : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: int fileatime ( string $filename ); + Description: Returns the time the file was last accessed, or FALSE + in case of an error. The time is returned as a Unix timestamp. + + Prototype: int filemtime ( string $filename ); + Description: Returns the time the file was last modified, or FALSE + in case of an error. + + Prototype: int filectime ( string $filename ); + Description: Returns the time the file was last changed, or FALSE + in case of an error. The time is returned as a Unix timestamp. + + Prototype: bool touch ( string $filename [, int $time [, int $atime]] ); + Description: Attempts to set the access and modification times of the file + named in the filename parameter to the value given in time. +*/ + +/* + Prototype: void stat_fn(string $filename); + Description: Prints access, modification and change times of a file +*/ +function stat_fn( $filename ) { + echo "\n-- File '$filename' --\n"; + echo "-- File access time is => "; + echo fileatime($filename)."\n"; + clearstatcache(); + echo "-- File modification time is => "; + echo filemtime($filename)."\n"; + clearstatcache(); + echo "-- inode change time is => "; + echo filectime($filename)."\n"; + clearstatcache(); + + +} + +echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n"; +echo "\n*** testing file info ***"; +stat_fn(NULL); +stat_fn(false); +stat_fn(''); +stat_fn(' '); +stat_fn('|'); +echo "\n*** testing touch ***"; +var_dump(touch(NULL)); +var_dump(touch(false)); +var_dump(touch('')); + +//php generates permission denied, we generate No such file or dir. +var_dump(touch(' ')); +var_dump(touch('|')); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations *** + +*** testing file info *** +-- File '' -- +-- File access time is => +-- File modification time is => +-- inode change time is => + +-- File '' -- +-- File access time is => +-- File modification time is => +-- inode change time is => + +-- File '' -- +-- File access time is => +-- File modification time is => +-- inode change time is => + +-- File ' ' -- +-- File access time is => +Warning: fileatime(): stat failed for in %s on line %d + +-- File modification time is => +Warning: filemtime(): stat failed for in %s on line %d + +-- inode change time is => +Warning: filectime(): stat failed for in %s on line %d + + +-- File '|' -- +-- File access time is => +Warning: fileatime(): stat failed for | in %s on line %d + +-- File modification time is => +Warning: filemtime(): stat failed for | in %s on line %d + +-- inode change time is => +Warning: filectime(): stat failed for | in %s on line %d + + +*** testing touch *** +Warning: touch(): Unable to create file because No such file or directory in %s on line %d +bool(false) + +Warning: touch(): Unable to create file because No such file or directory in %s on line %d +bool(false) + +Warning: touch(): Unable to create file because No such file or directory in %s on line %d +bool(false) + +Warning: touch(): Unable to create file because %s in %s on line %d +bool(false) + +Warning: touch(): Unable to create file | because %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/file/005_variation2.phpt b/ext/standard/tests/file/005_variation2.phpt new file mode 100644 index 0000000000..4d9942402b --- /dev/null +++ b/ext/standard/tests/file/005_variation2.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test fileatime(), filemtime(), filectime() & touch() functions : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. only for Non Windows Systems'); +} +?> +--FILE-- +<?php +/* + Prototype: int fileatime ( string $filename ); + Description: Returns the time the file was last accessed, or FALSE + in case of an error. The time is returned as a Unix timestamp. + + Prototype: int filemtime ( string $filename ); + Description: Returns the time the file was last modified, or FALSE + in case of an error. + + Prototype: int filectime ( string $filename ); + Description: Returns the time the file was last changed, or FALSE + in case of an error. The time is returned as a Unix timestamp. + + Prototype: bool touch ( string $filename [, int $time [, int $atime]] ); + Description: Attempts to set the access and modification times of the file + named in the filename parameter to the value given in time. +*/ + +/* + Prototype: void stat_fn(string $filename); + Description: Prints access, modification and change times of a file +*/ +function stat_fn( $filename ) { + echo "\n-- File '$filename' --\n"; + echo "-- File access time is => "; + echo fileatime($filename)."\n"; + clearstatcache(); + echo "-- File modification time is => "; + echo filemtime($filename)."\n"; + clearstatcache(); + echo "-- inode change time is => "; + echo filectime($filename)."\n"; + clearstatcache(); + + +} + +echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n"; +echo "\n*** testing touch ***\n"; +var_dump(touch(NULL)); +var_dump(touch(false)); +var_dump(touch('')); +var_dump(touch(' ')); +var_dump(touch('|')); + +echo "\n*** testing file info ***"; +stat_fn(NULL); +stat_fn(false); +stat_fn(''); +stat_fn(' '); +stat_fn('|'); + +var_dump(unlink(' ')); +var_dump(unlink('|')); + +echo "Done"; +?> +--EXPECTF-- +*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations *** + +*** testing touch *** + +Warning: touch(): Unable to create file because No such file or directory in %s on line %d +bool(false) + +Warning: touch(): Unable to create file because No such file or directory in %s on line %d +bool(false) + +Warning: touch(): Unable to create file because No such file or directory in %s on line %d +bool(false) +bool(true) +bool(true) + +*** testing file info *** +-- File '' -- +-- File access time is => +-- File modification time is => +-- inode change time is => + +-- File '' -- +-- File access time is => +-- File modification time is => +-- inode change time is => + +-- File '' -- +-- File access time is => +-- File modification time is => +-- inode change time is => + +-- File ' ' -- +-- File access time is => %d +-- File modification time is => %d +-- inode change time is => %d + +-- File '|' -- +-- File access time is => %d +-- File modification time is => %d +-- inode change time is => %d +bool(true) +bool(true) +Done diff --git a/ext/standard/tests/file/006_error.phpt b/ext/standard/tests/file/006_error.phpt index bce98ecd3d..bef7a89f44 100644 --- a/ext/standard/tests/file/006_error.phpt +++ b/ext/standard/tests/file/006_error.phpt @@ -11,7 +11,7 @@ $fp = fopen($filename, 'w'); fclose($fp); if(fileowner($filename) == 0) { unlink ($filename); - die('skip cannot be run as root'); + die('skip...cannot be run as root\n'); } unlink($filename); @@ -68,13 +68,13 @@ unlink( dirname(__FILE__)."/006_error.tmp"); --EXPECTF-- *** Testing error conditions for fileperms(), chmod() *** -Warning: chmod(): %s in %s on line %d +Warning: chmod(): Operation not permitted in %s on line %d bool(false) -100644 +%d -Warning: chmod(): %s in %s on line %d +Warning: chmod(): Operation not permitted in %s on line %d bool(false) -40755 +%d Warning: chmod(): No such file or directory in %s on line %d bool(false) @@ -105,3 +105,4 @@ Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d NULL *** Done *** + diff --git a/ext/standard/tests/file/006_variation2.phpt b/ext/standard/tests/file/006_variation2.phpt index 33f31f527d..d8d2b8a517 100644 --- a/ext/standard/tests/file/006_variation2.phpt +++ b/ext/standard/tests/file/006_variation2.phpt @@ -11,7 +11,7 @@ $fp = fopen($filename, 'w'); fclose($fp); if(fileowner($filename) == 0) { unlink ($filename); - die('skip cannot be run as root'); + die('skip...cannot be run as root\n'); } unlink($filename); @@ -88,99 +88,100 @@ chmod(dirname(__FILE__)."/006_variation2", 0777); unlink(dirname(__FILE__)."/006_variation2.tmp"); rmdir(dirname(__FILE__)."/006_variation2"); ?> ---EXPECTF-- +--EXPECTF-- *** Testing fileperms() & chmod() : usage variations *** *** Testing fileperms(), chmod() with miscellaneous permissions *** -- Iteration 1 -- bool(true) -107777 +%d bool(true) -47777 +%d -- Iteration 2 -- bool(true) -100000 +%d bool(true) -40000 +%d -- Iteration 3 -- bool(true) -101000 +%d bool(true) -41000 +%d -- Iteration 4 -- bool(true) -101111 +%d bool(true) -41111 +%d -- Iteration 5 -- bool(true) -107001 +%d bool(true) -47001 +%d -- Iteration 6 -- bool(true) -100001 +%d bool(true) -40001 +%d -- Iteration 7 -- bool(true) -101411 +%d bool(true) -41411 +%d -- Iteration 8 -- bool(true) -107141 +%d bool(true) -47141 +%d -- Iteration 9 -- bool(true) -100637 +%d bool(true) -40637 +%d -- Iteration 10 -- bool(true) -103567 +%d bool(true) -43567 +%d -- Iteration 11 -- bool(true) -103567 +%d bool(true) -43567 +%d -- Iteration 12 -- Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -103567 +%d Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -43567 +%d -- Iteration 13 -- Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -103567 +%d Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -43567 +%d -- Iteration 14 -- Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -103567 +%d Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -43567 +%d -- Iteration 15 -- Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -103567 +%d Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d NULL -43567 +%d *** Done *** + diff --git a/ext/standard/tests/file/007_error.phpt b/ext/standard/tests/file/007_error.phpt index 3b79f0e591..8f4b47ab7a 100644 --- a/ext/standard/tests/file/007_error.phpt +++ b/ext/standard/tests/file/007_error.phpt @@ -1,5 +1,9 @@ --TEST-- Test fopen, fclose() & feof() functions: error conditions +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> --FILE-- <?php /* @@ -44,7 +48,6 @@ var_dump( feof($fp, "handle")); fclose($fp); /* test invalid arguments : non-resources */ -chdir(dirname(__FILE__)); echo "-- Testing fopen(), fclose() & feof() with invalid arguments --\n"; $invalid_args = array ( "string", @@ -74,32 +77,32 @@ bool(false) Warning: fopen() expects at least 2 parameters, 0 given in %s on line %d bool(false) -Warning: fclose(): %d is not a valid stream resource in %s on line %d +Warning: fclose(): 5 is not a valid stream resource in %s on line %d bool(false) Warning: fclose() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) Warning: fclose() expects exactly 1 parameter, 0 given in %s on line %d -NULL +bool(false) -Warning: feof(): %d is not a valid stream resource in %s on line %d +Warning: feof(): 5 is not a valid stream resource in %s on line %d bool(false) Warning: feof() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) Warning: feof() expects exactly 1 parameter, 0 given in %s on line %d -NULL +bool(false) Warning: fopen() expects at most 4 parameters, 5 given in %s on line %d bool(false) Warning: fclose() expects exactly 1 parameter, 2 given in %s on line %d -NULL +bool(false) Warning: feof() expects exactly 1 parameter, 2 given in %s on line %d -NULL +bool(false) -- Testing fopen(), fclose() & feof() with invalid arguments -- -- Iteration 1 -- @@ -107,65 +110,66 @@ Warning: fopen(string): failed to open stream: No such file or directory in %s o bool(false) Warning: fclose() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: fopen(10): failed to open stream: No such file or directory in %s on line %d bool(false) Warning: fclose() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: fopen(10.5): failed to open stream: No such file or directory in %s on line %d bool(false) Warning: fclose() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: fopen(1): failed to open stream: No such file or directory in %s on line %d bool(false) Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Notice: Array to string conversion in %s on line %d -Warning: fopen(Array): failed to open stream: No such file or directory in %s on line %d +Warning: fopen() expects parameter 1 to be string, array given in %s on line %d bool(false) Warning: fclose() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- bool(false) Warning: fclose() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) -- Iteration 7 -- bool(false) Warning: fclose() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) Warning: feof() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) + diff --git a/ext/standard/tests/file/basename-win32.phpt b/ext/standard/tests/file/basename-win32.phpt new file mode 100644 index 0000000000..51e066b4d5 --- /dev/null +++ b/ext/standard/tests/file/basename-win32.phpt @@ -0,0 +1,341 @@ +--TEST-- +basename +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only basename tests'); +} +?> +--FILE-- +<?php +/* + * proto string basename(string path [, string suffix]) + * Function is implemented in ext/standard/string.c + */ +$file_paths = array ( + /* simple paths */ + array("bar"), + array("\\foo\\bar"), + array("foo\\bar"), + array("\\bar"), + + /* simple paths with trailing slashes */ + array("bar\\"), + array("\\bar\\"), + array("\\foo\\bar\\"), + array("foo\\bar\\"), + array("\\bar\\"), + + /* paths with suffix removal */ + array("bar.zip", ".zip"), + array("bar.zip", "bar.zip"), + array("\\foo\\bar.zip", ".zip"), + array("foo\\bar.zip", ".zip"), + array("\\bar.zip", ".zip"), + + /* paths with suffix and trailing slashes with suffix removal*/ + array("bar.zip\\", ".zip"), + array("\\bar.zip\\", ".zip"), + array("\\foo\\bar.zip\\", ".zip"), + array("foo\\bar.zip\\", ".zip"), + array("\\bar.zip\\", ".zip"), + + /* paths with basename only suffix, with suffix removal*/ + array("\\.zip", ".zip"), + array(".zip", ".zip"), + array("\\foo\\.zip", ".zip"), + + /* paths with basename only suffix & trailing slashes, with suffix removal*/ + array(".zip\\", ".zip"), + array("\\foo\\.zip\\", ".zip"), + array("foo\\.zip\\", ".zip"), +); + +$file_path_variations = array ( + /* paths with shortcut home dir char, with suffix variation */ + array("C:\\temp\\bar"), + array("C:\\temp\\bar", ""), + array("C:\\temp\\bar", NULL), + array("C:\\temp\\bar", ' '), + array("C:\\temp\\bar.tar", ".tar"), + array("C:\\temp\\bar.tar", "~"), + array("C:\\temp\\bar.tar\\", "~"), + array("C:\\temp\\bar.tar\\", ""), + array("C:\\temp\\bar.tar", NULL), + array("C:\\temp\\bar.tar", ''), + array("C:\\temp\\bar.tar", " "), + + /* paths with numeric strings */ + array("10.5"), + array("10.5", ".5"), + array("10.5", "10.5"), + array("10"), + array("105", "5"), + array("/10.5"), + array("10.5\\"), + array("10/10.zip"), + array("0"), + array('0'), + + /* paths and suffix given as same */ + array("bar.zip", "bar.zip"), + array("\\bar.zip", "\\bar.zip"), + array("\\bar.zip\\", "\\bar.zip\\"), + array(" ", " "), + array(' ', ' '), + array(NULL, NULL), + + /* path with spaces */ + array(" "), + array(' '), + + /* empty paths */ + array(""), + array(''), + array(NULL) +); + +function check_basename( $path_arrays ) { + $loop_counter = 1; + foreach ($path_arrays as $path) { + echo "\n--Iteration $loop_counter--\n"; $loop_counter++; + if( 1 == count($path) ) { // no suffix provided + var_dump( basename($path[0]) ); + } else { // path as well as suffix provided, + var_dump( basename($path[0], $path[1]) ); + } + } +} + +echo "*** Testing basic operations ***\n"; +check_basename( $file_paths ); + +echo "\n*** Testing possible variations in path and suffix ***\n"; +check_basename( $file_path_variations ); + +echo "\n*** Testing error conditions ***\n"; +// zero arguments +var_dump( basename() ); + +// more than expected no. of arguments +var_dump( basename("\\blah\\tmp\\bar.zip", ".zip", ".zip") ); + +// passing invalid type arguments +$object = new stdclass; +var_dump( basename( array("string\\bar") ) ); +var_dump( basename( array("string\\bar"), "bar" ) ); +var_dump( basename( "bar", array("string\\bar") ) ); +var_dump( basename( $object, "bar" ) ); +var_dump( basename( $object ) ); +var_dump( basename( $object, $object ) ); +var_dump( basename( "bar", $object ) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing basic operations *** + +--Iteration 1-- +unicode(3) "bar" + +--Iteration 2-- +unicode(3) "bar" + +--Iteration 3-- +unicode(3) "bar" + +--Iteration 4-- +unicode(3) "bar" + +--Iteration 5-- +unicode(3) "bar" + +--Iteration 6-- +unicode(3) "bar" + +--Iteration 7-- +unicode(3) "bar" + +--Iteration 8-- +unicode(3) "bar" + +--Iteration 9-- +unicode(3) "bar" + +--Iteration 10-- +unicode(3) "bar" + +--Iteration 11-- +unicode(7) "bar.zip" + +--Iteration 12-- +unicode(3) "bar" + +--Iteration 13-- +unicode(3) "bar" + +--Iteration 14-- +unicode(3) "bar" + +--Iteration 15-- +unicode(3) "bar" + +--Iteration 16-- +unicode(3) "bar" + +--Iteration 17-- +unicode(3) "bar" + +--Iteration 18-- +unicode(3) "bar" + +--Iteration 19-- +unicode(3) "bar" + +--Iteration 20-- +unicode(4) ".zip" + +--Iteration 21-- +unicode(4) ".zip" + +--Iteration 22-- +unicode(4) ".zip" + +--Iteration 23-- +unicode(4) ".zip" + +--Iteration 24-- +unicode(4) ".zip" + +--Iteration 25-- +unicode(4) ".zip" + +*** Testing possible variations in path and suffix *** + +--Iteration 1-- +unicode(3) "bar" + +--Iteration 2-- +unicode(3) "bar" + +--Iteration 3-- +unicode(3) "bar" + +--Iteration 4-- +unicode(3) "bar" + +--Iteration 5-- +unicode(3) "bar" + +--Iteration 6-- +unicode(7) "bar.tar" + +--Iteration 7-- +unicode(7) "bar.tar" + +--Iteration 8-- +unicode(7) "bar.tar" + +--Iteration 9-- +unicode(7) "bar.tar" + +--Iteration 10-- +unicode(7) "bar.tar" + +--Iteration 11-- +unicode(7) "bar.tar" + +--Iteration 12-- +unicode(4) "10.5" + +--Iteration 13-- +unicode(2) "10" + +--Iteration 14-- +unicode(4) "10.5" + +--Iteration 15-- +unicode(2) "10" + +--Iteration 16-- +unicode(2) "10" + +--Iteration 17-- +unicode(4) "10.5" + +--Iteration 18-- +unicode(4) "10.5" + +--Iteration 19-- +unicode(6) "10.zip" + +--Iteration 20-- +unicode(1) "0" + +--Iteration 21-- +unicode(1) "0" + +--Iteration 22-- +unicode(7) "bar.zip" + +--Iteration 23-- +unicode(7) "bar.zip" + +--Iteration 24-- +unicode(7) "bar.zip" + +--Iteration 25-- +unicode(1) " " + +--Iteration 26-- +unicode(1) " " + +--Iteration 27-- +unicode(0) "" + +--Iteration 28-- +unicode(1) " " + +--Iteration 29-- +unicode(1) " " + +--Iteration 30-- +unicode(0) "" + +--Iteration 31-- +unicode(0) "" + +--Iteration 32-- +unicode(0) "" + +*** Testing error conditions *** + +Warning: basename() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Warning: basename() expects at most 2 parameters, 3 given in %s on line %d +NULL + +Warning: basename() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL + +Warning: basename() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d +NULL + +Warning: basename() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d +NULL + +Warning: basename() expects parameter 1 to be string (Unicode or binary), object given in %s on line %d +NULL + +Warning: basename() expects parameter 1 to be string (Unicode or binary), object given in %s on line %d +NULL + +Warning: basename() expects parameter 1 to be string (Unicode or binary), object given in %s on line %d +NULL + +Warning: basename() expects parameter 2 to be string (Unicode or binary), object given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/file/basename.phpt b/ext/standard/tests/file/basename.phpt Binary files differnew file mode 100644 index 0000000000..59e0e17183 --- /dev/null +++ b/ext/standard/tests/file/basename.phpt diff --git a/ext/standard/tests/file/basename_error.phpt b/ext/standard/tests/file/basename_error.phpt new file mode 100644 index 0000000000..53c53cf8b9 --- /dev/null +++ b/ext/standard/tests/file/basename_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test basename() function : error conditions +--FILE-- +<?php +/* Prototype : string basename(string path [, string suffix]) + * Description: Returns the filename component of the path + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing basename() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing basename() function with Zero arguments --\n"; +var_dump( basename() ); + +//Test basename with one more than the expected number of arguments +echo "\n-- Testing basename() function with more than expected no. of arguments --\n"; +$path = 'string_val'; +$suffix = 'string_val'; +$extra_arg = 10; +var_dump( basename($path, $suffix, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing basename() : error conditions *** + +-- Testing basename() function with Zero arguments -- + +Warning: basename() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing basename() function with more than expected no. of arguments -- + +Warning: basename() expects at most 2 parameters, 3 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/file/bug41655_1.phpt b/ext/standard/tests/file/bug41655_1.phpt index 5e010faf31..62d64dfb1e 100644 --- a/ext/standard/tests/file/bug41655_1.phpt +++ b/ext/standard/tests/file/bug41655_1.phpt @@ -1,12 +1,15 @@ --TEST-- Bug #41655 (open_basedir bypass via glob()) 1/2 +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> --INI-- open_basedir=/tmp --FILE-- <?php - $a=glob("./*.jpeg"); - +$a=glob("./*.jpeg"); +var_dump($a); echo "Done\n"; ?> --EXPECT-- -Done +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/chmod_variation3.phpt b/ext/standard/tests/file/chmod_variation3.phpt new file mode 100644 index 0000000000..37a02368a0 --- /dev/null +++ b/ext/standard/tests/file/chmod_variation3.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test chmod() function : first parameter variation +--FILE-- +<?php +/* Prototype : bool chmod(string filename, int mode) + * Description: Change file mode + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing chmod() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$mode = 0777; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for filename + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( chmod($value, $mode) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing chmod() : usage variation *** + +--int 0-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--int 1-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--float .5-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--empty array-- +Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--associative array-- +Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--uppercase NULL-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), object given, %s(%d) +NULL + +--undefined var-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) + +--unset var-- +Error: 2 - chmod(): No such file or directory, %s(%d) +bool(false) +===DONE=== + diff --git a/ext/standard/tests/file/chmod_variation4.phpt b/ext/standard/tests/file/chmod_variation4.phpt new file mode 100644 index 0000000000..f4c191c611 --- /dev/null +++ b/ext/standard/tests/file/chmod_variation4.phpt @@ -0,0 +1,202 @@ +--TEST-- +Test chmod() function : second parameter variation +--XFAIL-- +--FILE-- +<?php +/* Prototype : bool chmod(string filename, int mode) + * Description: Change file mode + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing chmod() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted +$filename = __FILE__ . ".tmp"; +$fd = fopen($filename, "w+"); +fclose($fd); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for mode + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( chmod($filename, $value) ); +}; + +chmod($filename, 0777); +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing chmod() : usage variation *** + +--float 10.5-- +bool(true) + +--float -10.5-- +bool(true) + +--float 12.3456789000e10-- +bool(true) + +--float -12.3456789000e10-- +bool(true) + +--float .5-- +bool(true) + +--empty array-- +Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(true) + +--lowercase null-- +bool(true) + +--lowercase true-- +bool(true) + +--lowercase false-- +bool(true) + +--uppercase TRUE-- +bool(true) + +--uppercase FALSE-- +bool(true) + +--empty string DQ-- +Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - chmod() expects parameter 2 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - chmod() expects parameter 2 to be long, object given, %s(%d) +NULL + +--undefined var-- +bool(true) + +--unset var-- +bool(true) +===DONE=== + diff --git a/ext/standard/tests/file/copy_variation13.phpt b/ext/standard/tests/file/copy_variation13.phpt index a71c597e41..779f82b6f6 100644 --- a/ext/standard/tests/file/copy_variation13.phpt +++ b/ext/standard/tests/file/copy_variation13.phpt @@ -1,5 +1,5 @@ --TEST-- -Test copy() function: usage variations - src as dir and dest as an existing file (Bug #42243) +Test copy() function: usage variations - src as dir and dest as an existing file(Bug #42243) --FILE-- <?php /* Prototype: bool copy ( string $source, string $dest ); diff --git a/ext/standard/tests/file/copy_variation18.phpt b/ext/standard/tests/file/copy_variation18.phpt index 8781cebdd3..25145d6393 100644 --- a/ext/standard/tests/file/copy_variation18.phpt +++ b/ext/standard/tests/file/copy_variation18.phpt @@ -1,5 +1,7 @@ --TEST-- Test copy() function: usage variations - stat after copy +--XFAIL-- +Pending completion of Unicode streams --FILE-- <?php /* Prototype: bool copy ( string $source, string $dest ); @@ -16,7 +18,7 @@ require($file_path."/file.inc"); echo "*** Test copy() function: stat of file before and after copy ***\n"; $src_file_name = $file_path."/copy_variation18.tmp"; $file_handle = fopen($src_file_name, "w"); -fwrite($file_handle, str_repeat(b"Hello2world...\n", 100)); +fwrite($file_handle, str_repeat("Hello2world...\n", 100)); fclose($file_handle); $dest_file_name = $file_path."/copy_copy_variation18.tmp"; @@ -32,8 +34,13 @@ var_dump( copy($src_file_name, $dest_file_name) ); $stat_after_copy = stat($src_file_name); clearstatcache(); +// compare all stat fields except access time +$stat_keys_to_compare = array("dev", "ino", "mode", "nlink", "uid", "gid", + "rdev", "size", "mtime", "ctime", + "blksize", "blocks"); + echo "Comparing the stats of file before and after copy operation => "; -var_dump( compare_stats($stat_before_copy, $stat_after_copy, $all_stat_keys) ); +var_dump( compare_stats($stat_before_copy, $stat_after_copy, $stat_keys_to_compare) ); echo "*** Done ***\n"; ?> @@ -43,8 +50,10 @@ echo "*** Done ***\n"; unlink(dirname(__FILE__)."/copy_copy_variation18.tmp"); unlink(dirname(__FILE__)."/copy_variation18.tmp"); ?> ---EXPECT-- + +--EXPECTF-- *** Test copy() function: stat of file before and after copy *** Copy operation => bool(true) Comparing the stats of file before and after copy operation => bool(true) *** Done *** + diff --git a/ext/standard/tests/file/dirname_basic-win32.phpt b/ext/standard/tests/file/dirname_basic-win32.phpt new file mode 100644 index 0000000000..097b0fa474 --- /dev/null +++ b/ext/standard/tests/file/dirname_basic-win32.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test dirname() function : basic functionality +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : string dirname(string path) + * Description: Returns the directory name component of the path + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing dirname() : basic functionality ***\n"; + + +// Initialise all required variables +$paths = array( + '', + ' ', + 'c:', + 'c:\\', + 'c:/', + 'afile', + 'c:\test\afile', + 'c:\\test\\afile', + 'c://test//afile', + 'c:\test\afile\\', + '/usr/lib/locale/en_US', + '//usr/lib//locale/en_US', + '\\', + '\\\\', + '/', + '//', + '///', + '/usr/lib/locale/en_US/', + 'c:\windows/system32\drivers/etc\hosts', + '/usr\lib/locale\en_US', + ' c:\test\adir\afile.txt', + 'c:\test\adir\afile.txt ', + ' c:\test\adir\afile.txt ', + ' /usr/lib/locale/en_US', + '/usr/lib/locale/en_US ', + ' /usr/lib/locale/en_US ', + ' c:', + ' c:\test\adir\afile.txt', + '/usr', + '/usr/', + ); + +foreach ($paths as $path) { + var_dump( dirname($path) ); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing dirname() : basic functionality *** +unicode(0) "" +unicode(1) "." +unicode(2) "c:" +unicode(3) "c:\" +unicode(3) "c:\" +unicode(1) "." +unicode(7) "c:\test" +unicode(7) "c:\test" +unicode(8) "c://test" +unicode(7) "c:\test" +unicode(15) "/usr/lib/locale" +unicode(17) "//usr/lib//locale" +unicode(1) "\" +unicode(1) "\" +unicode(1) "\" +unicode(1) "\" +unicode(1) "\" +unicode(15) "/usr/lib/locale" +unicode(31) "c:\windows/system32\drivers/etc" +unicode(15) "/usr\lib/locale" +unicode(15) " c:\test\adir" +unicode(12) "c:\test\adir" +unicode(15) " c:\test\adir" +unicode(18) " /usr/lib/locale" +unicode(15) "/usr/lib/locale" +unicode(18) " /usr/lib/locale" +unicode(1) "." +unicode(14) " c:\test\adir" +unicode(1) "\" +unicode(1) "\" +===DONE=== diff --git a/ext/standard/tests/file/dirname_basic.phpt b/ext/standard/tests/file/dirname_basic.phpt new file mode 100644 index 0000000000..90ced2dd7f --- /dev/null +++ b/ext/standard/tests/file/dirname_basic.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test dirname() function : basic functionality +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : string dirname(string path) + * Description: Returns the directory name component of the path + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing dirname() : basic functionality ***\n"; + + +// Initialise all required variables +$paths = array( + '', + ' ', + 'c:', + 'c:\\', + 'c:/', + 'afile', + 'c:\test\afile', + 'c:\\test\\afile', + 'c://test//afile', + 'c:\test\afile\\', + '/usr/lib/locale/en_US', + '//usr/lib//locale/en_US', + '\\', + '\\\\', + '/', + '//', + '///', + '/usr/lib/locale/en_US/', + 'c:\windows/system32\drivers/etc\hosts', + '/usr\lib/locale\en_US', + ' c:\test\adir\afile.txt', + 'c:\test\adir\afile.txt ', + ' c:\test\adir\afile.txt ', + ' /usr/lib/locale/en_US', + '/usr/lib/locale/en_US ', + ' /usr/lib/locale/en_US ', + ' c:', + ' c:\test\adir\afile.txt', + '/usr', + '/usr/' + ); + +foreach ($paths as $path) { + var_dump( dirname($path) ); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing dirname() : basic functionality *** +unicode(0) "" +unicode(1) "." +unicode(1) "." +unicode(1) "." +unicode(1) "." +unicode(1) "." +unicode(1) "." +unicode(1) "." +unicode(8) "c://test" +unicode(1) "." +unicode(15) "/usr/lib/locale" +unicode(17) "//usr/lib//locale" +unicode(1) "." +unicode(1) "." +unicode(1) "/" +unicode(1) "/" +unicode(1) "/" +unicode(15) "/usr/lib/locale" +unicode(27) "c:\windows/system32\drivers" +unicode(8) "/usr\lib" +unicode(1) "." +unicode(1) "." +unicode(1) "." +unicode(18) " /usr/lib/locale" +unicode(15) "/usr/lib/locale" +unicode(18) " /usr/lib/locale" +unicode(1) "." +unicode(1) "." +unicode(1) "/" +unicode(1) "/" +===DONE=== + diff --git a/ext/standard/tests/file/dirname_error.phpt b/ext/standard/tests/file/dirname_error.phpt new file mode 100644 index 0000000000..dc7814f7f7 --- /dev/null +++ b/ext/standard/tests/file/dirname_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test dirname() function : error conditions +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string dirname(string path) + * Description: Returns the directory name component of the path + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing dirname() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing dirname() function with Zero arguments --\n"; +var_dump( dirname() ); + +//Test dirname with one more than the expected number of arguments +echo "\n-- Testing dirname() function with more than expected no. of arguments --\n"; +$path = 'string_val'; +$extra_arg = 10; +var_dump( dirname($path, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing dirname() : error conditions *** + +-- Testing dirname() function with Zero arguments -- + +Warning: dirname() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing dirname() function with more than expected no. of arguments -- + +Warning: dirname() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== + diff --git a/ext/standard/tests/file/dirname_variation1.phpt b/ext/standard/tests/file/dirname_variation1.phpt new file mode 100644 index 0000000000..a15918071c --- /dev/null +++ b/ext/standard/tests/file/dirname_variation1.phpt @@ -0,0 +1,190 @@ +--TEST-- +Test dirname() function : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string dirname(string path) + * Description: Returns the directory name component of the path + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing dirname() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for path + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( dirname($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing dirname() : usage variation *** + +--int 0-- +unicode(1) "." + +--int 1-- +unicode(1) "." + +--int 12345-- +unicode(1) "." + +--int -12345-- +unicode(1) "." + +--float 10.5-- +unicode(1) "." + +--float -10.5-- +unicode(1) "." + +--float 12.3456789000e10-- +unicode(1) "." + +--float -12.3456789000e10-- +unicode(1) "." + +--float .5-- +unicode(1) "." + +--empty array-- +Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--associative array-- +Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--uppercase NULL-- +unicode(0) "" + +--lowercase null-- +unicode(0) "" + +--lowercase true-- +unicode(1) "." + +--lowercase false-- +unicode(0) "" + +--uppercase TRUE-- +unicode(1) "." + +--uppercase FALSE-- +unicode(0) "" + +--empty string DQ-- +unicode(0) "" + +--empty string SQ-- +unicode(0) "" + +--instance of classWithToString-- +unicode(1) "." + +--instance of classWithoutToString-- +Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), object given, %s(%d) +NULL + +--undefined var-- +unicode(0) "" + +--unset var-- +unicode(0) "" +===DONE=== + diff --git a/ext/standard/tests/file/disk.phpt b/ext/standard/tests/file/disk.phpt index a048af6ccb..e1a74fc984 100644 --- a/ext/standard/tests/file/disk.phpt +++ b/ext/standard/tests/file/disk.phpt @@ -25,7 +25,7 @@ var_dump(disk_total_space("/some/path/here")); echo "Done\n"; ?> ---EXPECTF-- +--EXPECTF-- Warning: disk_free_space() expects exactly 1 parameter, 0 given in %s on line %d NULL @@ -37,8 +37,8 @@ bool(false) Warning: disk_total_space(): No such file or directory in %s on line %d bool(false) -float(%d) -float(%d) +float(%f) +float(%f) Warning: disk_free_space(): No such file or directory in %s on line %d bool(false) diff --git a/ext/standard/tests/file/disk_free_space_basic.phpt b/ext/standard/tests/file/disk_free_space_basic.phpt index f8684e92a9..cae37bad59 100644 --- a/ext/standard/tests/file/disk_free_space_basic.phpt +++ b/ext/standard/tests/file/disk_free_space_basic.phpt @@ -7,27 +7,26 @@ memory_limit=32M /* * Prototype: float disk_free_space( string directory ) * Description: Given a string containing a directory, this function - * will return the number of bytes available on the corresponding - * filesystem or disk partition + * will return the number of bytes available on the corresponding + * filesystem or disk partition */ $file_path = dirname(__FILE__); +include($file_path."/file.inc"); echo "*** Testing with existing directory ***\n"; var_dump( disk_free_space($file_path) ); var_dump( diskfreespace($file_path) ); +$dir = "/disk_free_space"; echo "*** Testing with newly created directory ***\n"; -$dir = "/disk_free_space"; mkdir($file_path.$dir); echo" \n Free Space before writing to a file\n"; $space1 = disk_free_space($file_path.$dir); -var_dump( $space1 ); +var_dump($space1); -$fh = fopen($file_path.$dir."/disk_free_space.tmp", "a"); -for( $i=1; $i<=1000; $i++) -fwrite($fh, (binary)"x"); -fclose($fh); +fill_buffer($buffer, "text", 3000000); +file_put_contents($file_path.$dir."/disk_free_space.tmp", $buffer); echo "\n Free Space after writing to a file\n"; $space2 = disk_free_space($file_path.$dir); @@ -38,33 +37,29 @@ if( $space1 > $space2 ) else echo "\n Free Space Value Is Incorrect\n"; -echo "*** Testing with Binary Input ***\n"; -var_dump( disk_free_space(b"$file_path") ); - -echo"\n--- Done ---"; +echo"\n-- Done --"; ?> --CLEAN-- <?php $file_path = dirname(__FILE__); -unlink($file_path."/disk_free_space/disk_free_space.tmp"); -rmdir($file_path."/disk_free_space"); +$dir = "/disk_free_space"; +unlink($file_path.$dir."/disk_free_space.tmp"); +rmdir($file_path.$dir); ?> --EXPECTF-- *** Testing with existing directory *** -float(%d) -float(%d) +float(%f) +float(%f) *** Testing with newly created directory *** Free Space before writing to a file -float(%d) +float(%f) Free Space after writing to a file -float(%d) +float(%f) Free Space Value Is Correct -*** Testing with Binary Input *** -float(%d) ---- Done --- +-- Done -- diff --git a/ext/standard/tests/file/disk_free_space_error.phpt b/ext/standard/tests/file/disk_free_space_error.phpt index aad4e4e452..945b7b9c84 100644 --- a/ext/standard/tests/file/disk_free_space_error.phpt +++ b/ext/standard/tests/file/disk_free_space_error.phpt @@ -1,15 +1,15 @@ --TEST-- -Test disk_free_space and its alias diskfreespace() functions : error conditions. +Test disk_free_space and its alias diskfreespace() functions : error conditions --SKIPIF-- <?php -if(substr(PHP_OS, 0, 3) == 'WIN') - die("skip Not valid on Windows"); +if(substr(PHP_OS, 0, 3) == 'WIN' ) + die("skip Not Valid for Windows"); ?> --FILE-- <?php /* * Prototype: float disk_free_space( string directory ) - * Description: Given a string containing a directory, this function will + * Description: Given a string containing a directory, this function will * return the number of bytes available on the corresponding * filesystem or disk partition */ @@ -27,7 +27,7 @@ var_dump( disk_free_space( $file_path."/dir1" )); // Invalid directory var_dump( diskfreespace( $file_path."/dir1" )); $fh = fopen( $file_path."/disk_free_space.tmp", "w" ); -fwrite( $fh, (binary)" Garbage data for the temporary file" ); +fwrite( $fh, " Garbage data for the temporary file" ); var_dump( disk_free_space( $file_path."/disk_free_space.tmp" )); // file input instead of directory var_dump( diskfreespace( $file_path."/disk_free_space.tmp" )); fclose($fh); @@ -55,12 +55,12 @@ NULL Warning: diskfreespace() expects exactly 1 parameter, 2 given in %s on line %d NULL -Warning: disk_free_space(): No such file or directory in %s on line %d +Warning: disk_free_space(): %s in %s on line %d bool(false) -Warning: diskfreespace(): No such file or directory in %s on line %d +Warning: diskfreespace(): %s in %s on line %d bool(false) -float(%d) -float(%d) +float(%f) +float(%f) -- Done -- diff --git a/ext/standard/tests/file/disk_free_space_variation.phpt b/ext/standard/tests/file/disk_free_space_variation.phpt index c1809986fd..01fa183735 100644 --- a/ext/standard/tests/file/disk_free_space_variation.phpt +++ b/ext/standard/tests/file/disk_free_space_variation.phpt @@ -1,5 +1,5 @@ --TEST-- -Test disk_free_space and its alias diskfreespace() functions : Usage Variations +Test disk_free_space and its alias diskfreespace() functions : usage variations --FILE-- <?php /* @@ -11,15 +11,16 @@ Test disk_free_space and its alias diskfreespace() functions : Usage Variations $file_path = dirname(__FILE__); -echo "*** Testing with a directory ***\n"; +echo "*** Testing disk_free_space() function with a directory ***\n"; var_dump( disk_free_space($file_path."/..") ); var_dump( diskfreespace($file_path."/..") ); -echo "\nTesting for the return type ***\n"; +echo "\n*** Testing for the return type ***\n"; $return_value = disk_free_space($file_path); var_dump( is_float($return_value) ); -echo "\n*** Testing with different directory combinations ***"; +echo "\n*** Testing disk_free_space() function with different styles of file and directory ***"; + $dir = "/disk_free_space"; mkdir($file_path.$dir); @@ -41,15 +42,15 @@ $dirs_arr = array( $file_path.$dir.chr(0), $file_path."/.".$dir.chr(0), ".".chr(0).$file_path.$dir, - ".".chr(0).$file_path.$dir.chr(0) + ".".chr(0).$file_path.$dir.chr(0) ); $count = 1; /* loop through to test each element the above array */ -foreach($dirs_arr as $dir1) { +foreach($dirs_arr as $dir) { echo "\n-- Iteration $count --\n"; - var_dump( disk_free_space( $dir1 ) ); - var_dump( diskfreespace( $dir1 ) ); + var_dump( disk_free_space( $dir ) ); + var_dump( diskfreespace( $dir ) ); $count++; } @@ -58,66 +59,65 @@ echo"\n--- Done ---"; --CLEAN-- <?php -$file_path = dirname(__FILE__); -rmdir($file_path."/disk_free_space"); +$file_path = dirname(__FILE__)."/disk_free_space"; +rmdir($file_path); ?> - --EXPECTF-- -*** Testing with a directory *** -float(%d) -float(%d) +*** Testing disk_free_space() function with a directory *** +float(%f) +float(%f) -Testing for the return type *** +*** Testing for the return type *** bool(true) -*** Testing with different directory combinations *** +*** Testing disk_free_space() function with different styles of file and directory *** -- Iteration 1 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 2 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 3 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 4 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 5 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 6 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 7 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 8 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 9 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 10 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 11 -- -float(%d) -float(%d) +float(%f) +float(%f) -- Iteration 12 -- -float(%d) -float(%d) +float(%f) +float(%f) --- Done --- diff --git a/ext/standard/tests/file/disk_total_space_basic.phpt b/ext/standard/tests/file/disk_total_space_basic.phpt index d211f39437..dd459c2819 100644 --- a/ext/standard/tests/file/disk_total_space_basic.phpt +++ b/ext/standard/tests/file/disk_total_space_basic.phpt @@ -1,34 +1,36 @@ --TEST-- Test disk_total_space() function : basic functionality +--XFAIL-- +Pending completion of Unicode streams --FILE-- <?php /* * Prototype: float disk_total_space( string $directory ); - * Description: given a string containing a directory, this function will - * return the total number of bytes on the corresponding filesyatem - * or disk partition. + * Description: given a string containing a directory, this + * function will return the total number of bytes + * on the corresponding filesyatem or disk partition. */ $file_path = dirname(__FILE__); -echo "*** Testing with normal directory ***\n"; +echo "*** Testing with existing directory ***\n"; var_dump( disk_total_space($file_path) ); echo "*** Testing with newly created directory ***\n"; -$dir = "/disk_total_space"; +mkdir($file_path."/disk_total_space"); +var_dump( disk_total_space($file_path."/disk_total_space") ); -mkdir($file_path.$dir); -var_dump( disk_total_space($file_path.$dir) ); -$fh = fopen($file_path.$dir."/disk_total_space.tmp", "w"); -fwrite($fh, (binary)"Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data"); +$fh = fopen($file_path."/disk_total_space/disk_total_space.tmp", "w"); +fwrite($fh, "Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data"); fclose($fh); -echo"\nTotal Space after writing to a file\n"; -var_dump( disk_total_space($file_path.$dir) ); +echo" \n Total Space after writing to a file\n"; +var_dump( disk_total_space($file_path."/disk_total_space") ); -echo"\n-- Done --"; +echo"\n--- Done ---"; ?> + --CLEAN-- <?php $file_path = dirname(__FILE__); @@ -37,12 +39,12 @@ rmdir($file_path."/disk_total_space"); ?> --EXPECTF-- -*** Testing with normal directory *** -float(%d) +*** Testing with existing directory *** +float(%f) *** Testing with newly created directory *** -float(%d) - -Total Space after writing to a file -float(%d) +float(%f) + + Total Space after writing to a file +float(%f) --- Done -- +--- Done --- diff --git a/ext/standard/tests/file/disk_total_space_error.phpt b/ext/standard/tests/file/disk_total_space_error.phpt index 3888b7e09d..d49589af41 100644 --- a/ext/standard/tests/file/disk_total_space_error.phpt +++ b/ext/standard/tests/file/disk_total_space_error.phpt @@ -1,15 +1,17 @@ --TEST-- Test disk_total_space() function : error conditions +--XFAIL-- +Pending completion of Unicode streams --SKIPIF-- <?php -if(substr(PHP_OS, 0, 3) == 'WIN') - die("skip Not valid on Windows"); +if(substr(PHP_OS, 0, 3) == 'WIN' ) + die("skip Not Valid for Windows"); ?> --FILE-- <?php /* * Prototype: float disk_total_space( string $directory ); - * Description: given a string containing a directory, this function + * Description: given a string containing a directory, this function * will return the total number of bytes on the corresponding * filesystem or disk partition */ @@ -24,7 +26,7 @@ var_dump( disk_total_space( $file_path, "extra argument") ); // More than valid var_dump( disk_total_space( $file_path."/dir1" )); // Invalid directory $fh = fopen( $file_path."/disk_total_space.tmp", "w" ); -fwrite( $fh, (binary)" Garbage data for the temporary file" ); +fwrite( $fh, " Garbage data for the temporary file" ); var_dump( disk_total_space( $file_path."/disk_total_space.tmp" )); // file input instead of directory fclose($fh); @@ -46,6 +48,6 @@ NULL Warning: disk_total_space(): No such file or directory in %s on line %d bool(false) -float(%d) +float(%f) --- Done --- diff --git a/ext/standard/tests/file/disk_total_space_variation.phpt b/ext/standard/tests/file/disk_total_space_variation.phpt index c03ba594bd..6cd96cd872 100644 --- a/ext/standard/tests/file/disk_total_space_variation.phpt +++ b/ext/standard/tests/file/disk_total_space_variation.phpt @@ -1,5 +1,5 @@ --TEST-- -Testing disk_total_space() functions : Usage Variations. +Test disk_total_space() functions : usage variations --FILE-- <?php /* @@ -18,9 +18,9 @@ echo "\nTesting for the return type ***\n"; $return_value = disk_total_space($file_path); var_dump( is_float($return_value) ); -echo "\n*** Testing with different directory combinations ***"; -$dir = "/disk_total_space"; +echo "\n*** Testing disk_total_space() function with different directory combinations ***"; +$dir = "/disk_total_space"; mkdir($file_path.$dir); $dirs_arr = array( @@ -29,7 +29,7 @@ $dirs_arr = array( $file_path."/.".$dir, /* Testing a file trailing slash */ - $file_path."".$dir."/", + $file_path.$dir."/", $file_path."/.".$dir."/", /* Testing file with double trailing slashes */ @@ -44,7 +44,6 @@ $dirs_arr = array( ".".chr(0).$file_path.$dir.chr(0) ); - $count = 1; /* loop through to test each element the above array */ foreach($dirs_arr as $dir1) { @@ -53,63 +52,57 @@ foreach($dirs_arr as $dir1) { $count++; } -echo "*** Testing with Binary Input ***\n"; -var_dump( disk_total_space(b"$file_path") ); - echo"\n--- Done ---"; ?> --CLEAN-- <?php $file_path = dirname(__FILE__); -rmdir($file_path."/disk_total_space"); +$dir = "/disk_total_space"; +rmdir($file_path.$dir); ?> - - --EXPECTF-- *** Testing with a directory *** -float(%d) +float(%f) Testing for the return type *** bool(true) -*** Testing with different directory combinations *** +*** Testing disk_total_space() function with different directory combinations *** -- Iteration 1 -- -float(%d) +float(%f) -- Iteration 2 -- -float(%d) +float(%f) -- Iteration 3 -- -float(%d) +float(%f) -- Iteration 4 -- -float(%d) +float(%f) -- Iteration 5 -- -float(%d) +float(%f) -- Iteration 6 -- -float(%d) +float(%f) -- Iteration 7 -- -float(%d) +float(%f) -- Iteration 8 -- -float(%d) +float(%f) -- Iteration 9 -- -float(%d) +float(%f) -- Iteration 10 -- -float(%d) +float(%f) -- Iteration 11 -- -float(%d) +float(%f) -- Iteration 12 -- -float(%d) -*** Testing with Binary Input *** -float(%d) +float(%f) --- Done --- diff --git a/ext/standard/tests/file/feof_basic.phpt b/ext/standard/tests/file/feof_basic.phpt new file mode 100644 index 0000000000..7403e22cfa --- /dev/null +++ b/ext/standard/tests/file/feof_basic.phpt @@ -0,0 +1,103 @@ +--TEST-- +Test feof() function : basic functionality +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto bool feof(resource fp) + * Description: Test for end-of-file on a file pointer + * Source code: ext/standard/file.c + * Alias to functions: gzeof + */ + +echo "*** Testing feof() : basic functionality ***\n"; +$tmpFile1 = __FILE__.".tmp1"; +$h = fopen($tmpFile1, 'wb'); +$count = 10; +for ($i = 1; $i <= $count; $i++) { + fwrite($h, "some data $i\n"); +} +fclose($h); + +echo "\n*** testing reading complete file using feof to stop ***\n"; +$h = fopen($tmpFile1, 'rb'); + +//feof is not set to true until you try to read past the end of file. +//so fgets will be called even if we are at the end of the file on +//last time to set the eof flag but it will fail to read. +$lastline = ""; +while (!feof($h)) { + $previousLine = $lastline; + $lastline = fgets($h); +} +echo $previousLine; +var_dump($lastline); // this should be false +fclose($h); + +$tmpFile2 = __FILE__.".tmp2"; +$h = fopen($tmpFile2, 'wb+'); +$count = 10; +echo "*** writing $count lines, testing feof ***\n"; +for ($i = 1; $i <=$count; $i++) { + fwrite($h, "some data $i\n"); + var_dump(feof($h)); +} + +echo "*** testing feof on unclosed file after a read ***\n"; + +fread($h, 100); +var_dump(feof($h)); + +$eofPointer = ftell($h); + +echo "*** testing feof after a seek to near the beginning ***\n"; +fseek($h, 20, SEEK_SET); +var_dump(feof($h)); + +echo "*** testing feof after a seek to end ***\n"; +fseek($h, $eofPointer, SEEK_SET); +var_dump(feof($h)); + +echo "*** testing feof after a seek passed the end ***\n"; +fseek($h, $eofPointer + 1000, SEEK_SET); +var_dump(feof($h)); + +echo "*** closing file, testing eof ***\n"; +fclose($h); +feof($h); +unlink($tmpFile1); +unlink($tmpFile2); + +echo "Done"; +?> +--EXPECTF-- +*** Testing feof() : basic functionality *** + +*** testing reading complete file using feof to stop *** +some data 10 +bool(false) +*** writing 10 lines, testing feof *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** testing feof on unclosed file after a read *** +bool(true) +*** testing feof after a seek to near the beginning *** +bool(false) +*** testing feof after a seek to end *** +bool(false) +*** testing feof after a seek passed the end *** +bool(false) +*** closing file, testing eof *** + +Warning: feof(): %d is not a valid stream resource in %s on line %d +Done diff --git a/ext/standard/tests/file/fflush_error.phpt b/ext/standard/tests/file/fflush_error.phpt index 0e82e47fc1..b1c59015de 100644 --- a/ext/standard/tests/file/fflush_error.phpt +++ b/ext/standard/tests/file/fflush_error.phpt @@ -24,9 +24,10 @@ if($file_handle == false) var_dump( fflush($file_handle, $file_handle) ); fclose($file_handle); +fflush($file_handle); // test invalid arguments : non-resources -echo "-- Testing fflush(): with invalid arguments --\n"; +echo "\n-- Testing fflush(): with invalid arguments --\n"; $invalid_args = array ( "string", 10, @@ -41,7 +42,7 @@ for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) { echo "-- Iteration $loop_counter --\n"; var_dump( fflush($invalid_args[$loop_counter - 1]) ); } -echo "\n*** Done ***"; +echo "Done\n"; ?> --CLEAN-- @@ -60,6 +61,9 @@ NULL Warning: fflush() expects exactly 1 parameter, 2 given in %s on line %d NULL + +Warning: fflush(): 5 is not a valid stream resource in %s on line %d + -- Testing fflush(): with invalid arguments -- -- Iteration 1 -- @@ -85,5 +89,5 @@ NULL Warning: fflush() expects parameter 1 to be resource, object given in %s on line %d NULL +Done -*** Done *** diff --git a/ext/standard/tests/file/fgetc_basic.phpt b/ext/standard/tests/file/fgetc_basic.phpt index d4c8bec7eb..2bf6b09e49 100644 --- a/ext/standard/tests/file/fgetc_basic.phpt +++ b/ext/standard/tests/file/fgetc_basic.phpt @@ -1,5 +1,7 @@ --TEST-- Test fgetc() function : basic functionality +--XFAIL-- +Pending completion of Unicode streams --FILE-- <?php /* @@ -541,3 +543,4 @@ int(6) bool(false) resource(%d) of type (stream) Done + diff --git a/ext/standard/tests/file/fgetc_variation2.phpt b/ext/standard/tests/file/fgetc_variation2.phpt index e7f22b3041..9fbefeaaa8 100644 --- a/ext/standard/tests/file/fgetc_variation2.phpt +++ b/ext/standard/tests/file/fgetc_variation2.phpt @@ -1,5 +1,7 @@ --TEST-- Test fgetc() function : usage variations - closed handle +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php /* @@ -47,6 +49,6 @@ bool(false) Notice: Undefined variable: file_handle in %s on line %d -Warning: fgetc(): supplied argument is not a valid stream resource in %s on line %d +Warning: fgetc() expects parameter 1 to be resource, null given in %s on line %d bool(false) Done diff --git a/ext/standard/tests/file/fgets_error.phpt b/ext/standard/tests/file/fgets_error.phpt index 27d0b12930..9857b4d3fc 100644 --- a/ext/standard/tests/file/fgets_error.phpt +++ b/ext/standard/tests/file/fgets_error.phpt @@ -1,5 +1,7 @@ --TEST-- Test fgets() function : error conditions +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php /* @@ -60,11 +62,11 @@ echo "Done\n"; -- Testing fgets() with zero argument -- Warning: fgets() expects at least 1 parameter, 0 given in %s on line %d -NULL +bool(false) -- Testing fgets() with more than expected number of arguments -- Warning: fgets() expects at most 2 parameters, 3 given in %s on line %d -NULL +bool(false) -- Testing fgets() with invalid length arguments -- Warning: fgets(): Length parameter must be greater than 0 in %s on line %d @@ -77,31 +79,32 @@ bool(false) -- Iteration 1 -- Warning: fgets() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: fgets() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: fgets() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: fgets() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: fgets() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: fgets() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing fgets() with closed/unset file handle -- -Warning: fgets(): 5 is not a valid stream resource in %s on line %d +Warning: fgets(): %d is not a valid stream resource in %s on line %d bool(false) Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Done + diff --git a/ext/standard/tests/file/fgets_socket_variation1.phpt b/ext/standard/tests/file/fgets_socket_variation1.phpt new file mode 100644 index 0000000000..a4a720c015 --- /dev/null +++ b/ext/standard/tests/file/fgets_socket_variation1.phpt @@ -0,0 +1,58 @@ +--TEST-- +fgets() with a socket stream +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +if (!$client) { + die("Unable to create socket"); +} + +/* Accept that connection */ +$socket = stream_socket_accept($server); + +echo "Write some data:\n"; +fwrite($socket, "line1\nline2\nline3\n"); + + +echo "\n\nRead a line from the client:\n"; +var_dump(fgets($client)); + +echo "\n\nRead another line from the client:\n"; +var_dump(fgets($client)); + +echo "\n\nClose the server side socket and read the remaining data from the client\n"; +fclose($socket); +fclose($server); +while(!feof($client)) { + fread($client, 1); +} + +echo "done\n"; + +?> +--EXPECT-- +Write some data: + + +Read a line from the client: +unicode(6) "line1 +" + + +Read another line from the client: +unicode(6) "line2 +" + + +Close the server side socket and read the remaining data from the client +done diff --git a/ext/standard/tests/file/fgets_socket_variation2.phpt b/ext/standard/tests/file/fgets_socket_variation2.phpt new file mode 100644 index 0000000000..468a7459ac --- /dev/null +++ b/ext/standard/tests/file/fgets_socket_variation2.phpt @@ -0,0 +1,65 @@ +--TEST-- +fgets() over a socket with more than a buffer's worth of data +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php + +// create a file +$filename = __FILE__ . ".tmp"; +$fd = fopen($filename, "w+"); + +// populate the file with lines of data +define("LINE_OF_DATA", "12345678\n"); +for ($i = 0; $i < 1000; $i++) { + fwrite($fd, LINE_OF_DATA); +} +fclose($fd); + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +if (!$client) { + die("Unable to create socket"); +} + +/* Accept that connection */ +$socket = stream_socket_accept($server); + +echo "Write data from the file:\n"; +$data = file_get_contents($filename); +unlink($filename); + +var_dump(fwrite($socket, $data)); +fclose($socket); + +echo "\nRead lines from the client\n"; +while ($line = fgets($client,256)) { + if (strcmp($line, LINE_OF_DATA) != 0) { + echo "Error - $line does not match " . LINE_OF_DATA; + break; + } +} + +echo "\nClose the server side socket and read the remaining data from the client\n"; +fclose($server); +while(!feof($client)) { + fread($client, 1); +} + +echo "done\n"; + +?> +--EXPECT-- +Write data from the file: +int(9000) + +Read lines from the client + +Close the server side socket and read the remaining data from the client +done diff --git a/ext/standard/tests/file/fgets_variation2.phpt b/ext/standard/tests/file/fgets_variation2.phpt index 60205a558c..a723782e78 100644 --- a/ext/standard/tests/file/fgets_variation2.phpt +++ b/ext/standard/tests/file/fgets_variation2.phpt @@ -1,5 +1,7 @@ --TEST-- Test fgets() function : usage variations - closed handle +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php /* @@ -43,20 +45,21 @@ echo "Done"; *** Testing fgets() : usage variations *** -- Testing fgets() with closed handle -- -Warning: fgets(): 6 is not a valid stream resource in %s on line %s +Warning: fgets(): %d is not a valid stream resource in %s on line %d bool(false) -Warning: fgets(): 6 is not a valid stream resource in %s on line %s +Warning: fgets(): %d is not a valid stream resource in %s on line %d bool(false) -- Testing fgets() with unset handle -- -Notice: Undefined variable: file_handle in %s on line %s +Notice: Undefined variable: file_handle in %s on line %d -Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s -NULL +Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d +bool(false) -Notice: Undefined variable: file_handle in %s on line %s +Notice: Undefined variable: file_handle in %s on line %d -Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s -NULL +Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d +bool(false) Done + diff --git a/ext/standard/tests/file/file.inc b/ext/standard/tests/file/file.inc index 4a52b1d51d..5714308860 100644 --- a/ext/standard/tests/file/file.inc +++ b/ext/standard/tests/file/file.inc @@ -279,7 +279,7 @@ function create_files( $file_path, if ( $content_type == "empty" ) { $return_value['filled'] = $count; } else { - // fill the file with specifiec type of data and size + //fill the file with specifiec type of data and size $tmp_name_suffix = $name_suffix; for($loop_counter = 1; $loop_counter <= $count; $loop_counter ++) { $filename = $file_path."/".$name_prefix.$tmp_name_suffix.$file_extension; @@ -577,7 +577,7 @@ Description: $stat2 = second stat array $op = type of the comparision to be perform between elements of stat1 and stat2 "!=" compare for not equal - "==" compare for equality + "==" comprae for equality ">" if each element of stat1 is > than stat2 "<" if each element of stat1 is < than stat2 $fields = contains the key of the elements that needs to be compared. @@ -585,10 +585,7 @@ Description: $flag = specify true to dump the stat1 and stat2 */ -$all_stat_keys = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - "dev", "ino", "mode", "nlink", "uid", "gid", - "rdev", "size", "atime", "mtime", "ctime", - "blksize", "blocks"); +$all_stat_keys = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, "dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime", "blksize", "blocks"); function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) { // dump the stat if requested @@ -638,8 +635,6 @@ function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) { // if the result is false(i.e values are not as expected), // dump the stat array so that easy to figure out the error if ( $result == false ) { - echo "\n Dumping diff between stat array 1 and 2...\n"; - var_dump(array_diff($stat1, $stat2)); echo "\n Dumping stat array 1...\n"; var_dump($stat1); echo "\n Dumping stat array 2...\n"; diff --git a/ext/standard/tests/file/file_exists_error.phpt b/ext/standard/tests/file/file_exists_error.phpt new file mode 100644 index 0000000000..bd890f9b29 --- /dev/null +++ b/ext/standard/tests/file/file_exists_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test file_exists() function : error conditions +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto bool file_exists(string filename) + * Description: Returns true if filename exists + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing file_exists() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing file_exists() function with Zero arguments --\n"; +var_dump( file_exists() ); + +//Test file_exists with one more than the expected number of arguments +echo "\n-- Testing file_exists() function with more than expected no. of arguments --\n"; +$filename = 'string_val'; +$extra_arg = 10; +var_dump( file_exists($filename, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing file_exists() : error conditions *** + +-- Testing file_exists() function with Zero arguments -- + +Warning: file_exists() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing file_exists() function with more than expected no. of arguments -- + +Warning: file_exists() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/file/file_exists_variation1.phpt b/ext/standard/tests/file/file_exists_variation1.phpt new file mode 100644 index 0000000000..35c86a2808 --- /dev/null +++ b/ext/standard/tests/file/file_exists_variation1.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test file_exists() function : usage variations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto bool file_exists(string filename) + * Description: Returns true if filename exists + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing file_exists() : usage variations ***\n"; + +var_dump(file_exists(NULL)); +var_dump(file_exists(false)); +var_dump(file_exists('')); +var_dump(file_exists(' ')); +var_dump(file_exists('|')); +echo "Done"; +?> + +--EXPECTF-- +*** Testing file_exists() : usage variations *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/file_get_contents_basic.phpt b/ext/standard/tests/file/file_get_contents_basic.phpt new file mode 100644 index 0000000000..e17a779bc1 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +file_get_contents() function : basic functionality +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php + +/* Prototype: string file_get_contents( string $filename[, bool $use_include_path[, + * resource $context[, int $offset[, int $maxlen]]]] ) + * Description: Reads entire file into a string + */ + +$file_path = dirname(__FILE__); +include($file_path."/file.inc"); + +echo "*** Testing the basic functionality of the file_get_contents() function ***\n"; + +echo "-- Testing with simple valid data file --\n"; + + +create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte"); +var_dump( file_get_contents($file_path."/file1.tmp") ); +delete_files($file_path, 1); + +echo "\n-- Testing with empty file --\n"; + +create_files($file_path, 1, "empty", 0755, 100, "w", "file", 1, "byte"); +var_dump( file_get_contents($file_path."/file1.tmp") ); +delete_files($file_path, 1); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/file_put_contents.tmp"); +unlink($file_path."/file_put_contents1.tmp"); +?> +--EXPECTF-- +*** Testing the basic functionality of the file_get_contents() function *** +-- Testing with simple valid data file -- +unicode(100) "text text text text text text text text text text text text text text text text text text text text " + +-- Testing with empty file -- +unicode(0) "" + +*** Done *** diff --git a/ext/standard/tests/file/file_get_contents_error.phpt b/ext/standard/tests/file/file_get_contents_error.phpt new file mode 100644 index 0000000000..5d1ee1c5a0 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_error.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test file_get_contents() function : error conditions +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: string file_get_contents( string $filename{, bool $use_include_path[, + * resource $context[, int $offset[, int $maxlen]]]] ) + * Description: Reads entire file into a string + */ + +echo "*** Testing error conditions ***\n"; + +$file_path = dirname(__FILE__); +include($file_path."/file.inc"); + +echo "\n-- Testing with Non-existing file --\n"; +print( file_get_contents("/no/such/file/or/dir") ); + +echo "\n-- Testing No.of arguments less than expected --\n"; +print( file_get_contents() ); + +echo "\n-- Testing No.of arguments greater than expected --\n"; + +create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte"); +$file_handle = fopen($file_path."/file_put_contents_error.tmp", "w"); +print( file_get_contents($file_path."/file1.tmp", false, $file_handle, 1, 2, "extra_argument") ); + +echo "\n-- Testing for invalid negative maxlen values --"; +var_dump( file_get_contents($file_path."/file1.tmp", FALSE, $file_handle, 0, -5) ); + +delete_files($file_path, 1); +fclose($file_handle); +unlink($file_path."/file_put_contents_error.tmp"); + +echo "\n*** Done ***\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/file_put_contents_error.tmp"); +unlink($file_path."/file_put_contents1.tmp"); + +?> +--EXPECTF-- +*** Testing error conditions *** + +-- Testing with Non-existing file -- + +Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d + +-- Testing No.of arguments less than expected -- + +Warning: file_get_contents() expects at least 1 parameter, 0 given in %s on line %d + +-- Testing No.of arguments greater than expected -- + +Warning: file_get_contents() expects at most 5 parameters, 6 given in %s on line %d + +-- Testing for invalid negative maxlen values -- +Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d +bool(false) + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/file_get_contents_variation1.phpt b/ext/standard/tests/file/file_get_contents_variation1.phpt new file mode 100644 index 0000000000..de809c3f9a --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation1.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test file_get_contents() function : variation - include path testing +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; + +require_once('fopen_include_path.inc'); + +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "fileGetContentsVar1.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = "afile.txt"; +$secondFile = $dir2."/".$filename; + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $secondFile, $filename; + $h = fopen($secondFile, "w"); + fwrite($h, "File in include path"); + fclose($h); + $line = file_get_contents($filename, true); + echo "$line\n"; + unlink($secondFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing file_get_contents() : variation *** +File in include path +===DONE=== diff --git a/ext/standard/tests/file/file_get_contents_variation2.phpt b/ext/standard/tests/file/file_get_contents_variation2.phpt new file mode 100644 index 0000000000..29f3838ddd --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation2.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test file_get_contents() function : variation - include path testing +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; + + +require_once('fopen_include_path.inc'); + +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "FileGetContentsVar2.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = 'FileGetContentsVar2.tmp'; +$scriptLocFile = dirname(__FILE__)."/".$filename; + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $scriptLocFile, $filename; + $h = fopen($scriptLocFile, "w"); + fwrite($h, "File in script location"); + fclose($h); + $line = file_get_contents($filename, true); + echo "$line\n"; + unlink($scriptLocFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing file_get_contents() : variation *** +File in script location +===DONE=== diff --git a/ext/standard/tests/file/file_get_contents_variation3.phpt b/ext/standard/tests/file/file_get_contents_variation3.phpt new file mode 100644 index 0000000000..1de2954d2b --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation3.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test file_get_contents() function : usage variation - different type for use_include_path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'FileGetContentsVar3.tmp'; +$absFile = dirname(__FILE__).'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + + + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for use_include_path + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( file_get_contents($absFile, $value) ); +}; + +unlink($absFile); + +?> +===DONE=== +--EXPECTF-- +*** Testing file_get_contents() : usage variation *** + +--int 0-- +unicode(13) "contents read" + +--int 1-- +unicode(13) "contents read" + +--int 12345-- +unicode(%d) "contents read" + +--int -12345-- +unicode(%d) "contents read" + +--float 10.5-- +unicode(%d) "contents read" + +--float -10.5-- +unicode(%d) "contents read" + +--float 12.3456789000e10-- +unicode(%d) "contents read" + +--float -12.3456789000e10-- +unicode(%d) "contents read" + +--float .5-- +unicode(%d) "contents read" + +--empty array-- +Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d) +NULL + +--uppercase NULL-- +unicode(%d) "contents read" + +--lowercase null-- +unicode(%d) "contents read" + +--lowercase true-- +unicode(%d) "contents read" + +--lowercase false-- +unicode(%d) "contents read" + +--uppercase TRUE-- +unicode(%d) "contents read" + +--uppercase FALSE-- +unicode(%d) "contents read" + +--empty string DQ-- +unicode(%d) "contents read" + +--empty string SQ-- +unicode(%d) "contents read" + +--string DQ-- +unicode(%d) "contents read" + +--string SQ-- +unicode(%d) "contents read" + +--mixed case string-- +unicode(%d) "contents read" + +--heredoc-- +unicode(%d) "contents read" + +--instance of classWithToString-- +Error: 2 - file_get_contents() expects parameter 2 to be boolean, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - file_get_contents() expects parameter 2 to be boolean, object given, %s(%d) +NULL + +--undefined var-- +unicode(%d) "contents read" + +--unset var-- +unicode(%d) "contents read" +===DONE=== diff --git a/ext/standard/tests/file/file_get_contents_variation4.phpt b/ext/standard/tests/file/file_get_contents_variation4.phpt new file mode 100644 index 0000000000..e7b8650140 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation4.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test file_get_contents() function : usage variation - different types for context. +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'FileGetContentsVar4.tmp'; +$absFile = dirname(__FILE__).'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + +$fileRes = fopen(__FILE__,'r'); +$strContext = stream_context_create(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + //non context resource + 'file resource' => $fileRes, + + //valid stream context + 'stream context' => $strContext, +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( file_get_contents($absFile, false, $value) ); +}; + +unlink($absFile); +fclose($fileRes); + +?> +===DONE=== +--EXPECTF-- +*** Testing file_get_contents() : usage variation *** + +--int 0-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d) +NULL + +--int 1-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d) +NULL + +--int 12345-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d) +NULL + +--int -12345-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d) +NULL + +--float 10.5-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d) +NULL + +--float -10.5-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d) +NULL + +--float 12.3456789000e10-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d) +NULL + +--float -12.3456789000e10-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d) +NULL + +--float .5-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d) +NULL + +--empty array-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d) +NULL + +--uppercase NULL-- +unicode(%d) "contents read" + +--lowercase null-- +unicode(%d) "contents read" + +--lowercase true-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d) +NULL + +--lowercase false-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d) +NULL + +--uppercase TRUE-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d) +NULL + +--uppercase FALSE-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d) +NULL + +--empty string DQ-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - file_get_contents() expects parameter 3 to be resource, object given, %s(%d) +NULL + +--undefined var-- +unicode(%d) "contents read" + +--unset var-- +unicode(%d) "contents read" + +--file resource-- +Error: 2 - file_get_contents(): supplied resource is not a valid Stream-Context resource, %s(%d) +unicode(%d) "contents read" + +--stream context-- +unicode(%d) "contents read" +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/file_get_contents_variation5.phpt b/ext/standard/tests/file/file_get_contents_variation5.phpt new file mode 100644 index 0000000000..4fedb843f3 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation5.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test file_get_contents() function : usage variation +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'FileGetContentsVar5.tmp'; +$absFile = dirname(__FILE__).'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for offset + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( file_get_contents($absFile, false, null, $value) ); +}; + +unlink($absFile); + +?> +===DONE=== +--EXPECTF-- +*** Testing file_get_contents() : usage variation *** + +--int 0-- +unicode(%d) "contents read" + +--int 1-- +unicode(%d) "ontents read" + +--int 12345-- +unicode(%d) "" + +--int -12345-- +unicode(%d) "contents read" + +--float 10.5-- +unicode(3) "ead" + +--float -10.5-- +unicode(%d) "contents read" + +--float 12.3456789000e10-- +unicode(%d) %s + +--float -12.3456789000e10-- +unicode(%d) %s + +--float .5-- +unicode(%d) "contents read" + +--empty array-- +Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +unicode(%d) "contents read" + +--lowercase null-- +unicode(%d) "contents read" + +--lowercase true-- +unicode(12) "ontents read" + +--lowercase false-- +unicode(%d) "contents read" + +--uppercase TRUE-- +unicode(12) "ontents read" + +--uppercase FALSE-- +unicode(%d) "contents read" + +--empty string DQ-- +Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - file_get_contents() expects parameter 4 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - file_get_contents() expects parameter 4 to be long, object given, %s(%d) +NULL + +--undefined var-- +unicode(%d) "contents read" + +--unset var-- +unicode(%d) "contents read" +===DONE=== diff --git a/ext/standard/tests/file/file_get_contents_variation6.phpt b/ext/standard/tests/file/file_get_contents_variation6.phpt new file mode 100644 index 0000000000..624ba52feb --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation6.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test file_get_contents() function : usage variation +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'FileGetContentsVar5.tmp'; +$absFile = dirname(__FILE__).'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for maxlen + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( file_get_contents($absFile, false, null, 0, $value) ); +}; + +unlink($absFile); + +?> +===DONE=== +--EXPECTF-- +*** Testing file_get_contents() : usage variation *** + +--int 0-- +unicode(%d) "" + +--int 1-- +unicode(%d) "c" + +--int 12345-- +unicode(%d) "contents read" + +--int -12345-- +Error: 2 - file_get_contents(): length must be greater than or equal to zero, %s(%d) +bool(false) + +--float 10.5-- +unicode(%d) "contents r" + +--float -10.5-- +Error: 2 - file_get_contents(): length must be greater than or equal to zero, %s(%d) +bool(false) + +--float .5-- +unicode(%d) "" + +--empty array-- +Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +unicode(%d) "" + +--lowercase null-- +unicode(%d) "" + +--lowercase true-- +unicode(%d) "c" + +--lowercase false-- +unicode(%d) "" + +--uppercase TRUE-- +unicode(%d) "c" + +--uppercase FALSE-- +unicode(%d) "" + +--empty string DQ-- +Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - file_get_contents() expects parameter 5 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - file_get_contents() expects parameter 5 to be long, object given, %s(%d) +NULL + +--undefined var-- +unicode(%d) "" + +--unset var-- +unicode(%d) "" +===DONE=== diff --git a/ext/standard/tests/file/file_get_contents_variation7-win32.phpt b/ext/standard/tests/file/file_get_contents_variation7-win32.phpt new file mode 100644 index 0000000000..b8a6a74a24 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation7-win32.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test file_get_contents() function : variation - various absolute and relative paths +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only run on Windows"); +?> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; +$mainDir = "fileGetContentsVar7.dir"; +$subDir = "fileGetContentsVar7Sub"; +$absMainDir = dirname(__FILE__)."\\".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."\\".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); +$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3); + +$allDirs = array( + // absolute paths + "$absSubDir\\", + "$absSubDir\\..\\".$subDir, + "$absSubDir\\\\..\\.\\".$subDir, + "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir, + "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir, + "$absSubDir\\BADDIR", + + // relative paths + $mainDir."\\".$subDir, + $mainDir."\\\\".$subDir, + $mainDir."\\\\\\".$subDir, + ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir, + "BADDIR", + + // unixifed path + $unixifiedDir, +); + +$filename = 'FileGetContentsVar7.tmp'; +$absFile = $absSubDir.'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + var_dump(file_get_contents($dir."\\".$filename)); +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_get_contents() : variation *** + +-- Iteration 1 -- +unicode(%d) "contents read" + +-- Iteration 2 -- +unicode(%d) "contents read" + +-- Iteration 3 -- +unicode(%d) "contents read" + +-- Iteration 4 -- +unicode(%d) "contents read" + +-- Iteration 5 -- + +Warning: file_get_contents(%sfileGetContentsVar7.dir\fileGetContentsVar7Sub\..\\\fileGetContentsVar7Sub\\..\\..\fileGetContentsVar7Sub\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: file_get_contents(%sfileGetContentsVar7.dir\fileGetContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +unicode(%d) "contents read" + +-- Iteration 8 -- +unicode(%d) "contents read" + +-- Iteration 9 -- +unicode(%d) "contents read" + +-- Iteration 10 -- +unicode(%d) "contents read" + +-- Iteration 11 -- + +Warning: file_get_contents(BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 12 -- +unicode(%d) "contents read" + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/file_get_contents_variation7.phpt b/ext/standard/tests/file/file_get_contents_variation7.phpt new file mode 100644 index 0000000000..48bb9139a8 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation7.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test file_get_contents() function : variation - various absolute and relative paths +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; +$mainDir = "fileGetContentsVar7.dir"; +$subDir = "fileGetContentsVar7Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."/".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + +$allDirs = array( + // absolute paths + "$absSubDir/", + "$absSubDir/../".$subDir, + "$absSubDir//.././".$subDir, + "$absSubDir/../../".$mainDir."/./".$subDir, + "$absSubDir/..///".$subDir."//..//../".$subDir, + "$absSubDir/BADDIR", + + // relative paths + $mainDir."/".$subDir, + $mainDir."//".$subDir, + $mainDir."///".$subDir, + "./".$mainDir."/../".$mainDir."/".$subDir, + "BADDIR", + +); + +$filename = 'FileGetContentsVar7.tmp'; +$absFile = $absSubDir.'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + var_dump(file_get_contents($dir."/".$filename)); +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_get_contents() : variation *** + +-- Iteration 1 -- +unicode(%d) "contents read" + +-- Iteration 2 -- +unicode(%d) "contents read" + +-- Iteration 3 -- +unicode(%d) "contents read" + +-- Iteration 4 -- +unicode(%d) "contents read" + +-- Iteration 5 -- + +Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/..///fileGetContentsVar7Sub//..//../fileGetContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +unicode(%d) "contents read" + +-- Iteration 8 -- +unicode(%d) "contents read" + +-- Iteration 9 -- +unicode(%d) "contents read" + +-- Iteration 10 -- +unicode(%d) "contents read" + +-- Iteration 11 -- + +Warning: file_get_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/file_get_contents_variation8-win32.phpt b/ext/standard/tests/file/file_get_contents_variation8-win32.phpt new file mode 100644 index 0000000000..de471d30a2 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation8-win32.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test file_get_contents() function : variation - obscure filenames +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only run on Windows"); +?> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; +/* An array of filenames */ +$names_arr = array( + /* Invalid args */ + -1, + TRUE, + FALSE, + NULL, + "", + " ", + "\0", + array(), + + /* prefix with path separator of a non existing directory*/ + "/no/such/file/dir", + "php/php" + +); + +for( $i=0; $i<count($names_arr); $i++ ) { + echo "-- Iteration $i --\n"; + var_dump(file_get_contents($names_arr[$i])); +} + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_get_contents() : variation *** +-- Iteration 0 -- + +Warning: file_get_contents(-1): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 1 -- + +Warning: file_get_contents(1): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(false) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- + +Warning: file_get_contents( ): failed to open stream: Permission denied in %s on line %d +bool(false) +-- Iteration 6 -- +bool(false) +-- Iteration 7 -- + +Notice: Array to string conversion in %s on line %d + +Warning: file_get_contents(Array): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: file_get_contents(/no/such/file/dir): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: file_get_contents(php/php): failed to open stream: No such file or directory in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/file_get_contents_variation8.phpt b/ext/standard/tests/file/file_get_contents_variation8.phpt new file mode 100644 index 0000000000..103d6db446 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation8.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test file_get_contents() function : variation - obscure filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Do not run on Windows"); +?> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; +/* An array of filenames */ +$names_arr = array( + /* Invalid args */ + -1, + TRUE, + FALSE, + NULL, + "", + " ", + "\0", + array(), + + /* prefix with path separator of a non existing directory*/ + "/no/such/file/dir", + "php/php" + +); + +for( $i=0; $i<count($names_arr); $i++ ) { + echo "-- Iteration $i --\n"; + var_dump(file_get_contents($names_arr[$i])); +} + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_get_contents() : variation *** +-- Iteration 0 -- + +Warning: file_get_contents(-1): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 1 -- + +Warning: file_get_contents(1): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(false) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- + +Warning: file_get_contents( ): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 6 -- +bool(false) +-- Iteration 7 -- + +Notice: Array to string conversion in %s on line %d + +Warning: file_get_contents(Array): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: file_get_contents(/no/such/file/dir): failed to open stream: No such file or directory in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: file_get_contents(php/php): failed to open stream: No such file or directory in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/file_get_contents_variation9.phpt b/ext/standard/tests/file/file_get_contents_variation9.phpt new file mode 100644 index 0000000000..7e500e8c56 --- /dev/null +++ b/ext/standard/tests/file/file_get_contents_variation9.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test file_get_contents() function : variation - linked files +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Do not run on Windows"); +?> +--FILE-- +<?php +/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) + * Description: Read the entire file into a string + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_get_contents() : variation ***\n"; +$filename = dirname(__FILE__).'/fileGetContentsVar9.tmp'; +$softlink = dirname(__FILE__).'/fileGetContentsVar9.SoftLink'; +$hardlink = dirname(__FILE__).'/fileGetContentsVar9.HardLink'; +$chainlink = dirname(__FILE__).'/fileGetContentsVar9.ChainLink'; + +// create file +$h = fopen($filename,"w"); +//Data should be more than the size of a link. +for ($i = 1; $i <= 10; $i++) { + fwrite($h, "Here is a repeated amount of data"); +} +fclose($h); + +// link files +link($filename, $hardlink); +symlink($filename, $softlink); +symlink($softlink, $chainlink); + +// perform tests +var_dump(file_get_contents($chainlink)); +var_dump(file_get_contents($softlink)); +var_dump(file_get_contents($hardlink)); + +unlink($chainlink); +unlink($softlink); +unlink($hardlink); +unlink($filename); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_get_contents() : variation *** +string(330) "Here is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of data" +string(330) "Here is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of data" +string(330) "Here is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of data" + +*** Done *** + diff --git a/ext/standard/tests/file/file_put_contents_variation1.phpt b/ext/standard/tests/file/file_put_contents_variation1.phpt new file mode 100644 index 0000000000..8642a2dc7a --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation1.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test file_put_contents() function : variation - test append flag +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : variation ***\n"; + +$filename = "FilePutContentsVar1.tmp"; + +$data = "The first string to write"; +$extra = ", followed by this"; + +var_dump(file_put_contents($filename, $data)); +var_dump(file_put_contents($filename, $extra, FILE_APPEND)); +echo filesize($filename)."\n"; +readfile($filename); +echo "\n"; +clearstatcache(); +file_put_contents($filename, $data); +echo filesize($filename)."\n"; +readfile($filename); +echo "\n"; +unlink($filename); + + +?> +===DONE=== +--EXPECTF-- +*** Testing file_put_contents() : variation *** +int(25) +int(18) +43 +The first string to write, followed by this +25 +The first string to write +===DONE=== diff --git a/ext/standard/tests/file/file_put_contents_variation2.phpt b/ext/standard/tests/file/file_put_contents_variation2.phpt new file mode 100644 index 0000000000..44ee1f23a4 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation2.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test file_put_contents() function : usage variation - different data types to write +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +$filename = 'fwriteVar5.tmp'; + + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for str + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + file_put_contents($filename, $value); + readfile($filename); +}; +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing file_put_contents() : usage variation *** + +--int 0-- +0 +--int 1-- +1 +--int 12345-- +12345 +--int -12345-- +-2345 +--float 10.5-- +10.5 +--float -10.5-- +-10.5 +--float 12.3456789000e10-- +123456789000 +--float -12.3456789000e10-- +-123456789000 +--float .5-- +0.5 +--empty array-- + +--int indexed array-- +123 +--associative array-- +12 +--nested arrays-- +Error: 8 - Array to string conversion, %s(%d) +Error: 8 - Array to string conversion, %s(%d) +fooArrayArray +--uppercase NULL-- + +--lowercase null-- + +--lowercase true-- +1 +--lowercase false-- + +--uppercase TRUE-- +1 +--uppercase FALSE-- + +--empty string DQ-- + +--empty string SQ-- + +--instance of classWithToString-- +Error: 2 - file_put_contents(): 2nd parameter must be non-object (for now), %s(%d) + +--instance of classWithoutToString-- +Error: 2 - file_put_contents(): 2nd parameter must be non-object (for now), %s(%d) + +--undefined var-- + +--unset var-- +===DONE=== + diff --git a/ext/standard/tests/file/file_put_contents_variation3.phpt b/ext/standard/tests/file/file_put_contents_variation3.phpt new file mode 100644 index 0000000000..0509873bd9 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation3.phpt @@ -0,0 +1,252 @@ +--TEST-- +Test file_put_contents() function : usage variation - different types for context. +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'FilePutContentsVar4.tmp'; +$absFile = dirname(__FILE__).'/'.$filename; + +$fileRes = fopen(__FILE__,'r'); +$strContext = stream_context_create(); + +$data = "data to write"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + //non context resource + 'file resource' => $fileRes, + + //valid stream context + 'stream context' => $strContext, +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( file_put_contents($absFile, $data, null, $value) ); +}; + +unlink($absFile); +fclose($fileRes); + +?> +===DONE=== +--EXPECTF-- +*** Testing file_put_contents() : usage variation *** + +--int 0-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d) +NULL + +--int 1-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d) +NULL + +--int 12345-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d) +NULL + +--int -12345-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d) +NULL + +--float 10.5-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d) +NULL + +--float -10.5-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d) +NULL + +--float 12.3456789000e10-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d) +NULL + +--float -12.3456789000e10-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d) +NULL + +--float .5-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d) +NULL + +--empty array-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d) +NULL + +--uppercase NULL-- +int(13) + +--lowercase null-- +int(13) + +--lowercase true-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d) +NULL + +--lowercase false-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d) +NULL + +--uppercase TRUE-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d) +NULL + +--uppercase FALSE-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d) +NULL + +--empty string DQ-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - file_put_contents() expects parameter 4 to be resource, object given, %s(%d) +NULL + +--undefined var-- +int(13) + +--unset var-- +int(13) + +--file resource-- +Error: 2 - file_put_contents(): supplied resource is not a valid Stream-Context resource, %s(%d) +int(13) + +--stream context-- +int(13) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/file_put_contents_variation4.phpt b/ext/standard/tests/file/file_put_contents_variation4.phpt new file mode 100644 index 0000000000..36da5e715e --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation4.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test file_put_contents() function : variation - include path testing +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : variation ***\n"; + +require_once('fopen_include_path.inc'); + +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "filePutContentsVar4.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = "afile.txt"; +$firstFile = $dir1."/".$filename; + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_path(); +set_include_path($newpath); +runtest(); +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $firstFile, $filename; + file_put_contents($filename, "File in include path", FILE_USE_INCLUDE_PATH); + $line = file_get_contents($firstFile); + echo "$line\n"; + unlink($firstFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing file_put_contents() : variation *** +File in include path +File in include path +===DONE=== diff --git a/ext/standard/tests/file/file_put_contents_variation5.phpt b/ext/standard/tests/file/file_put_contents_variation5.phpt new file mode 100644 index 0000000000..1a0f0f197d --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation5.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test file_put_contents() function : variation - include path testing +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : variation ***\n"; + +require_once('fopen_include_path.inc'); + +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "fileGetContentsVar7.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = "readFileVar7.tmp"; +$scriptLocFile = dirname(__FILE__)."/".$filename; + +$newpath = "rubbish"; +set_include_path($newpath); +runtest(); +$newpath = ""; +set_include_path($newpath); +runtest(); +set_include_path(null); +runtest(); +set_include_path(";; ; ;c:\\rubbish"); +runtest(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $scriptLocFile, $filename; + file_put_contents($filename, "File in script location", FILE_USE_INCLUDE_PATH); + $line = file_get_contents($scriptLocFile); + echo "$line\n"; + unlink($scriptLocFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing file_put_contents() : variation *** +File in script location +File in script location +File in script location +File in script location +===DONE=== + diff --git a/ext/standard/tests/file/file_put_contents_variation6.phpt b/ext/standard/tests/file/file_put_contents_variation6.phpt new file mode 100644 index 0000000000..8e33da5478 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation6.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test file_put_contents() function : variation - include path testing +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : variation ***\n"; + +require_once('fopen_include_path.inc'); + +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "filePutContentsVar6.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = "afile.txt"; +$firstFile = $dir1."/".$filename; + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_path(); +set_include_path($newpath); +runtest(); +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $firstFile, $filename; + file_put_contents($filename, "File in include path", FILE_USE_INCLUDE_PATH); + file_put_contents($filename, ". This was appended", FILE_USE_INCLUDE_PATH | FILE_APPEND); + $line = file_get_contents($firstFile); + echo "$line\n"; + unlink($firstFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing file_put_contents() : variation *** +File in include path. This was appended +File in include path. This was appended +===DONE=== diff --git a/ext/standard/tests/file/file_put_contents_variation7-win32.phpt b/ext/standard/tests/file/file_put_contents_variation7-win32.phpt new file mode 100644 index 0000000000..d7bfdf9233 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation7-win32.phpt @@ -0,0 +1,130 @@ +--TEST-- +Test file_put_contents() function : usage variation - various absolute and relative paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only run on Windows"); +?> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : usage variation ***\n"; + +$mainDir = "filePutContentsVar7.dir"; +$subDir = "filePutContentsVar7Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."\\".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); +$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3); + + +// Note invalid dirs in p8 result in (The system cannot find the path specified.) +// rather than No Such File or Directory in php.net +$allDirs = array( + // absolute paths + "$absSubDir\\", + "$absSubDir\\..\\".$subDir, + "$absSubDir\\\\..\\.\\".$subDir, + "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir, + "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir, + "$absSubDir\\BADDIR", + + // relative paths + $mainDir."\\".$subDir, + $mainDir."\\\\".$subDir, + $mainDir."\\\\\\".$subDir, + ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir, + "BADDIR", + + // unixifed path + $unixifiedDir, +); + +$filename = 'FileGetContentsVar7.tmp'; +$absFile = $absSubDir.'/'.$filename; +$data = "This was the written data"; + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + $res = file_put_contents($dir."\\".$filename, ($data + $i)); + if ($res !== false) { + $in = file_get_contents($absFile); + if ($in == ($data + $i)) { + echo "Data written correctly\n"; + } + else { + echo "Data not written correctly or to correct place\n"; + } + unlink($dir."/".$filename); + } + else { + echo "No data written\n"; + } + +} + +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_put_contents() : usage variation *** + +-- Iteration 1 -- +Data written correctly + +-- Iteration 2 -- +Data written correctly + +-- Iteration 3 -- +Data written correctly + +-- Iteration 4 -- +Data written correctly + +-- Iteration 5 -- + +Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\..\\\filePutContentsVar7Sub\\..\\..\filePutContentsVar7Sub\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d +No data written + +-- Iteration 6 -- + +Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d +No data written + +-- Iteration 7 -- +Data written correctly + +-- Iteration 8 -- +Data written correctly + +-- Iteration 9 -- +Data written correctly + +-- Iteration 10 -- +Data written correctly + +-- Iteration 11 -- + +Warning: file_put_contents(BADDIR\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d +No data written + +-- Iteration 12 -- +Data written correctly + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/file_put_contents_variation7.phpt b/ext/standard/tests/file/file_put_contents_variation7.phpt new file mode 100644 index 0000000000..5c8e5f3602 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation7.phpt @@ -0,0 +1,119 @@ +--TEST-- +Test file_put_contents() function : usage variation - various absolute and relative paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : usage variation ***\n"; + +$mainDir = "filePutContentsVar7.dir"; +$subDir = "filePutContentsVar7Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."/".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + + +// Note invalid dirs in p8 result in (The system cannot find the path specified.) +// rather than No Such File or Directory in php.net +$allDirs = array( + // absolute paths + "$absSubDir/", + "$absSubDir/../".$subDir, + "$absSubDir//.././".$subDir, + "$absSubDir/../../".$mainDir."/./".$subDir, + "$absSubDir/..///".$subDir."//..//../".$subDir, + "$absSubDir/BADDIR", + + // relative paths + $mainDir."/".$subDir, + $mainDir."//".$subDir, + $mainDir."///".$subDir, + "./".$mainDir."/../".$mainDir."/".$subDir, + "BADDIR", + +); + +$filename = 'FileGetContentsVar7.tmp'; +$absFile = $absSubDir.'/'.$filename; +$data = "This was the written data"; + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + $res = file_put_contents($dir."/".$filename, ($data + $i)); + if ($res !== false) { + $in = file_get_contents($absFile); + if ($in == ($data + $i)) { + echo "Data written correctly\n"; + } + else { + echo "Data not written correctly or to correct place\n"; + } + unlink($dir."/".$filename); + } + else { + echo "No data written\n"; + } + +} + +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file_put_contents() : usage variation *** + +-- Iteration 1 -- +Data written correctly + +-- Iteration 2 -- +Data written correctly + +-- Iteration 3 -- +Data written correctly + +-- Iteration 4 -- +Data written correctly + +-- Iteration 5 -- + +Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/..///filePutContentsVar7Sub//..//../filePutContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d +No data written + +-- Iteration 6 -- + +Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d +No data written + +-- Iteration 7 -- +Data written correctly + +-- Iteration 8 -- +Data written correctly + +-- Iteration 9 -- +Data written correctly + +-- Iteration 10 -- +Data written correctly + +-- Iteration 11 -- + +Warning: file_put_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d +No data written + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/file_put_contents_variation8-win32.phpt b/ext/standard/tests/file/file_put_contents_variation8-win32.phpt Binary files differnew file mode 100644 index 0000000000..b762deea85 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation8-win32.phpt diff --git a/ext/standard/tests/file/file_put_contents_variation8.phpt b/ext/standard/tests/file/file_put_contents_variation8.phpt Binary files differnew file mode 100644 index 0000000000..a5b6c273bc --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation8.phpt diff --git a/ext/standard/tests/file/file_put_contents_variation9.phpt b/ext/standard/tests/file/file_put_contents_variation9.phpt new file mode 100644 index 0000000000..433b5369fd --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_variation9.phpt @@ -0,0 +1,73 @@ +--TEST-- +est file_put_contents() function : usage variation - linked files +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Do not run on Windows"); +?> +--FILE-- +<?php +/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) + * Description: Write/Create a file with contents data and return the number of bytes written + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file_put_contents() : usage variation ***\n"; + +$filename = dirname(__FILE__).'/fileGetContentsVar9.tmp'; +$softlink = dirname(__FILE__).'/fileGetContentsVar9.SoftLink'; +$hardlink = dirname(__FILE__).'/fileGetContentsVar9.HardLink'; +$chainlink = dirname(__FILE__).'/fileGetContentsVar9.ChainLink'; + + +// link files even though it original file doesn't exist yet +symlink($filename, $softlink); +symlink($softlink, $chainlink); + + +// perform tests +run_test($chainlink); +run_test($softlink); + +//can only create a hardlink if the file exists. +file_put_contents($filename,""); +link($filename, $hardlink); +run_test($hardlink); + +unlink($chainlink); +unlink($softlink); +unlink($hardlink); +unlink($filename); + + +function run_test($file) { + $data = "Here is some data"; + $extra = ", more data"; + var_dump(file_put_contents($file, $data)); + var_dump(file_put_contents($file, $extra, FILE_APPEND)); + readfile($file); + echo "\n"; +} + + +echo "\n*** Done ***\n"; +?> +--EXPECT-- +*** Testing file_put_contents() : usage variation *** +int(17) +int(11) +Here is some data, more data +int(17) +int(11) +Here is some data, more data +int(17) +int(11) +Here is some data, more data + +*** Done *** + diff --git a/ext/standard/tests/file/file_variation8-win32.phpt b/ext/standard/tests/file/file_variation8-win32.phpt new file mode 100644 index 0000000000..d94bd17a1c --- /dev/null +++ b/ext/standard/tests/file/file_variation8-win32.phpt @@ -0,0 +1,145 @@ +--TEST-- +Test file() function : variation - various absolute and relative paths +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only run on Windows"); +?> +--FILE-- +<?php +/* Prototype : array file(string filename [, int flags[, resource context]]) + * Description: Read entire file into an array + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file() : variation ***\n"; +$mainDir = "fileVar8.dir"; +$subDir = "fileVar8Sub"; +$absMainDir = dirname(__FILE__)."\\".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."\\".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); +$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3); + +$allDirs = array( + // absolute paths + "$absSubDir\\", + "$absSubDir\\..\\".$subDir, + "$absSubDir\\\\..\\.\\".$subDir, + "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir, + "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir, + "$absSubDir\\BADDIR", + + // relative paths + $mainDir."\\".$subDir, + $mainDir."\\\\".$subDir, + $mainDir."\\\\\\".$subDir, + ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir, + "BADDIR", + + // unixifed path + $unixifiedDir, +); + +$filename = 'FileGetContentsVar7.tmp'; +$absFile = $absSubDir.'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + var_dump(file($dir."\\".$filename)); +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file() : variation *** + +-- Iteration 1 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 2 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 3 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 4 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 5 -- + +Warning: file(%s\fileVar8.dir\fileVar8Sub\..\\\fileVar8Sub\\..\\..\fileVar8Sub\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: file(%s\fileVar8.dir\fileVar8Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 8 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 9 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 10 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 11 -- + +Warning: file(BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 12 -- +array(1) { + [0]=> + string(13) "contents read" +} + +*** Done *** + diff --git a/ext/standard/tests/file/file_variation8.phpt b/ext/standard/tests/file/file_variation8.phpt new file mode 100644 index 0000000000..f18ca727ab --- /dev/null +++ b/ext/standard/tests/file/file_variation8.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test file function : variation - various absolute and relative paths +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array file(string filename [, int flags[, resource context]]) + * Description: Read entire file into an array + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file() : variation ***\n"; +$mainDir = "fileVar8.dir"; +$subDir = "fileVar8Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."/".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + +$allDirs = array( + // absolute paths + "$absSubDir/", + "$absSubDir/../".$subDir, + "$absSubDir//.././".$subDir, + "$absSubDir/../../".$mainDir."/./".$subDir, + "$absSubDir/..///".$subDir."//..//../".$subDir, + "$absSubDir/BADDIR", + + // relative paths + $mainDir."/".$subDir, + $mainDir."//".$subDir, + $mainDir."///".$subDir, + "./".$mainDir."/../".$mainDir."/".$subDir, + "BADDIR", + +); + +$filename = 'FileGetContentsVar7.tmp'; +$absFile = $absSubDir.'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, "contents read"); +fclose($h); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + var_dump(file($dir."/".$filename)); +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file() : variation *** + +-- Iteration 1 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 2 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 3 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 4 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 5 -- + +Warning: file(%s/fileVar8.dir/fileVar8Sub/..///fileVar8Sub//..//../fileVar8Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: file(%s/fileVar8.dir/fileVar8Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 8 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 9 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 10 -- +array(1) { + [0]=> + string(13) "contents read" +} + +-- Iteration 11 -- + +Warning: file(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/file_variation9.phpt b/ext/standard/tests/file/file_variation9.phpt new file mode 100644 index 0000000000..5d5c93f7bd --- /dev/null +++ b/ext/standard/tests/file/file_variation9.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test file function : variation - test various endings of a file +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array file(string filename [, int flags[, resource context]]) + * Description: Read entire file into an array + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing file() : variation ***\n"; +$testfile = dirname(__FILE__)."/fileVar9.txt"; + +$contents = array( + "File ends on a single character\na", + "File ends on a new line\n", + "File ends on multiple newlines\n\n\n\n", + "File has\n\nmultiple lines and newlines\n\n", + "File has\r\nmultiple crlfs\n\r\n" + ); + +@unlink($testfile); +foreach ($contents as $content) { + $h = fopen($testfile, "w"); + fwrite($h, $content); + fclose($h); + var_dump(file($testfile)); + unlink($testfile); +} + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing file() : variation *** +array(2) { + [0]=> + string(32) "File ends on a single character +" + [1]=> + string(1) "a" +} +array(1) { + [0]=> + string(24) "File ends on a new line +" +} +array(4) { + [0]=> + string(31) "File ends on multiple newlines +" + [1]=> + string(1) " +" + [2]=> + string(1) " +" + [3]=> + string(1) " +" +} +array(4) { + [0]=> + string(9) "File has +" + [1]=> + string(1) " +" + [2]=> + string(28) "multiple lines and newlines +" + [3]=> + string(1) " +" +} +array(3) { + [0]=> + string(10) "File has +" + [1]=> + string(15) "multiple crlfs +" + [2]=> + string(2) " +" +} + +*** Done *** + diff --git a/ext/standard/tests/file/filegroup_variation1.phpt b/ext/standard/tests/file/filegroup_variation1.phpt new file mode 100644 index 0000000000..ee76477ac8 --- /dev/null +++ b/ext/standard/tests/file/filegroup_variation1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test filegroup() function: usage variations - links +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Do not run on Windows'); +} +--FILE-- +<?php +/* Prototype: int filegroup ( string $filename ) + * Description: Returns the group ID of the file, or FALSE in case of an error. + */ + +/* Creating soft and hard links to a file and applying filegroup() on links */ + +$file_path = dirname(__FILE__); +fclose( fopen($file_path."/filegroup_variation1.tmp", "w") ); + +echo "*** Testing filegroup() with links ***\n"; +/* With symlink */ +symlink($file_path."/filegroup_variation1.tmp", $file_path."/filegroup_variation1_symlink.tmp"); +var_dump( filegroup($file_path."/filegroup_variation1_symlink.tmp") ); //expected true +clearstatcache(); + +/* With hardlink */ +link($file_path."/filegroup_variation1.tmp", $file_path."/filegroup_variation1_link.tmp"); +var_dump( filegroup($file_path."/filegroup_variation1_link.tmp") ); // expected: true +clearstatcache(); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/filegroup_variation1_symlink.tmp"); +unlink($file_path."/filegroup_variation1_link.tmp"); +unlink($file_path."/filegroup_variation1.tmp"); +?> + +--EXPECTF-- +*** Testing filegroup() with links *** +int(%d) +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/filegroup_variation2.phpt b/ext/standard/tests/file/filegroup_variation2.phpt new file mode 100644 index 0000000000..e544f59786 --- /dev/null +++ b/ext/standard/tests/file/filegroup_variation2.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test filegroup() function: usage variations - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: int filegroup ( string $filename ) + * Description: Returns the group ID of the file, or FALSE in case of an error. + */ + +/* Testing filegroup() with invalid arguments -int, float, bool, NULL, resource */ + +$file_path = dirname(__FILE__); +$file_handle = fopen($file_path."/filegroup_variation2.tmp", "w"); + +echo "*** Testing Invalid file types ***\n"; +$filenames = array( + /* Invalid filenames */ + -2.34555, + " ", + "", + TRUE, + FALSE, + NULL, + $file_handle, + + /* scalars */ + 1234, + 0 +); + +/* loop through to test each element the above array */ +foreach( $filenames as $filename ) { + var_dump( filegroup($filename) ); + clearstatcache(); +} +fclose($file_handle); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/filegroup_variation2.tmp"); +?> +--EXPECTF-- +*** Testing Invalid file types *** + +Warning: filegroup(): stat failed for -2.34555 in %s on line %d +bool(false) + +Warning: filegroup(): stat failed for in %s on line %d +bool(false) +bool(false) + +Warning: filegroup(): stat failed for 1 in %s on line %d +bool(false) +bool(false) +bool(false) + +Warning: filegroup() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL + +Warning: filegroup(): stat failed for 1234 in %s on line %d +bool(false) + +Warning: filegroup(): stat failed for 0 in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/filegroup_variation3.phpt b/ext/standard/tests/file/filegroup_variation3.phpt new file mode 100644 index 0000000000..dd875a082b --- /dev/null +++ b/ext/standard/tests/file/filegroup_variation3.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test filegroup() function: usage variations - diff. path notations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: int filegroup ( string $filename ) + * Description: Returns the group ID of the file, or FALSE in case of an error. + */ + +/* Passing file names with different notations, using slashes, wild-card chars */ + +$file_path = dirname(__FILE__); + +echo "*** Testing filegroup() with different notations of file names ***\n"; +$dir_name = $file_path."/filegroup_variation3"; +mkdir($dir_name); +$file_handle = fopen($dir_name."/filegroup_variation3.tmp", "w"); +fclose($file_handle); + +$files_arr = array( + "/filegroup_variation3/filegroup_variation3.tmp", + + /* Testing a file trailing slash */ + "/filegroup_variation3/filegroup_variation3.tmp/", + + /* Testing file with double slashes */ + "/filegroup_variation3//filegroup_variation3.tmp", + "//filegroup_variation3//filegroup_variation3.tmp", + "/filegroup_variation3/*.tmp", + "filegroup_variation3/filegroup*.tmp", + + /* Testing Binary safe */ + "/filegroup_variation3/filegroup_variation3.tmp".chr(0), + "/filegroup_variation3/filegroup_variation3.tmp\0" +); + +$count = 1; +/* loop through to test each element in the above array */ +foreach($files_arr as $file) { + echo "- Iteration $count -\n"; + var_dump( filegroup( $file_path."/".$file ) ); + clearstatcache(); + $count++; +} + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_name = $file_path."/filegroup_variation3"; +unlink($dir_name."/filegroup_variation3.tmp"); +rmdir($dir_name); +?> +--EXPECTF-- +*** Testing filegroup() with different notations of file names *** +- Iteration 1 - +int(%d) +- Iteration 2 - + +Warning: filegroup(): stat failed for %s//filegroup_variation3/filegroup_variation3.tmp/ in %s on line %d +bool(false) +- Iteration 3 - +int(%d) +- Iteration 4 - +int(%d) +- Iteration 5 - + +Warning: filegroup(): stat failed for %s//filegroup_variation3/*.tmp in %s on line %d +bool(false) +- Iteration 6 - + +Warning: filegroup(): stat failed for %s/filegroup_variation3/filegroup*.tmp in %s on line %d +bool(false) +- Iteration 7 - +int(%d) +- Iteration 8 - +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/fileinode_variation1.phpt b/ext/standard/tests/file/fileinode_variation1.phpt new file mode 100644 index 0000000000..d251cc3f85 --- /dev/null +++ b/ext/standard/tests/file/fileinode_variation1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test fileinode() function: usage variations - links +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Do not run on Windows'); +} +--FILE-- +<?php +/* +Prototype: int fileinode ( string $filename ); +Description: Returns the inode number of the file, or FALSE in case of an error. +*/ + +/* Creating soft and hard links to a file and applying fileinode() on links */ + +$file_path = dirname(__FILE__); +fclose( fopen($file_path."/fileinode_variation1.tmp", "w") ); + +echo "*** Testing fileinode() with links ***\n"; +/* With symlink */ +symlink($file_path."/fileinode_variation1.tmp", $file_path."/fileinode_variation1_symlink.tmp"); +var_dump( fileinode($file_path."/fileinode_variation1_symlink.tmp") ); //expected true +clearstatcache(); + +/* With hardlink */ +link($file_path."/fileinode_variation1.tmp", $file_path."/fileinode_variation1_link.tmp"); +var_dump( fileinode($file_path."/fileinode_variation1_link.tmp") ); // expected: true +clearstatcache(); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/fileinode_variation1_symlink.tmp"); +unlink($file_path."/fileinode_variation1_link.tmp"); +unlink($file_path."/fileinode_variation1.tmp"); +?> + +--EXPECTF-- +*** Testing fileinode() with links *** +int(%d) +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/fileinode_variation2.phpt b/ext/standard/tests/file/fileinode_variation2.phpt new file mode 100644 index 0000000000..717133482c --- /dev/null +++ b/ext/standard/tests/file/fileinode_variation2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test fileinode() function: usage variations - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* +Prototype: int fileinode ( string $filename ); +Description: Returns the inode number of the file, or FALSE in case of an error. +*/ + +/* Testing fileinode() with invalid arguments -int, float, bool, NULL, resource */ + +$file_path = dirname(__FILE__); +$file_handle = fopen($file_path."/fileinode_variation2.tmp", "w"); + +echo "*** Testing Invalid file types ***\n"; +$filenames = array( + /* Invalid filenames */ + -2.34555, + " ", + "", + TRUE, + FALSE, + NULL, + $file_handle, + + /* scalars */ + 1234, + 0 +); + +/* loop through to test each element the above array */ +foreach( $filenames as $filename ) { + var_dump( fileinode($filename) ); + clearstatcache(); +} +fclose($file_handle); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/fileinode_variation2.tmp"); +?> +--EXPECTF-- +*** Testing Invalid file types *** + +Warning: fileinode(): stat failed for -2.34555 in %s on line %d +bool(false) + +Warning: fileinode(): stat failed for in %s on line %d +bool(false) +bool(false) + +Warning: fileinode(): stat failed for 1 in %s on line %d +bool(false) +bool(false) +bool(false) + +Warning: fileinode() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL + +Warning: fileinode(): stat failed for 1234 in %s on line %d +bool(false) + +Warning: fileinode(): stat failed for 0 in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/fileinode_variation3.phpt b/ext/standard/tests/file/fileinode_variation3.phpt new file mode 100644 index 0000000000..c81b573246 --- /dev/null +++ b/ext/standard/tests/file/fileinode_variation3.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test fileinode() function: usage variations - diff. path notations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* +Prototype: int fileinode ( string $filename ); +Description: Returns the inode number of the file, or FALSE in case of an error. +*/ + +/* Passing file names with different notations, using slashes, wild-card chars */ + +$file_path = dirname(__FILE__); + +echo "*** Testing fileinode() with different notations of file names ***\n"; +$dir_name = $file_path."/fileinode_variation3"; +mkdir($dir_name); +$file_handle = fopen($dir_name."/fileinode_variation3.tmp", "w"); +fclose($file_handle); + +$files_arr = array( + "/fileinode_variation3/fileinode_variation3.tmp", + + /* Testing a file trailing slash */ + "/fileinode_variation3/fileinode_variation3.tmp/", + + /* Testing file with double slashes */ + "/fileinode_variation3//fileinode_variation3.tmp", + "//fileinode_variation3//fileinode_variation3.tmp", + "/fileinode_variation3/*.tmp", + "fileinode_variation3/fileinode*.tmp", + + /* Testing Binary safe */ + "/fileinode_variation3/fileinode_variation3.tmp".chr(0), + "/fileinode_variation3/fileinode_variation3.tmp\0" +); + +$count = 1; +/* loop through to test each element in the above array */ +foreach($files_arr as $file) { + echo "- Iteration $count -\n"; + var_dump( fileinode( $file_path."/".$file ) ); + clearstatcache(); + $count++; +} + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_name = $file_path."/fileinode_variation3"; +unlink($dir_name."/fileinode_variation3.tmp"); +rmdir($dir_name); +?> +--EXPECTF-- +*** Testing fileinode() with different notations of file names *** +- Iteration 1 - +int(%d) +- Iteration 2 - + +Warning: fileinode(): stat failed for %s//fileinode_variation3/fileinode_variation3.tmp/ in %s on line %d +bool(false) +- Iteration 3 - +int(%d) +- Iteration 4 - +int(%d) +- Iteration 5 - + +Warning: fileinode(): stat failed for %s//fileinode_variation3/*.tmp in %s on line %d +bool(false) +- Iteration 6 - + +Warning: fileinode(): stat failed for %s/fileinode_variation3/fileinode*.tmp in %s on line %d +bool(false) +- Iteration 7 - +int(%d) +- Iteration 8 - +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/fileowner_variation1.phpt b/ext/standard/tests/file/fileowner_variation1.phpt new file mode 100644 index 0000000000..b70ac366d2 --- /dev/null +++ b/ext/standard/tests/file/fileowner_variation1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test fileowner() function: usage variations - links +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Do not run on Windows'); +} +--FILE-- +<?php +/* Prototype: int fileowner ( string $filename ) + * Description: Returns the user ID of the owner of the file, or + * FALSE in case of an error. + */ + +/* Creating soft and hard links to a file and applying fileowner() on links */ + +$file_path = dirname(__FILE__); +fclose( fopen($file_path."/fileowner_variation1.tmp", "w") ); + +echo "*** Testing fileowner() with links ***\n"; +/* With symlink */ +symlink($file_path."/fileowner_variation1.tmp", $file_path."/fileowner_variation1_symlink.tmp"); +var_dump( fileowner($file_path."/fileowner_variation1_symlink.tmp") ); //expected true +clearstatcache(); + +/* With hardlink */ +link($file_path."/fileowner_variation1.tmp", $file_path."/fileowner_variation1_link.tmp"); +var_dump( fileowner($file_path."/fileowner_variation1_link.tmp") ); // expected: true +clearstatcache(); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/fileowner_variation1_symlink.tmp"); +unlink($file_path."/fileowner_variation1_link.tmp"); +unlink($file_path."/fileowner_variation1.tmp"); +?> + +--EXPECTF-- +*** Testing fileowner() with links *** +int(%d) +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/fileowner_variation2.phpt b/ext/standard/tests/file/fileowner_variation2.phpt new file mode 100644 index 0000000000..3fc5f76345 --- /dev/null +++ b/ext/standard/tests/file/fileowner_variation2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test fileowner() function: usage variations - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: int fileowner ( string $filename ) + * Description: Returns the user ID of the owner of the file, or + * FALSE in case of an error. + */ + +/* Testing fileowner() with invalid arguments -int, float, bool, NULL, resource */ + +$file_path = dirname(__FILE__); +$file_handle = fopen($file_path."/fileowner_variation2.tmp", "w"); + +echo "*** Testing Invalid file types ***\n"; +$filenames = array( + /* Invalid filenames */ + -2.34555, + " ", + "", + TRUE, + FALSE, + NULL, + $file_handle, + + /* scalars */ + 1234, + 0 +); + +/* loop through to test each element the above array */ +foreach( $filenames as $filename ) { + var_dump( fileowner($filename) ); + clearstatcache(); +} +fclose($file_handle); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/fileowner_variation2.tmp"); +?> +--EXPECTF-- +*** Testing Invalid file types *** + +Warning: fileowner(): stat failed for -2.34555 in %s on line %d +bool(false) + +Warning: fileowner(): stat failed for in %s on line %d +bool(false) +bool(false) + +Warning: fileowner(): stat failed for 1 in %s on line %d +bool(false) +bool(false) +bool(false) + +Warning: fileowner() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL + +Warning: fileowner(): stat failed for 1234 in %s on line %d +bool(false) + +Warning: fileowner(): stat failed for 0 in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/fileowner_variation3.phpt b/ext/standard/tests/file/fileowner_variation3.phpt new file mode 100644 index 0000000000..2a322b6dbc --- /dev/null +++ b/ext/standard/tests/file/fileowner_variation3.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test fileowner() function: usage variations - diff. path notations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: int fileowner ( string $filename ) + * Description: Returns the user ID of the owner of the file, or + * FALSE in case of an error. + */ + +/* Passing file names with different notations, using slashes, wild-card chars */ + +$file_path = dirname(__FILE__); + +echo "*** Testing fileowner() with different notations of file names ***\n"; +$dir_name = $file_path."/fileowner_variation3"; +mkdir($dir_name); +$file_handle = fopen($dir_name."/fileowner_variation3.tmp", "w"); +fclose($file_handle); + +$files_arr = array( + "/fileowner_variation3/fileowner_variation3.tmp", + + /* Testing a file trailing slash */ + "/fileowner_variation3/fileowner_variation3.tmp/", + + /* Testing file with double slashes */ + "/fileowner_variation3//fileowner_variation3.tmp", + "//fileowner_variation3//fileowner_variation3.tmp", + "/fileowner_variation3/*.tmp", + "fileowner_variation3/fileowner*.tmp", + + /* Testing Binary safe */ + "/fileowner_variation3/fileowner_variation3.tmp".chr(0), + "/fileowner_variation3/fileowner_variation3.tmp\0" +); + +$count = 1; +/* loop through to test each element in the above array */ +foreach($files_arr as $file) { + echo "- Iteration $count -\n"; + var_dump( fileowner( $file_path."/".$file ) ); + clearstatcache(); + $count++; +} + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_name = $file_path."/fileowner_variation3"; +unlink($dir_name."/fileowner_variation3.tmp"); +rmdir($dir_name); +?> +--EXPECTF-- +*** Testing fileowner() with different notations of file names *** +- Iteration 1 - +int(%d) +- Iteration 2 - + +Warning: fileowner(): stat failed for %s//fileowner_variation3/fileowner_variation3.tmp/ in %s on line %d +bool(false) +- Iteration 3 - +int(%d) +- Iteration 4 - +int(%d) +- Iteration 5 - + +Warning: fileowner(): stat failed for %s//fileowner_variation3/*.tmp in %s on line %d +bool(false) +- Iteration 6 - + +Warning: fileowner(): stat failed for %s/fileowner_variation3/fileowner*.tmp in %s on line %d +bool(false) +- Iteration 7 - +int(%d) +- Iteration 8 - +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/fileperms_variation1.phpt b/ext/standard/tests/file/fileperms_variation1.phpt new file mode 100644 index 0000000000..e90cf8784f --- /dev/null +++ b/ext/standard/tests/file/fileperms_variation1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test fileperms() function: usage variations - links +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Do not run on Windows'); +} +--FILE-- +<?php +/* Prototype: int fileperms ( string $filename ) + * Description: Returns the group ID of the file, or FALSE in case of an error. + */ + +/* Creating soft and hard links to a file and applying fileperms() on links */ + +$file_path = dirname(__FILE__); +fclose( fopen($file_path."/fileperms_variation1.tmp", "w") ); + +echo "*** Testing fileperms() with links ***\n"; +/* With symlink */ +symlink($file_path."/fileperms_variation1.tmp", $file_path."/fileperms_variation1_symlink.tmp"); +var_dump( fileperms($file_path."/fileperms_variation1_symlink.tmp") ); //expected true +clearstatcache(); + +/* With hardlink */ +link($file_path."/fileperms_variation1.tmp", $file_path."/fileperms_variation1_link.tmp"); +var_dump( fileperms($file_path."/fileperms_variation1_link.tmp") ); // expected: true +clearstatcache(); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/fileperms_variation1_symlink.tmp"); +unlink($file_path."/fileperms_variation1_link.tmp"); +unlink($file_path."/fileperms_variation1.tmp"); +?> + +--EXPECTF-- +*** Testing fileperms() with links *** +int(%d) +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/fileperms_variation2.phpt b/ext/standard/tests/file/fileperms_variation2.phpt new file mode 100644 index 0000000000..8fd10cabe8 --- /dev/null +++ b/ext/standard/tests/file/fileperms_variation2.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test fileperms() function: usage variations - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: int fileperms ( string $filename ) + * Description: Returns the group ID of the file, or FALSE in case of an error. + */ + +/* Testing fileperms() with invalid arguments -int, float, bool, NULL, resource */ + +$file_path = dirname(__FILE__); +$file_handle = fopen($file_path."/fileperms_variation2.tmp", "w"); + +echo "*** Testing Invalid file types ***\n"; +$filenames = array( + /* Invalid filenames */ + -2.34555, + " ", + "", + TRUE, + FALSE, + NULL, + $file_handle, + + /* scalars */ + 1234, + 0 +); + +/* loop through to test each element the above array */ +foreach( $filenames as $filename ) { + var_dump( fileperms($filename) ); + clearstatcache(); +} +fclose($file_handle); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/fileperms_variation2.tmp"); +?> +--EXPECTF-- +*** Testing Invalid file types *** + +Warning: fileperms(): stat failed for -2.34555 in %s on line %d +bool(false) + +Warning: fileperms(): stat failed for in %s on line %d +bool(false) +bool(false) + +Warning: fileperms(): stat failed for 1 in %s on line %d +bool(false) +bool(false) +bool(false) + +Warning: fileperms() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d +NULL + +Warning: fileperms(): stat failed for 1234 in %s on line %d +bool(false) + +Warning: fileperms(): stat failed for 0 in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/fileperms_variation3.phpt b/ext/standard/tests/file/fileperms_variation3.phpt new file mode 100644 index 0000000000..38101e363c --- /dev/null +++ b/ext/standard/tests/file/fileperms_variation3.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test fileperms() function: usage variations - diff. path notations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: int fileperms ( string $filename ) + * Description: Returns the group ID of the file, or FALSE in case of an error. + */ + +/* Passing file names with different notations, using slashes, wild-card chars */ + +$file_path = dirname(__FILE__); + +echo "*** Testing fileperms() with different notations of file names ***\n"; +$dir_name = $file_path."/fileperms_variation3"; +mkdir($dir_name); +$file_handle = fopen($dir_name."/fileperms_variation3.tmp", "w"); +fclose($file_handle); + +$files_arr = array( + "/fileperms_variation3/fileperms_variation3.tmp", + + /* Testing a file trailing slash */ + "/fileperms_variation3/fileperms_variation3.tmp/", + + /* Testing file with double slashes */ + "/fileperms_variation3//fileperms_variation3.tmp", + "//fileperms_variation3//fileperms_variation3.tmp", + "/fileperms_variation3/*.tmp", + "fileperms_variation3/fileperms*.tmp", + + /* Testing Binary safe */ + "/fileperms_variation3/fileperms_variation3.tmp".chr(0), + "/fileperms_variation3/fileperms_variation3.tmp\0" +); + +$count = 1; +/* loop through to test each element in the above array */ +foreach($files_arr as $file) { + echo "- Iteration $count -\n"; + var_dump( fileperms( $file_path."/".$file ) ); + clearstatcache(); + $count++; +} + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_name = $file_path."/fileperms_variation3"; +unlink($dir_name."/fileperms_variation3.tmp"); +rmdir($dir_name); +?> +--EXPECTF-- +*** Testing fileperms() with different notations of file names *** +- Iteration 1 - +int(%d) +- Iteration 2 - + +Warning: fileperms(): stat failed for %s//fileperms_variation3/fileperms_variation3.tmp/ in %s on line %d +bool(false) +- Iteration 3 - +int(%d) +- Iteration 4 - +int(%d) +- Iteration 5 - + +Warning: fileperms(): stat failed for %s//fileperms_variation3/*.tmp in %s on line %d +bool(false) +- Iteration 6 - + +Warning: fileperms(): stat failed for %s/fileperms_variation3/fileperms*.tmp in %s on line %d +bool(false) +- Iteration 7 - +int(%d) +- Iteration 8 - +int(%d) + +*** Done *** diff --git a/ext/standard/tests/file/filesize_variation1.phpt b/ext/standard/tests/file/filesize_variation1.phpt index 7e27353605..0a490cd7e6 100644 --- a/ext/standard/tests/file/filesize_variation1.phpt +++ b/ext/standard/tests/file/filesize_variation1.phpt @@ -3,7 +3,7 @@ Test filesize() function: usage variations - size of files --SKIPIF-- <?php if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip only valid for Linux'); + die('skip Not valid on Windows'); } --FILE-- <?php @@ -29,17 +29,17 @@ for($size = 1; $size <10000; $size = $size+1000) echo "Done\n"; ---EXPECT-- +--EXPECTF-- *** Testing filesize(): usage variations *** *** Checking filesize() with different size of files *** -int(1024) -int(1025024) -int(2049024) -int(3073024) -int(4097024) -int(5121024) -int(6145024) -int(7169024) -int(8193024) -int(9217024) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) Done diff --git a/ext/standard/tests/file/filesize_variation5.phpt b/ext/standard/tests/file/filesize_variation5.phpt new file mode 100644 index 0000000000..638f8ba8ed --- /dev/null +++ b/ext/standard/tests/file/filesize_variation5.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test filesize() function: usage variations - size of files +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* + * Prototype : int filesize ( string $filename ); + * Description : Returns the size of the file in bytes, or FALSE + * (and generates an error of level E_WARNING) in case of an error. + */ + +echo "*** Testing filesize(): usage variations ***\n"; + +/* null, false, "", " " */ +var_dump( filesize(NULL) ); +var_dump( filesize(false) ); +var_dump( filesize('') ); +var_dump( filesize(' ') ); +var_dump( filesize('|') ); +echo "*** Done ***\n"; +?> +--EXPECTF-- +*** Testing filesize(): usage variations *** +bool(false) +bool(false) +bool(false) + +Warning: filesize(): stat failed for in %s on line %d +bool(false) + +Warning: filesize(): stat failed for | in %s on line %d +bool(false) +*** Done *** diff --git a/ext/standard/tests/file/filetype_variation2.phpt b/ext/standard/tests/file/filetype_variation2.phpt new file mode 100644 index 0000000000..95885757cd --- /dev/null +++ b/ext/standard/tests/file/filetype_variation2.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test filetype() function: Variations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no /dev on Windows'); +} +?> +--FILE-- +<?php +/* +Prototype: string filetype ( string $filename ); +Description: Returns the type of the file. Possible values are fifo, char, + dir, block, link, file, and unknown. +*/ + +echo "*** Testing filetype() with various types ***\n"; +echo "-- Checking for char --\n"; +print( filetype("/dev/console") )."\n"; + +echo "-- Checking for block --\n"; +//we have cheated in our mac build by creating a ram0 block device. +print( filetype("/dev/ram0") )."\n"; + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing filetype() with various types *** +-- Checking for char -- +char +-- Checking for block -- +block + +*** Done *** diff --git a/ext/standard/tests/file/flock_error.phpt b/ext/standard/tests/file/flock_error.phpt index 4b968e52ca..a33dafa29e 100644 --- a/ext/standard/tests/file/flock_error.phpt +++ b/ext/standard/tests/file/flock_error.phpt @@ -55,7 +55,7 @@ echo "\n*** Done ***\n"; $file = dirname(__FILE__)."/flock.tmp"; unlink($file); ?> ---EXPECTF-- +--EXPECTF-- *** Testing error conditions *** --- Iteration 0 --- @@ -91,8 +91,10 @@ Warning: flock() expects parameter 2 to be long, Unicode string given in %s on l NULL --- Iteration 8 --- -Warning: flock() expects parameter 2 to be long, string given in %s on line %d -NULL +Notice: A non well formed numeric value encountered in %s on line %d + +Warning: flock(): Illegal operation argument in %s on line %d +bool(false) Warning: flock(): 6 is not a valid stream resource in %s on line %d bool(false) @@ -110,3 +112,4 @@ Warning: flock() expects at most 3 parameters, 4 given in %s on line %d NULL *** Done *** + diff --git a/ext/standard/tests/file/flock_variation.phpt b/ext/standard/tests/file/flock_variation.phpt index c76f1d769a..339f10cb9f 100644 --- a/ext/standard/tests/file/flock_variation.phpt +++ b/ext/standard/tests/file/flock_variation.phpt @@ -1,371 +1,45 @@ --TEST-- -Test flock() function: Variations +Test flock() function: usage variations --FILE-- <?php /* Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]); -Description: PHP supports a portable way of locking complete files - in an advisory way +Description: PHP supports a portable way of locking complete files in an advisory way */ -echo "*** Testing flock() fun with the various operation and - wouldblock values ***\n"; -$file = dirname(__FILE__)."/flock.tmp"; -$fp = fopen($file, "w"); +echo "*** Test flock() function: with the operations given as numeric values ***\n"; -/* array of operatons */ -$operations = array( - LOCK_SH, - LOCK_EX, - LOCK_SH|LOCK_NB, - LOCK_EX|LOCK_NB, - LOCK_SH|LOCK_EX, - LOCK_UN, - 1, - 2, - 2.234, - TRUE -); +$filename = dirname(__FILE__)."/flock_variation.tmp"; +$file_handle = fopen($filename, "w"); -/* array of wouldblocks */ -$wouldblocks = array( - 0, - 1, - 2, - 1.234, - TRUE, - FALSE, - NULL, - array(1,2,3), - array(), - "string", - "", - /* binary input */ - b"string", - b"", - "\0" +/* array of operations */ +$operations = array( + 1, //nothing but LOCK_SH + 2, //nothing but LOCK_EX + 2.234, //nothing but LOCK_EX + TRUE //nothing but LOCK_SH ); $i = 0; foreach($operations as $operation) { - echo "--- Outer iteration $i ---\n"; - var_dump(flock($fp, $operation)); - $j = 0; - foreach($wouldblocks as $wouldblock) { - echo "-- Inner iteration $j in $i --\n"; - var_dump(flock($fp, $operation, $wouldblock)); - $j++; - } + var_dump(flock($file_handle, $operation)); + var_dump(flock($file_handle, 3)); //nothing but LOCK_UN $i++; } -fclose($fp); -@unlink($file); +fclose($file_handle); +unlink($filename); -echo "\n*** Done ***\n"; +echo "*** Done ***\n"; ?> ---EXPECT-- -*** Testing flock() fun with the various operation and - wouldblock values *** ---- Outer iteration 0 --- -bool(true) --- Inner iteration 0 in 0 -- -bool(true) --- Inner iteration 1 in 0 -- -bool(true) --- Inner iteration 2 in 0 -- -bool(true) --- Inner iteration 3 in 0 -- -bool(true) --- Inner iteration 4 in 0 -- -bool(true) --- Inner iteration 5 in 0 -- -bool(true) --- Inner iteration 6 in 0 -- -bool(true) --- Inner iteration 7 in 0 -- -bool(true) --- Inner iteration 8 in 0 -- -bool(true) --- Inner iteration 9 in 0 -- -bool(true) --- Inner iteration 10 in 0 -- -bool(true) --- Inner iteration 11 in 0 -- -bool(true) --- Inner iteration 12 in 0 -- -bool(true) --- Inner iteration 13 in 0 -- -bool(true) ---- Outer iteration 1 --- -bool(true) --- Inner iteration 0 in 1 -- -bool(true) --- Inner iteration 1 in 1 -- -bool(true) --- Inner iteration 2 in 1 -- -bool(true) --- Inner iteration 3 in 1 -- -bool(true) --- Inner iteration 4 in 1 -- -bool(true) --- Inner iteration 5 in 1 -- -bool(true) --- Inner iteration 6 in 1 -- -bool(true) --- Inner iteration 7 in 1 -- -bool(true) --- Inner iteration 8 in 1 -- -bool(true) --- Inner iteration 9 in 1 -- -bool(true) --- Inner iteration 10 in 1 -- -bool(true) --- Inner iteration 11 in 1 -- -bool(true) --- Inner iteration 12 in 1 -- -bool(true) --- Inner iteration 13 in 1 -- -bool(true) ---- Outer iteration 2 --- -bool(true) --- Inner iteration 0 in 2 -- -bool(true) --- Inner iteration 1 in 2 -- -bool(true) --- Inner iteration 2 in 2 -- -bool(true) --- Inner iteration 3 in 2 -- -bool(true) --- Inner iteration 4 in 2 -- -bool(true) --- Inner iteration 5 in 2 -- -bool(true) --- Inner iteration 6 in 2 -- -bool(true) --- Inner iteration 7 in 2 -- -bool(true) --- Inner iteration 8 in 2 -- -bool(true) --- Inner iteration 9 in 2 -- -bool(true) --- Inner iteration 10 in 2 -- -bool(true) --- Inner iteration 11 in 2 -- -bool(true) --- Inner iteration 12 in 2 -- -bool(true) --- Inner iteration 13 in 2 -- -bool(true) ---- Outer iteration 3 --- -bool(true) --- Inner iteration 0 in 3 -- -bool(true) --- Inner iteration 1 in 3 -- -bool(true) --- Inner iteration 2 in 3 -- -bool(true) --- Inner iteration 3 in 3 -- -bool(true) --- Inner iteration 4 in 3 -- -bool(true) --- Inner iteration 5 in 3 -- -bool(true) --- Inner iteration 6 in 3 -- -bool(true) --- Inner iteration 7 in 3 -- -bool(true) --- Inner iteration 8 in 3 -- -bool(true) --- Inner iteration 9 in 3 -- -bool(true) --- Inner iteration 10 in 3 -- -bool(true) --- Inner iteration 11 in 3 -- -bool(true) --- Inner iteration 12 in 3 -- -bool(true) --- Inner iteration 13 in 3 -- -bool(true) ---- Outer iteration 4 --- -bool(true) --- Inner iteration 0 in 4 -- -bool(true) --- Inner iteration 1 in 4 -- -bool(true) --- Inner iteration 2 in 4 -- -bool(true) --- Inner iteration 3 in 4 -- -bool(true) --- Inner iteration 4 in 4 -- -bool(true) --- Inner iteration 5 in 4 -- -bool(true) --- Inner iteration 6 in 4 -- -bool(true) --- Inner iteration 7 in 4 -- -bool(true) --- Inner iteration 8 in 4 -- -bool(true) --- Inner iteration 9 in 4 -- +--EXPECTF-- +*** Test flock() function: with the operations given as numeric values *** bool(true) --- Inner iteration 10 in 4 -- bool(true) --- Inner iteration 11 in 4 -- bool(true) --- Inner iteration 12 in 4 -- bool(true) --- Inner iteration 13 in 4 -- bool(true) ---- Outer iteration 5 --- bool(true) --- Inner iteration 0 in 5 -- bool(true) --- Inner iteration 1 in 5 -- bool(true) --- Inner iteration 2 in 5 -- -bool(true) --- Inner iteration 3 in 5 -- -bool(true) --- Inner iteration 4 in 5 -- -bool(true) --- Inner iteration 5 in 5 -- -bool(true) --- Inner iteration 6 in 5 -- -bool(true) --- Inner iteration 7 in 5 -- -bool(true) --- Inner iteration 8 in 5 -- -bool(true) --- Inner iteration 9 in 5 -- -bool(true) --- Inner iteration 10 in 5 -- -bool(true) --- Inner iteration 11 in 5 -- -bool(true) --- Inner iteration 12 in 5 -- -bool(true) --- Inner iteration 13 in 5 -- -bool(true) ---- Outer iteration 6 --- -bool(true) --- Inner iteration 0 in 6 -- -bool(true) --- Inner iteration 1 in 6 -- -bool(true) --- Inner iteration 2 in 6 -- -bool(true) --- Inner iteration 3 in 6 -- -bool(true) --- Inner iteration 4 in 6 -- -bool(true) --- Inner iteration 5 in 6 -- -bool(true) --- Inner iteration 6 in 6 -- -bool(true) --- Inner iteration 7 in 6 -- -bool(true) --- Inner iteration 8 in 6 -- -bool(true) --- Inner iteration 9 in 6 -- -bool(true) --- Inner iteration 10 in 6 -- -bool(true) --- Inner iteration 11 in 6 -- -bool(true) --- Inner iteration 12 in 6 -- -bool(true) --- Inner iteration 13 in 6 -- -bool(true) ---- Outer iteration 7 --- -bool(true) --- Inner iteration 0 in 7 -- -bool(true) --- Inner iteration 1 in 7 -- -bool(true) --- Inner iteration 2 in 7 -- -bool(true) --- Inner iteration 3 in 7 -- -bool(true) --- Inner iteration 4 in 7 -- -bool(true) --- Inner iteration 5 in 7 -- -bool(true) --- Inner iteration 6 in 7 -- -bool(true) --- Inner iteration 7 in 7 -- -bool(true) --- Inner iteration 8 in 7 -- -bool(true) --- Inner iteration 9 in 7 -- -bool(true) --- Inner iteration 10 in 7 -- -bool(true) --- Inner iteration 11 in 7 -- -bool(true) --- Inner iteration 12 in 7 -- -bool(true) --- Inner iteration 13 in 7 -- -bool(true) ---- Outer iteration 8 --- -bool(true) --- Inner iteration 0 in 8 -- -bool(true) --- Inner iteration 1 in 8 -- -bool(true) --- Inner iteration 2 in 8 -- -bool(true) --- Inner iteration 3 in 8 -- -bool(true) --- Inner iteration 4 in 8 -- -bool(true) --- Inner iteration 5 in 8 -- -bool(true) --- Inner iteration 6 in 8 -- -bool(true) --- Inner iteration 7 in 8 -- -bool(true) --- Inner iteration 8 in 8 -- -bool(true) --- Inner iteration 9 in 8 -- -bool(true) --- Inner iteration 10 in 8 -- -bool(true) --- Inner iteration 11 in 8 -- -bool(true) --- Inner iteration 12 in 8 -- -bool(true) --- Inner iteration 13 in 8 -- -bool(true) ---- Outer iteration 9 --- -bool(true) --- Inner iteration 0 in 9 -- -bool(true) --- Inner iteration 1 in 9 -- -bool(true) --- Inner iteration 2 in 9 -- -bool(true) --- Inner iteration 3 in 9 -- -bool(true) --- Inner iteration 4 in 9 -- -bool(true) --- Inner iteration 5 in 9 -- -bool(true) --- Inner iteration 6 in 9 -- -bool(true) --- Inner iteration 7 in 9 -- -bool(true) --- Inner iteration 8 in 9 -- -bool(true) --- Inner iteration 9 in 9 -- -bool(true) --- Inner iteration 10 in 9 -- -bool(true) --- Inner iteration 11 in 9 -- -bool(true) --- Inner iteration 12 in 9 -- -bool(true) --- Inner iteration 13 in 9 -- -bool(true) - *** Done *** diff --git a/ext/standard/tests/file/flock_variation1.phpt b/ext/standard/tests/file/flock_variation1.phpt new file mode 100644 index 0000000000..3e3f5108e8 --- /dev/null +++ b/ext/standard/tests/file/flock_variation1.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test flock() function: usage variations +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. not for Windows'); +} +if (function_exists("pcntl_fork") == FALSE) { + die('skip.. no pcntl_fork()'); +} +?> +--FILE-- +<?php +/* +Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]); +Description: PHP supports a portable way of locking complete files in an advisory way +*/ + +echo "*** Test flock() function: with the operations given as numeric values ***\n"; + +$filename = dirname(__FILE__)."/flock_variation1.tmp"; +$file_handle = fopen($filename, "w"); +fwrite($file_handle, str_repeat("Hello2World", 10) ); +fclose($file_handle); + +$file_read = fopen($filename, "r"); + +$pid = pcntl_fork(); +echo "-- child process is created --\n"; +if ($pid == -1) { + die('could not fork'); +} else if ($pid) { + echo "-- Trying to get the Reader Lock --\n"; + if( flock($file_read, LOCK_EX) ) { + echo "-- Got Lock --\n"; + sleep(5); + flock($file_read, LOCK_UN); + } + else + echo "-- Couldn't get the Lock --\n"; +} else { + echo "-- Trying to get the Writer Lock --\n"; + if( flock($file_read, LOCK_EX) ) { + echo "-- Got Lock --\n"; + flock($file_read, LOCK_UN); + } + else + echo "-- Couldn't get the Lock --\n"; + +} + +echo "*** Done ***\n"; +?> +--CLEAN-- +<?php +fclose($file_read); +fclose($file_write); +unlink($filename); +?> +--EXPECTF-- diff --git a/ext/standard/tests/file/fopen_include_path.inc b/ext/standard/tests/file/fopen_include_path.inc new file mode 100644 index 0000000000..7d6723a815 --- /dev/null +++ b/ext/standard/tests/file/fopen_include_path.inc @@ -0,0 +1,92 @@ +<?php +$pwd = getcwd(); +$f = basename(__FILE__); +$dir1 = $pwd."/".$f.".dir1"; +$dir2 = $pwd."/".$f.".dir2"; +$dir3 = $pwd."/".$f.".dir3"; +//invalid directory +$dir4 = $pwd."/".$f.".dir4"; +$newdirs = array($dir1, $dir2, $dir3); + +$reldirs = array("dir1", "dir2", "dir3"); + +function generate_next_rel_path() { + global $reldirs; + //create the include directory structure + $pathSep = ":"; + $newIncludePath = ""; + if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; + } + foreach($reldirs as $newdir) { + $newIncludePath .= $newdir.$pathSep; + } + return "dir4".$pathSep . $newIncludePath; +} + +function generate_next_path() { + global $newdirs, $dir4; + //create the include directory structure + $pathSep = ":"; + $newIncludePath = ""; + if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; + } + foreach($newdirs as $newdir) { + $newIncludePath .= $newdir.$pathSep; + } + return $dir4.$pathSep . $newIncludePath; +} + + +function create_include_path() { + + global $newdirs; + //create the include directory structure + $pathSep = ":"; + $newIncludePath = ""; + if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; + } + foreach($newdirs as $newdir) { + mkdir($newdir); + $newIncludePath .= $newdir.$pathSep; + } + return $newIncludePath; +} + +function relative_include_path() { + + global $reldirs; + //create the include directory structure + $pathSep = ":"; + $newIncludePath = ""; + if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; + } + foreach($reldirs as $newdir) { + mkdir($newdir); + $newIncludePath .= $newdir.$pathSep; + } + return $newIncludePath; +} + + +function teardown_include_path() { + + global $newdirs; + // remove the directory structure + foreach($newdirs as $newdir) { + rmdir($newdir); + } +} + +function teardown_relative_path() { + + global $reldirs; + // remove the directory structure + foreach($reldirs as $newdir) { + rmdir($newdir); + } +} +?>
\ No newline at end of file diff --git a/ext/standard/tests/file/fopen_variation10-win32.phpt b/ext/standard/tests/file/fopen_variation10-win32.phpt new file mode 100644 index 0000000000..0c0d25b6db --- /dev/null +++ b/ext/standard/tests/file/fopen_variation10-win32.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test fopen() function : variation: interesting paths, no use include path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Run only on Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; + +// fopen with interesting windows paths. +$testdir = dirname(__FILE__).'/fopen10.tmpDir'; +$rootdir = 'fopen10.tmpdirTwo'; +mkdir($testdir); +mkdir('c:\\'.$rootdir); + +$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3); + +$paths = array('c:\\', + 'c:', + 'c', + '\\', + '/', + 'c:'.$rootdir, + 'c:adir', + 'c:\\/', + 'c:\\'.$rootdir.'\\/', + 'c:\\'.$rootdir.'\\', + 'c:\\'.$rootdir.'/', + $unixifiedDir, + '/sortout'); + +$file = "fopen_variation10.tmp"; +$firstfile = 'c:\\'.$rootdir.'\\'.$file; +$secondfile = $testdir.'\\'.$file; +$thirdfile = 'c:\\'.$file; + +$h = fopen($firstfile, 'w'); +fwrite($h, "file in $rootdir"); +fclose($h); + +$h = fopen($secondfile, 'w'); +fwrite($h, "file in fopen10.tmpDir"); +fclose($h); + +$h = fopen($thirdfile, 'w'); +fwrite($h, "file in root"); +fclose($h); + +foreach($paths as $path) { + echo "\n--$path--\n"; + $toFind = $path.'\\'.$file; + $h = fopen($toFind, 'r'); + if ($h === false) { + echo "file not opened for read\n"; + } + else { + fpassthru($h); + echo "\n"; + } + fclose($h); +}; + +unlink($firstfile); +unlink($secondfile); +unlink($thirdfile); +rmdir($testdir); +rmdir('c:\\'.$rootdir); + + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** + +--c:\-- +file in root + +--c:-- +file in root + +--c-- + +Warning: fopen(c\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--\-- + +Warning: fopen(\\fopen_variation10.tmp): failed to open stream: Invalid argument in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--/-- + +Warning: fopen(/\fopen_variation10.tmp): failed to open stream: Invalid argument in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--c:fopen10.tmpdirTwo-- + +Warning: fopen(c:fopen10.tmpdirTwo\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--c:adir-- + +Warning: fopen(c:adir\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--c:\/-- +file in root + +--c:\fopen10.tmpdirTwo\/-- +file in fopen10.tmpdirTwo + +--c:\fopen10.tmpdirTwo\-- +file in fopen10.tmpdirTwo + +--c:\fopen10.tmpdirTwo/-- +file in fopen10.tmpdirTwo + +--%s/fopen10.tmpDir-- +file in fopen10.tmpDir + +--/sortout-- + +Warning: fopen(/sortout\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d +===DONE=== + diff --git a/ext/standard/tests/file/fopen_variation11-win32.phpt b/ext/standard/tests/file/fopen_variation11-win32.phpt new file mode 100644 index 0000000000..f50adb8cc5 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation11-win32.phpt @@ -0,0 +1,149 @@ +--TEST-- +Test fopen() function : variation: interesting paths, use include path = true +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Run only on Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; + +// fopen with interesting windows paths. +$testdir = dirname(__FILE__).'/fopen11.tmpDir'; +$rootdir = 'fopen11.tmpdirTwo'; +mkdir($testdir); +mkdir('c:\\'.$rootdir); + +$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3); + +$paths = array('c:\\', + 'c:', + 'c', + '\\', + '/', + 'c:'.$rootdir, + 'c:adir', + 'c:\\/', + 'c:\\'.$rootdir.'\\/', + 'c:\\'.$rootdir.'\\', + 'c:\\'.$rootdir.'/', + $unixifiedDir, + '/sortout'); + +$file = "fopen_variation11.tmp"; +$firstfile = 'c:\\'.$rootdir.'\\'.$file; +$secondfile = $testdir.'\\'.$file; +$thirdfile = 'c:\\'.$file; + +$h = fopen($firstfile, 'w'); +fwrite($h, "file in $rootdir"); +fclose($h); + +$h = fopen($secondfile, 'w'); +fwrite($h, "file in fopen11.tmpDir"); +fclose($h); + +$h = fopen($thirdfile, 'w'); +fwrite($h, "file in root"); +fclose($h); + +foreach($paths as $path) { + echo "\n--$path--\n"; + $toFind = $path.'\\'.$file; + $h = fopen($toFind, 'r', true); + if ($h === false) { + echo "file not opened for read\n"; + } + else { + fpassthru($h); + echo "\n"; + } + fclose($h); +}; + +unlink($firstfile); +unlink($secondfile); +unlink($thirdfile); +rmdir($testdir); +rmdir('c:\\'.$rootdir); + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** + +--c:\-- +file in root + +--c:-- +file in root + +--c-- + +Warning: fopen(c\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--\-- + +Warning: fopen(\\FOPEN_VARIATION11.TMP): failed to open stream: Invalid argument in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--/-- + +Warning: fopen(\\FOPEN_VARIATION11.TMP): failed to open stream: Invalid argument in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--c:fopen11.tmpdirTwo-- + +Warning: fopen(c:fopen11.tmpdirTwo\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--c:adir-- + +Warning: fopen(c:adir\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d + +--c:\/-- +file in root + +--c:\fopen11.tmpdirTwo\/-- +file in fopen11.tmpdirTwo + +--c:\fopen11.tmpdirTwo\-- +file in fopen11.tmpdirTwo + +--c:\fopen11.tmpdirTwo/-- +file in fopen11.tmpdirTwo + +--%s/fopen11.tmpDir-- +file in fopen11.tmpDir + +--/sortout-- + +Warning: fopen(/sortout\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d +file not opened for read + +Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d +===DONE=== + diff --git a/ext/standard/tests/file/fopen_variation12.phpt b/ext/standard/tests/file/fopen_variation12.phpt new file mode 100644 index 0000000000..54a1fa93e9 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation12.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test fopen() function : variation: use include path (path is bad) create a file (relative) +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; +set_include_path("rubbish"); +testme(); +restore_include_path(); + + +function testme() { + $tmpfile = 'fopen_variation12.tmp'; + $h = fopen($tmpfile, "w", true); + fwrite($h, "This is the test file"); + fclose($h); + + + $h = @fopen($tmpfile, "r"); + if ($h === false) { + echo "Not created in working dir\n"; + } + else { + echo "created in working dir\n"; + fclose($h); + unlink($tmpfile); + } + + $scriptDirFile = dirname(__FILE__).'/'.$tmpfile; + $h = fopen($scriptDirFile, "r"); + if ($h === false) { + echo "Not created in script dir\n"; + } + else { + echo "created in script dir\n"; + fclose($h); + unlink($scriptDirFile); + } +} +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +Not created in working dir +created in script dir +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation13.phpt b/ext/standard/tests/file/fopen_variation13.phpt new file mode 100644 index 0000000000..01a7346d79 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation13.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test fopen() function : variation: use include path create a file (absolute) +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing fopen() : variation ***\n"; +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_path(); +set_include_path($newpath); +runtest(); + +teardown_include_path(); +restore_include_path(); + + +function runtest() { + $tempDir = 'fopen_variation13.dir.tmp'; + $tmpfile = 'fopen_variation13.tmp'; + $absFile = getcwd().'/'.$tempDir.'/'.$tmpfile; + + mkdir($tempDir); + $h = fopen($absFile, "w", true); + fwrite($h, "This is the test file"); + fclose($h); + + + $h = fopen($absFile, "r"); + if ($h === false) { + echo "Not created absolute location\n"; + } + else { + echo "Created in correct location\n"; + fclose($h); + } + unlink($absFile); + rmdir($tempDir); + +} +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +Created in correct location +Created in correct location +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation14-win32.phpt b/ext/standard/tests/file/fopen_variation14-win32.phpt new file mode 100644 index 0000000000..7bc32d8313 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation14-win32.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test fopen() function : variation: file uri, no use include path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Run only on Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; + +// fopen with interesting windows paths. +$testDir = 'fopen14.tmpDir'; +$absTestDir = getcwd().'/'.$testDir; +$file = "fopen_variation14.tmp"; +$unixifiedDir = '/'.substr(str_replace('\\','/',$absTestDir),3); +$absFile = $absTestDir.'/'.$file; + +mkdir($testDir); + +$files = array("file://$testDir\\$file", + "file://$testDir/$file", + "file://./$testDir/$file", + "file://.\\$testDir\\$file", + "file://$absTestDir/$file", + "file://$absTestDir\\$file", + "file://$unixifiedDir/$file" +); + +runtest($files); + +chdir($testDir); +$files = array("file://../$testDir/$file", + "file://..\\$testDir\\$file", + "file://$absTestDir/$file", + "file://$absTestDir\\$file", + "file://$unixifiedDir/$file" +); +runtest($files); +chdir(".."); +rmdir($testDir); + +function runtest($fileURIs) { + global $absFile; + $iteration = 0; + foreach($fileURIs as $fileURI) { + echo "--- READ: $fileURI ---\n"; + + $readData = "read:$iteration"; + $writeData = "write:$iteration"; + + // create the file and test read + $h = fopen($absFile, 'w'); + fwrite($h, $readData); + fclose($h); + + $h = fopen($fileURI, 'r'); + if ($h !== false) { + if (fread($h, 4096) != $readData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + + echo "--- WRITE: $fileURI ---\n"; + // create the file to test write + $h = fopen($fileURI, 'w'); + if ($h !== false) { + fwrite($h, $writeData); + fclose($h); + + $h = fopen($absFile, 'r'); + if ($h !== false) { + if (fread($h, 4096) != $writeData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + } + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** +--- READ: file://fopen14.tmpDir\fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir\fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://fopen14.tmpDir\fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir\fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://./fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://./fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://.\fopen14.tmpDir\fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://.\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://.\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://.\fopen14.tmpDir\fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://.\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://.\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- WRITE: file://%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- READ: file://%s/fopen14.tmpDir\fopen_variation14.tmp --- +test passed +--- WRITE: file://%s/fopen14.tmpDir\fopen_variation14.tmp --- +test passed +--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- READ: file://../fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://../fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://..\fopen14.tmpDir\fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://..\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://..\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://..\fopen14.tmpDir\fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://..\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://..\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- WRITE: file://%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- READ: file://%s/fopen14.tmpDir\fopen_variation14.tmp --- +test passed +--- WRITE: file://%s/fopen14.tmpDir\fopen_variation14.tmp --- +test passed +--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +===DONE=== + diff --git a/ext/standard/tests/file/fopen_variation14.phpt b/ext/standard/tests/file/fopen_variation14.phpt new file mode 100644 index 0000000000..c19e7e6d8f --- /dev/null +++ b/ext/standard/tests/file/fopen_variation14.phpt @@ -0,0 +1,136 @@ +--TEST-- +Test fopen() function : variation: file uri, no use include path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip not for Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; + +// fopen with interesting windows paths. +$testDir = 'fopen14.tmpDir'; +$absTestDir = getcwd().'/'.$testDir; +$file = "fopen_variation14.tmp"; +$absFile = $absTestDir.'/'.$file; + +mkdir($testDir); + +$files = array("file://$testDir/$file", + "file://./$testDir/$file", + "file://$absTestDir/$file" +); + +runtest($files); + +chdir($testDir); +$files = array("file://../$testDir/$file", + "file://$absTestDir/$file", +); +runtest($files); +chdir(".."); +rmdir($testDir); + +function runtest($fileURIs) { + global $absFile; + $iteration = 0; + foreach($fileURIs as $fileURI) { + echo "--- READ: $fileURI ---\n"; + + $readData = "read:$iteration"; + $writeData = "write:$iteration"; + + // create the file and test read + $h = fopen($absFile, 'w'); + fwrite($h, $readData); + fclose($h); + + $h = fopen($fileURI, 'r'); + if ($h !== false) { + if (fread($h, 4096) != $readData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + + echo "--- WRITE: $fileURI ---\n"; + // create the file to test write + $h = fopen($fileURI, 'w'); + if ($h !== false) { + fwrite($h, $writeData); + fclose($h); + + $h = fopen($absFile, 'r'); + if ($h !== false) { + if (fread($h, 4096) != $writeData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + } + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** +--- READ: file://fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://./fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://./fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- READ: file://../fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://../fopen14.tmpDir/fopen_variation14.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d + +Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- +test passed +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/fopen_variation15-win32.phpt b/ext/standard/tests/file/fopen_variation15-win32.phpt new file mode 100644 index 0000000000..ef4f90f53a --- /dev/null +++ b/ext/standard/tests/file/fopen_variation15-win32.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test fopen() function : variation: file uri, use include path = true +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Run only on Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; + +// fopen with interesting windows paths. +$includePathDir = getcwd().'/fopen15.includeDir'; +$testDir = 'fopen15.tmpDir'; +$absTestDir = getcwd().'/'.$testDir; +$file = "fopen_variation15.tmp"; +$unixifiedDir = '/'.substr(str_replace('\\','/',$absTestDir),3); +$absFile = $absTestDir.'/'.$file; + +mkdir($testDir); +mkdir($includePathDir); +set_include_path($includePathDir); + +$files = array("file://$testDir\\$file", + "file://$testDir/$file", + "file://./$testDir/$file", + "file://.\\$testDir\\$file", + "file://$absTestDir/$file", + "file://$absTestDir\\$file", + "file://$unixifiedDir/$file" +); + +runtest($files); + +chdir($testDir); +$files = array("file://../$testDir/$file", + "file://..\\$testDir\\$file", + "file://$absTestDir/$file", + "file://$absTestDir\\$file", + "file://$unixifiedDir/$file" +); +runtest($files); +chdir(".."); +rmdir($testDir); +rmdir($includePathDir); + +function runtest($fileURIs) { + global $absFile; + $iteration = 0; + foreach($fileURIs as $fileURI) { + echo "--- READ: $fileURI ---\n"; + + $readData = "read:$iteration"; + $writeData = "write:$iteration"; + + // create the file and test read + $h = fopen($absFile, 'w'); + fwrite($h, $readData); + fclose($h); + + $h = fopen($fileURI, 'r', true); + if ($h !== false) { + if (fread($h, 4096) != $readData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + + echo "--- WRITE: $fileURI ---\n"; + // create the file to test write + $h = fopen($fileURI, 'w', true); + if ($h !== false) { + fwrite($h, $writeData); + fclose($h); + + $h = fopen($absFile, 'r'); + if ($h !== false) { + if (fread($h, 4096) != $writeData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + } + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** +--- READ: file://fopen15.tmpDir\fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir\fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://fopen15.tmpDir\fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir\fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://./fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://.\fopen15.tmpDir\fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://.\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://.\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://.\fopen15.tmpDir\fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://.\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://.\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- WRITE: file://%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- READ: file://%s/fopen15.tmpDir\fopen_variation15.tmp --- +test passed +--- WRITE: file://%s/fopen15.tmpDir\fopen_variation15.tmp --- +test passed +--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- READ: file://../fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://..\fopen15.tmpDir\fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://..\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://..\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://..\fopen15.tmpDir\fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://..\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://..\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- WRITE: file://%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- READ: file://%s/fopen15.tmpDir\fopen_variation15.tmp --- +test passed +--- WRITE: file://%s/fopen15.tmpDir\fopen_variation15.tmp --- +test passed +--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +===DONE=== + diff --git a/ext/standard/tests/file/fopen_variation15.phpt b/ext/standard/tests/file/fopen_variation15.phpt new file mode 100644 index 0000000000..7753be365a --- /dev/null +++ b/ext/standard/tests/file/fopen_variation15.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test fopen() function : variation: file uri, use include path = true +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not for Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; + +// fopen with interesting windows paths. +$includePathDir = getcwd().'/fopen15.includeDir'; +$testDir = 'fopen15.tmpDir'; +$absTestDir = getcwd().'/'.$testDir; +$file = "fopen_variation15.tmp"; +$absFile = $absTestDir.'/'.$file; + +mkdir($testDir); +mkdir($includePathDir); +set_include_path($includePathDir); + +$files = array("file://$testDir/$file", + "file://./$testDir/$file", + "file://$absTestDir/$file" +); + +runtest($files); + +chdir($testDir); +$files = array("file://../$testDir/$file", + "file://$absTestDir/$file" +); +runtest($files); +chdir(".."); +rmdir($testDir); +rmdir($includePathDir); + +function runtest($fileURIs) { + global $absFile; + $iteration = 0; + foreach($fileURIs as $fileURI) { + echo "--- READ: $fileURI ---\n"; + + $readData = "read:$iteration"; + $writeData = "write:$iteration"; + + // create the file and test read + $h = fopen($absFile, 'w'); + fwrite($h, $readData); + fclose($h); + + $h = fopen($fileURI, 'r', true); + if ($h !== false) { + if (fread($h, 4096) != $readData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + + echo "--- WRITE: $fileURI ---\n"; + // create the file to test write + $h = fopen($fileURI, 'w', true); + if ($h !== false) { + fwrite($h, $writeData); + fclose($h); + + $h = fopen($absFile, 'r'); + if ($h !== false) { + if (fread($h, 4096) != $writeData) { + echo "contents not correct\n"; + } + else { + echo "test passed\n"; + } + fclose($h); + } + unlink($absFile); + } + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** +--- READ: file://fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file://./fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- READ: file://../fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp --- + +Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d + +Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d +--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- +test passed +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/fopen_variation16.phpt b/ext/standard/tests/file/fopen_variation16.phpt new file mode 100644 index 0000000000..375747f7f1 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation16.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen() function : variation: use include path create and read a file (relative) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--XFAIL-- +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing fopen() : variation ***\n"; +$thisTestDir = "fopenVariation16.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_path(); +set_include_path($newpath); +runtest(); + +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + +function runtest() { + global $dir1; + + $extraDir = "extraDir"; + + mkdir($dir1.'/'.$extraDir); + + $tmpfile = $extraDir.'/fopen_variation16.tmp'; + $h = fopen($tmpfile, "w+", true); + fwrite($h, "This is the test file"); + fclose($h); + + $h = fopen($dir1.'/'.$tmpfile, "r"); + if ($h === false) { + echo "Not created in dir1\n"; + } + else { + echo "created in dir1\n"; + fclose($h); + } + + $h = fopen($tmpfile, "r", true); + if ($h === false) { + echo "could not find file for reading\n"; + } + else { + echo "found file again in dir1\n"; + fclose($h); + } + + unlink($dir1.'/'.$tmpfile); + rmdir($dir1.'/'.$extraDir); +} +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +created in dir1 +found file again in dir1 +created in dir1 +found file again in dir1 +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation17.phpt b/ext/standard/tests/file/fopen_variation17.phpt new file mode 100644 index 0000000000..b47060c908 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation17.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen() function : variation: use include path create and read a file (relative) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--XFAIL-- +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing fopen() : variation ***\n"; +$thisTestDir = "fopenVariation17.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_path(); +set_include_path($newpath); +runtest(); + +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + +function runtest() { + global $dir1; + + $extraDir = "extraDir"; + + mkdir($dir1.'/'.$extraDir); + + $tmpfile = $extraDir.'/fopen_variation17.tmp'; + $h = fopen($tmpfile, "w+", true); + fwrite($h, "This is the test file"); + fclose($h); + + $h = fopen($dir1.'/'.$tmpfile, "r"); + if ($h === false) { + echo "Not created in dir1\n"; + } + else { + echo "created in dir1\n"; + fclose($h); + } + + $h = fopen($tmpfile, "r", true); + if ($h === false) { + echo "could not find file for reading\n"; + } + else { + echo "found file again in dir1\n"; + fclose($h); + } + + unlink($dir1.'/'.$tmpfile); + rmdir($dir1.'/'.$extraDir); +} +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +created in dir1 +found file again in dir1 +created in dir1 +found file again in dir1 +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation19.phpt b/ext/standard/tests/file/fopen_variation19.phpt new file mode 100644 index 0000000000..7b0e5b3159 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation19.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test fopen() function : variation: test opening linked files +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not for Windows"); +?> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +$tmpDir = 'fopenVar19.Dir'; +$realFilename = __FILE__.'.real'; +$sortFilename = __FILE__.'.soft'; +$hardFilename = __FILE__.'.hard'; +$linkOfLink = __FILE__.'.soft2'; + +echo "*** Testing fopen() : variation ***\n"; +// start the test +mkdir($tmpDir); +chdir($tmpDir); + +$h = fopen($realFilename, "w"); +fwrite($h, "Hello World"); +fclose($h); + +symlink($realFilename, $sortFilename); +symlink($sortFilename, $linkOfLink); +link($realFilename, $hardFilename); + + + +echo "*** testing reading of links ***\n"; +echo "soft link:"; +readFile2($sortFilename); +echo "hard link:"; +readFile2($hardFilename); +echo "link of link:"; +readFile2($linkOfLink); + +echo "*** test appending to links ***\n"; +echo "soft link:"; +appendFile($sortFilename); +echo "hard link:"; +appendFile($hardFilename); +echo "link of link:"; +appendFile($linkOfLink); + +echo "*** test overwriting links ***\n"; +echo "soft link:"; +writeFile($sortFilename); +echo "hard link:"; +writeFile($hardFilename); +echo "link of link:"; +writeFile($linkOfLink); + +unlink($linkOfLink); +unlink($sortFilename); +unlink($hardFilename); +unlink($realFilename); +chdir(".."); +rmdir($tmpDir); + +function readFile2($file) { + $h = fopen($file, 'r'); + fpassthru($h); + fclose($h); + echo "\n"; +} + +function appendFile($file) { + $h = fopen($file, 'a+'); + fwrite($h, ' again!'); + fseek($h, 0); + fpassthru($h); + fclose($h); + echo "\n"; +} + +function writeFile($file) { + $h = fopen($file, 'w'); + fwrite($h, 'Goodbye World'); + fclose($h); + readFile2($file); +} + + +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +*** testing reading of links *** +soft link:Hello World +hard link:Hello World +link of link:Hello World +*** test appending to links *** +soft link:Hello World again! +hard link:Hello World again! again! +link of link:Hello World again! again! again! +*** test overwriting links *** +soft link:Goodbye World +hard link:Goodbye World +link of link:Goodbye World +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation3.phpt b/ext/standard/tests/file/fopen_variation3.phpt new file mode 100644 index 0000000000..3467a3a606 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation3.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test fopen() function : usage variation different datatypes for use_include_path +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = __FILE__; +$mode = 'r'; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for use_include_path + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $h = fopen($filename, $mode, $value); + if ($h !== false) { + echo "ok\n"; + fclose($h); + } + else { + var_dump($h); + } +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : usage variation *** + +--int 0-- +ok + +--int 1-- +ok + +--int 12345-- +ok + +--int -12345-- +ok + +--float 10.5-- +ok + +--float -10.5-- +ok + +--float 12.3456789000e10-- +ok + +--float -12.3456789000e10-- +ok + +--float .5-- +ok + +--empty array-- +Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d) +bool(false) + +--uppercase NULL-- +ok + +--lowercase null-- +ok + +--lowercase true-- +ok + +--lowercase false-- +ok + +--uppercase TRUE-- +ok + +--uppercase FALSE-- +ok + +--empty string DQ-- +ok + +--empty string SQ-- +ok + +--string DQ-- +ok + +--string SQ-- +ok + +--mixed case string-- +ok + +--heredoc-- +ok + +--instance of classWithToString-- +Error: 2 - fopen() expects parameter 3 to be boolean, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - fopen() expects parameter 3 to be boolean, object given, %s(%d) +bool(false) + +--undefined var-- +ok + +--unset var-- +ok +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation4.phpt b/ext/standard/tests/file/fopen_variation4.phpt new file mode 100644 index 0000000000..0e138d08bb --- /dev/null +++ b/ext/standard/tests/file/fopen_variation4.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test fopen() function : usage variation different datatypes for stream context +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = __FILE__; +$mode = 'r'; +$use_include_path = false; +$fileresource = fopen($filename, $mode); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + //file resource + 'file resource' => $fileresource +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $h = fopen($filename, $mode, false, $value); + if ($h !== false) { + echo "ok\n"; + fclose($h); + } + else { + var_dump($h); + } +}; + +fclose($fileresource); + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : usage variation *** + +--int 0-- +Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d) +bool(false) + +--int 1-- +Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d) +bool(false) + +--float .5-- +Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d) +bool(false) + +--empty array-- +Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d) +bool(false) + +--string DQ-- +Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d) +bool(false) + +--string SQ-- +Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d) +bool(false) + +--mixed case string-- +Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d) +bool(false) + +--heredoc-- +Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - fopen() expects parameter 4 to be resource, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - fopen() expects parameter 4 to be resource, object given, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) +bool(false) + +--unset var-- +Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) +bool(false) + +--file resource-- +Error: 2 - fopen(): supplied resource is not a valid Stream-Context resource, %s(%d) +ok +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation5.phpt b/ext/standard/tests/file/fopen_variation5.phpt new file mode 100644 index 0000000000..9a47708f3e --- /dev/null +++ b/ext/standard/tests/file/fopen_variation5.phpt @@ -0,0 +1,173 @@ +--TEST-- +Test fopen() function : variation: use include path and stream context (absolute directories in path) +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + + + +echo "*** Testing fopen() : variation ***\n"; +//create the include directory structure +$thisTestDir = "fopenVariation5.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$workingDir = "workdir"; +$filename = "afile.txt"; +$scriptDir = dirname(__FILE__); +$baseDir = getcwd(); +$secondFile = $baseDir."/dir2/".$filename; +$firstFile = "../dir1/".$filename; +$scriptFile = $scriptDir.'/'.$filename; + +$newdirs = array("dir1", "dir2", "dir3"); +$pathSep = ":"; +$newIncludePath = ""; +if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; +} +foreach($newdirs as $newdir) { + mkdir($newdir); + $newIncludePath .= $baseDir.'/'.$newdir.$pathSep; +} +mkdir($workingDir); +chdir($workingDir); + +//define the files to go into these directories, create one in dir2 +echo "\n--- testing include path ---\n"; +set_include_path($newIncludePath); +$modes = array("r", "r+", "rt"); +foreach($modes as $mode) { + test_fopen($mode); +} +restore_include_path(); + +// remove the directory structure +chdir($baseDir); +rmdir($workingDir); +foreach($newdirs as $newdir) { + rmdir($newdir); +} + +chdir(".."); +rmdir($thisTestDir); + + +function test_fopen($mode) { + global $scriptFile, $secondFile, $firstFile, $filename; + + // create a file in the middle directory + $h = fopen($secondFile, "w"); + fwrite($h, "in dir2"); + fclose($h); + + echo "\n** testing with mode=$mode **\n"; + // should read dir2 file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + //create a file in dir1 + $h = fopen($firstFile, "w"); + fwrite($h, "in dir1"); + fclose($h); + + //should now read dir1 file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + // create a file in working directory + $h = fopen($filename, "w"); + fwrite($h, "in working dir"); + fclose($h); + + //should still read dir1 file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + unlink($firstFile); + unlink($secondFile); + + //should fail to read the file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + // create a file in the script directory + $h = fopen($scriptFile, "w"); + fwrite($h, "in script dir"); + fclose($h); + + //should read the file in script dir + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + //cleanup + unlink($filename); + unlink($scriptFile); + +} + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** + +--- testing include path --- + +** testing with mode=r ** +in dir2 +in dir1 +in dir1 + +Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d + +Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d + +in script dir + +** testing with mode=r+ ** +in dir2 +in dir1 +in dir1 + +Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d + +Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d + +in script dir + +** testing with mode=rt ** +in dir2 +in dir1 +in dir1 + +Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d + +Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d + +in script dir +===DONE=== + diff --git a/ext/standard/tests/file/fopen_variation6.phpt b/ext/standard/tests/file/fopen_variation6.phpt new file mode 100644 index 0000000000..bcf68b040d --- /dev/null +++ b/ext/standard/tests/file/fopen_variation6.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test fopen() function : variation: use include path and stream context relative/absolute file +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing fopen() : variation ***\n"; +$absfile = __FILE__.'.tmp'; +$relfile = "fopen_variation6.tmp"; + +$h = fopen($absfile, "w"); +fwrite($h, "This is an absolute file"); +fclose($h); + +$h = fopen($relfile, "w"); +fwrite($h, "This is a relative file"); +fclose($h); + +$ctx = stream_context_create(); +$h = fopen($absfile, "r", true, $ctx); +fpassthru($h); +fclose($h); +echo "\n"; + +$h = fopen($relfile, "r", true, $ctx); +fpassthru($h); +fclose($h); +echo "\n"; + +unlink($absfile); +unlink($relfile); +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** +This is an absolute file +This is a relative file +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation7.phpt b/ext/standard/tests/file/fopen_variation7.phpt new file mode 100644 index 0000000000..08ba2d61b8 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation7.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test fopen() function : variation: use include path create a file (relative) +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing fopen() : variation ***\n"; +$thisTestDir = "fopenVariation7.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_path(); +set_include_path($newpath); +runtest(); + +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + +function runtest() { + global $dir1; + $tmpfile = 'fopen_variation7.tmp'; + $h = fopen($tmpfile, "w", true); + fwrite($h, "This is the test file"); + fclose($h); + + + $h = @fopen($tmpfile, "r"); + if ($h === false) { + echo "Not created in working dir\n"; + } + else { + echo "created in working dir\n"; + fclose($h); + unlink($tmpfile); + } + + $h = fopen($dir1.'/'.$tmpfile, "r"); + if ($h === false) { + echo "Not created in dir1\n"; + } + else { + echo "created in dir1\n"; + fclose($h); + unlink($dir1.'/'.$tmpfile); + } +} +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +Not created in working dir +created in dir1 +Not created in working dir +created in dir1 +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation8.phpt b/ext/standard/tests/file/fopen_variation8.phpt new file mode 100644 index 0000000000..b142641adc --- /dev/null +++ b/ext/standard/tests/file/fopen_variation8.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test fopen() function : variation: use include path and stream context (relative directories in path) +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + + + +echo "*** Testing fopen() : variation ***\n"; +$thisTestDir = "fopenVariation8.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +//create the include directory structure +$workingDir = "workdir"; +$filename = "afile.txt"; +$scriptDir = dirname(__FILE__); +$baseDir = getcwd(); +$secondFile = $baseDir."/dir2/".$filename; +$firstFile = "../dir1/".$filename; +$scriptFile = $scriptDir.'/'.$filename; + +$newdirs = array("dir1", "dir2", "dir3"); +$pathSep = ":"; +$newIncludePath = ""; +if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; +} +foreach($newdirs as $newdir) { + mkdir($newdir); + $newIncludePath .= '../'.$newdir.$pathSep; +} +mkdir($workingDir); +chdir($workingDir); + +//define the files to go into these directories, create one in dir2 +echo "\n--- testing include path ---\n"; +set_include_path($newIncludePath); +$modes = array("r", "r+", "rt"); +foreach($modes as $mode) { + test_fopen($mode); +} +restore_include_path(); + +// remove the directory structure +chdir($baseDir); +rmdir($workingDir); +foreach($newdirs as $newdir) { + rmdir($newdir); +} + +chdir(".."); +rmdir($thisTestDir); + +function test_fopen($mode) { + global $scriptFile, $secondFile, $firstFile, $filename; + + // create a file in the middle directory + $h = fopen($secondFile, "w"); + fwrite($h, "in dir2"); + fclose($h); + + echo "\n** testing with mode=$mode **\n"; + // should read dir2 file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + //create a file in dir1 + $h = fopen($firstFile, "w"); + fwrite($h, "in dir1"); + fclose($h); + + //should now read dir1 file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + // create a file in working directory + $h = fopen($filename, "w"); + fwrite($h, "in working dir"); + fclose($h); + + //should still read dir1 file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + unlink($firstFile); + unlink($secondFile); + + //should fail to read the file + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + // create a file in the script directory + $h = fopen($scriptFile, "w"); + fwrite($h, "in script dir"); + fclose($h); + + //should read the file in script dir + $h = fopen($filename, $mode, true); + fpassthru($h); + fclose($h); + echo "\n"; + + //cleanup + unlink($filename); + unlink($scriptFile); + +} + +?> +===DONE=== +--EXPECTF-- +*** Testing fopen() : variation *** + +--- testing include path --- + +** testing with mode=r ** +in dir2 +in dir1 +in dir1 + +Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d + +Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d + +in script dir + +** testing with mode=r+ ** +in dir2 +in dir1 +in dir1 + +Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d + +Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d + +in script dir + +** testing with mode=rt ** +in dir2 +in dir1 +in dir1 + +Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d + +Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d + +in script dir +===DONE=== + diff --git a/ext/standard/tests/file/fopen_variation9.phpt b/ext/standard/tests/file/fopen_variation9.phpt new file mode 100644 index 0000000000..f144b22563 --- /dev/null +++ b/ext/standard/tests/file/fopen_variation9.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test fopen() function : variation: use include path and stream context create a file, relative path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) + * Description: Open a file or a URL and return a file pointer + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing fopen() : variation ***\n"; +$thisTestDir = "fopenVariation9.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$newpath = relative_include_path(); +set_include_path($newpath); +runtest(); +$newpath = generate_next_rel_path(); +set_include_path($newpath); +runtest(); + +teardown_relative_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + +function runtest() { + $tmpfile = 'fopen_variation7.tmp'; + $h = fopen($tmpfile, "w", true); + fwrite($h, "This is the test file"); + fclose($h); + + + $h = @fopen($tmpfile, "r"); + if ($h === false) { + echo "Not created in working dir\n"; + } + else { + echo "created in working dir\n"; + fclose($h); + unlink($tmpfile); + } + + $h = fopen('dir1/'.$tmpfile, "r"); + if ($h === false) { + echo "Not created in dir1\n"; + } + else { + echo "created in dir1\n"; + fclose($h); + unlink('dir1/'.$tmpfile); + } +} +?> +===DONE=== +--EXPECT-- +*** Testing fopen() : variation *** +Not created in working dir +created in dir1 +Not created in working dir +created in dir1 +===DONE=== diff --git a/ext/standard/tests/file/fpassthru_error.phpt b/ext/standard/tests/file/fpassthru_error.phpt index e9bfd26008..ada182dbbe 100644 --- a/ext/standard/tests/file/fpassthru_error.phpt +++ b/ext/standard/tests/file/fpassthru_error.phpt @@ -1,5 +1,7 @@ --TEST-- Test fpassthru() function: Error conditions +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php /* @@ -20,6 +22,11 @@ var_dump( fpassthru() ); /* No.of args greaer than expected */ var_dump( fpassthru("", "") ); +/* fpassthru on a closed file */ +$h = fopen(__FILE__,'r'); +fclose($h); +fpassthru($h); + echo "\n*** Done ***\n"; ?> @@ -28,13 +35,16 @@ echo "\n*** Done ***\n"; Warning: fread() expects parameter 1 to be resource, Unicode string given in %s on line %d -Warning: fpassthru() expects parameter 1 to be resource, null given in %s on line %d -NULL +Warning: fpassthru() expects parameter 1 to be resource, boolean given in %s on line %d +bool(false) Warning: fpassthru() expects exactly 1 parameter, 0 given in %s on line %d -NULL +bool(false) Warning: fpassthru() expects exactly 1 parameter, 2 given in %s on line %d -NULL +bool(false) + +Warning: fpassthru(): 5 is not a valid stream resource in %s on line %d *** Done *** + diff --git a/ext/standard/tests/file/fpassthru_variation1.phpt b/ext/standard/tests/file/fpassthru_variation1.phpt new file mode 100644 index 0000000000..9336eb6c5e --- /dev/null +++ b/ext/standard/tests/file/fpassthru_variation1.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test fpassthru() function : usage variations - different parameter types +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto int fpassthru(resource fp) + * Description: Output all remaining data from a file pointer + * Source code: ext/standard/file.c + * Alias to functions: gzpassthru + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing fpassthru() : usage variations ***\n"; +error_reporting(E_ALL & ~E_NOTICE); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +class testClass { + public function __toString() { + return "testClass"; + } +} + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new testClass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for fp + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( fpassthru($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing fpassthru() : usage variations *** + +Arg value 0 + +Warning: fpassthru() expects parameter 1 to be resource, integer given in %s on line %d +bool(false) + +Arg value 1 + +Warning: fpassthru() expects parameter 1 to be resource, integer given in %s on line %d +bool(false) + +Arg value 12345 + +Warning: fpassthru() expects parameter 1 to be resource, integer given in %s on line %d +bool(false) + +Arg value -2345 + +Warning: fpassthru() expects parameter 1 to be resource, integer given in %s on line %d +bool(false) + +Arg value 10.5 + +Warning: fpassthru() expects parameter 1 to be resource, double given in %s on line %d +bool(false) + +Arg value -10.5 + +Warning: fpassthru() expects parameter 1 to be resource, double given in %s on line %d +bool(false) + +Arg value 101234567000 + +Warning: fpassthru() expects parameter 1 to be resource, double given in %s on line %d +bool(false) + +Arg value 1.07654321E-9 + +Warning: fpassthru() expects parameter 1 to be resource, double given in %s on line %d +bool(false) + +Arg value 0.5 + +Warning: fpassthru() expects parameter 1 to be resource, double given in %s on line %d +bool(false) + +Arg value Array + +Warning: fpassthru() expects parameter 1 to be resource, array given in %s on line %d +bool(false) + +Arg value Array + +Warning: fpassthru() expects parameter 1 to be resource, array given in %s on line %d +bool(false) + +Arg value Array + +Warning: fpassthru() expects parameter 1 to be resource, array given in %s on line %d +bool(false) + +Arg value Array + +Warning: fpassthru() expects parameter 1 to be resource, array given in %s on line %d +bool(false) + +Arg value Array + +Warning: fpassthru() expects parameter 1 to be resource, array given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, null given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, null given in %s on line %d +bool(false) + +Arg value 1 + +Warning: fpassthru() expects parameter 1 to be resource, boolean given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, boolean given in %s on line %d +bool(false) + +Arg value 1 + +Warning: fpassthru() expects parameter 1 to be resource, boolean given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, boolean given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, Unicode string given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, Unicode string given in %s on line %d +bool(false) + +Arg value string + +Warning: fpassthru() expects parameter 1 to be resource, Unicode string given in %s on line %d +bool(false) + +Arg value string + +Warning: fpassthru() expects parameter 1 to be resource, Unicode string given in %s on line %d +bool(false) + +Arg value testClass + +Warning: fpassthru() expects parameter 1 to be resource, object given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, null given in %s on line %d +bool(false) + +Arg value + +Warning: fpassthru() expects parameter 1 to be resource, null given in %s on line %d +bool(false) +Done + diff --git a/ext/standard/tests/file/fread_error.phpt b/ext/standard/tests/file/fread_error.phpt index ae45f5e274..152a717327 100644 --- a/ext/standard/tests/file/fread_error.phpt +++ b/ext/standard/tests/file/fread_error.phpt @@ -1,5 +1,7 @@ --TEST-- Test fread() function : error conditions +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php /* @@ -62,11 +64,11 @@ echo "Done\n"; -- Testing fread() with zero argument -- Warning: fread() expects exactly 2 parameters, 0 given in %s on line %d -NULL +bool(false) -- Testing fread() with more than expected number of arguments -- Warning: fread() expects exactly 2 parameters, 3 given in %s on line %d -NULL +bool(false) -- Testing fread() with invalid length arguments -- Warning: fread(): Length parameter must be greater than 0 in %s on line %d @@ -78,37 +80,38 @@ bool(false) -- Iteration 1 -- Warning: fread() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: fread() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: fread() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: fread() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: fread() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: fread() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing fwrite() with closed/unset file handle -- Notice: Undefined variable: file_content_type in %s on line %d -Warning: fread(): 5 is not a valid stream resource in %s on line %d +Warning: fread(): %d is not a valid stream resource in %s on line %d bool(false) Warning: fread() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Warning: fclose() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Done + diff --git a/ext/standard/tests/file/fread_fwrite_basic.phpt b/ext/standard/tests/file/fread_fwrite_basic.phpt new file mode 100644 index 0000000000..c5ded8a18f --- /dev/null +++ b/ext/standard/tests/file/fread_fwrite_basic.phpt @@ -0,0 +1,74 @@ +--TEST-- +fread & fwrite - Test reading and writing using a single resource +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php + +/* + * proto int fwrite(resource fp, string str [, int length]) + * Function is implemented in ext/standard/file.c + */ + + /* + Prototype: string fread ( resource $handle [, int $length] ); + Description: reads up to length bytes from the file pointer referenced by handle. + Reading stops when up to length bytes have been read, EOF (end of file) is + reached, (for network streams) when a packet becomes available, or (after + opening userspace stream) when 8192 bytes have been read whichever comes first. +*/ + + +$outputfile = __FILE__.".tmp"; + +echo "--- testing rw moving about the file ---\n"; +$h = fopen($outputfile, 'wb+'); +$out1 = "The 1st prrt"; +$out2 = " part of the ttxt"; +$out3 = "text"; +fwrite($h, $out1); +fseek($h, 0, SEEK_SET); +echo "start:".fread($h, strlen($out1) - 5). "\n"; +fwrite($h, $out2); +echo "at end:".fread($h,100)."\n"; +var_dump(feof($h)); +fseek($h, -4, SEEK_CUR); +fwrite($h, $out3); +fseek($h, 0, SEEK_SET); +echo "final:".fread($h, 100)."\n"; +fclose($h); + +echo "--- testing eof ---\n"; +$h = fopen($outputfile, 'ab+'); +fread($h,1024); +var_dump(feof($h)); +fread($h,1); +var_dump(feof($h)); +$out = "extra"; +fwrite($h, $out); +var_dump(feof($h)); +fread($h,1); +var_dump(feof($h)); +fseek($h, -strlen($out) + 1, SEEK_CUR); +echo "last bytes: ".fread($h, strlen($out))."\n"; +fclose($h); + +unlink($outputfile); + +echo "Done"; +?> +--EXPECT-- +--- testing rw moving about the file --- +start:The 1st +at end: +bool(true) +final:The 1st part of the text +--- testing eof --- +bool(true) +bool(true) +bool(true) +bool(true) +last bytes: xtra +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/fseek_dir_basic.phpt b/ext/standard/tests/file/fseek_dir_basic.phpt index 8854af9138..f91399a8b9 100644 --- a/ext/standard/tests/file/fseek_dir_basic.phpt +++ b/ext/standard/tests/file/fseek_dir_basic.phpt @@ -1,5 +1,7 @@ --TEST-- Testing fseek() on a directory stream +--XFAIL-- +Pending completion of Unicode streams --FILE-- <?php @@ -40,9 +42,9 @@ closedir($dh); var_dump(rmdir($path)); ?> ---EXPECT-- +--EXPECTF-- call readdir(): -resource(12) of type (stream) +resource(%d) of type (stream) array(6) { [0]=> bool(false) diff --git a/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt b/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt index e84a9f1a90..b6b69952bc 100644 --- a/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt +++ b/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt @@ -1,5 +1,7 @@ --TEST-- Test fseek(), ftell() & rewind() functions : error conditions - fseek() +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php @@ -57,43 +59,44 @@ echo "Done\n"; -- Testing fseek() with zero argument -- Warning: fseek() expects at least 2 parameters, 0 given in %s on line %d -NULL +bool(false) -- Testing fseek() with unexpected number of arguments -- Warning: fseek() expects at least 2 parameters, 1 given in %s on line %d -NULL +bool(false) Warning: fseek() expects at most 3 parameters, 4 given in %s on line %d -NULL +bool(false) -- Testing fseek() with invalid arguments -- -- Iteration 1 -- Warning: fseek() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: fseek() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: fseek() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: fseek() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: fseek() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: fseek() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing fseek() with closed/unset file handle -- Warning: fseek(): %d is not a valid stream resource in %s on line %d bool(false) Warning: fseek() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Done + diff --git a/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt b/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt index a41f3b17a2..86b4d178de 100644 --- a/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt +++ b/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt @@ -1,5 +1,7 @@ --TEST-- Test fseek(), ftell() & rewind() functions : error conditions - ftell() +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php @@ -56,40 +58,41 @@ echo "Done\n"; -- Testing ftell() with zero argument -- Warning: ftell() expects exactly 1 parameter, 0 given in %s on line %d -NULL +bool(false) -- Testing ftell() with more than expected number of arguments -- Warning: ftell() expects exactly 1 parameter, 2 given in %s on line %d -NULL +bool(false) -- Testing ftell() with invalid arguments -- -- Iteration 1 -- Warning: ftell() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: ftell() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: ftell() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: ftell() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: ftell() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: ftell() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing ftell with closed/unset file handle -- Warning: ftell(): %d is not a valid stream resource in %s on line %d bool(false) Warning: ftell() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Done + diff --git a/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt b/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt index cdd73f5093..1bc3b02218 100644 --- a/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt +++ b/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt @@ -1,5 +1,7 @@ --TEST-- Test fseek(), ftell() & rewind() functions : error conditions - rewind() +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php @@ -56,40 +58,41 @@ echo "Done\n"; -- Testing rewind() with zero argument -- Warning: rewind() expects exactly 1 parameter, 0 given in %s on line %d -NULL +bool(false) -- Testing rewind() with more than expected number of arguments -- Warning: rewind() expects exactly 1 parameter, 2 given in %s on line %d -NULL +bool(false) -- Testing rewind() with invalid arguments -- -- Iteration 1 -- Warning: rewind() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: rewind() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: rewind() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: rewind() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: rewind() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: rewind() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing rewind() with closed/unset file handle -- Warning: rewind(): %d is not a valid stream resource in %s on line %d bool(false) Warning: rewind() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Done + diff --git a/ext/standard/tests/file/fseek_variation1.phpt b/ext/standard/tests/file/fseek_variation1.phpt new file mode 100644 index 0000000000..45dc5a804c --- /dev/null +++ b/ext/standard/tests/file/fseek_variation1.phpt @@ -0,0 +1,200 @@ +--TEST-- +Test fseek() function : usage variations - different types for offset +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto int fseek(resource fp, int offset [, int whence]) + * Description: Seek on a file pointer + * Source code: ext/standard/file.c + * Alias to functions: gzseek + */ + +echo "*** Testing fseek() : usage variations ***\n"; +error_reporting(E_ALL & ~E_NOTICE); + +// Initialise function arguments not being substituted (if any) + +$fp = fopen(__FILE__, 'r'); +$whence = SEEK_SET; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +class testClass { + public function __toString() { + return "testClass"; + } +} + + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new testClass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for offset + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( fseek($fp, $value, $whence) ); + var_dump( ftell($fp)); +}; +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing fseek() : usage variations *** + +Arg value 10.5 +int(0) +int(10) + +Arg value -10.5 +int(-1) +int(10) + +Arg value 1.07654321E-9 +int(0) +int(0) + +Arg value 0.5 +int(0) +int(0) + +Arg value Array + +Warning: fseek() expects parameter 2 to be long, array given in %s on line %d +bool(false) +int(0) + +Arg value Array + +Warning: fseek() expects parameter 2 to be long, array given in %s on line %d +bool(false) +int(0) + +Arg value Array + +Warning: fseek() expects parameter 2 to be long, array given in %s on line %d +bool(false) +int(0) + +Arg value Array + +Warning: fseek() expects parameter 2 to be long, array given in %s on line %d +bool(false) +int(0) + +Arg value Array + +Warning: fseek() expects parameter 2 to be long, array given in %s on line %d +bool(false) +int(0) + +Arg value +int(0) +int(0) + +Arg value +int(0) +int(0) + +Arg value 1 +int(0) +int(1) + +Arg value +int(0) +int(0) + +Arg value 1 +int(0) +int(1) + +Arg value +int(0) +int(0) + +Arg value + +Warning: fseek() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) +int(0) + +Arg value + +Warning: fseek() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) +int(0) + +Arg value string + +Warning: fseek() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) +int(0) + +Arg value string + +Warning: fseek() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) +int(0) + +Arg value testClass + +Warning: fseek() expects parameter 2 to be long, object given in %s on line %d +bool(false) +int(0) + +Arg value +int(0) +int(0) + +Arg value +int(0) +int(0) +Done + diff --git a/ext/standard/tests/file/fseek_variation2.phpt b/ext/standard/tests/file/fseek_variation2.phpt new file mode 100644 index 0000000000..5495f9ab73 --- /dev/null +++ b/ext/standard/tests/file/fseek_variation2.phpt @@ -0,0 +1,165 @@ +--TEST-- +Test fseek() function : usage variations - different types for whence +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto int fseek(resource fp, int offset [, int whence]) + * Description: Seek on a file pointer + * Source code: ext/standard/file.c + * Alias to functions: gzseek + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing fseek() : usage variations ***\n"; +error_reporting(E_ALL & ~E_NOTICE); +$fp = fopen(__FILE__, 'r'); +$offset = 3; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // outside of whence range + -100, + 100, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for whence + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( fseek($fp, $offset, $value) ); + var_dump( ftell($fp)); +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing fseek() : usage variations *** + +Arg value -100 +int(-1) +int(0) + +Arg value 100 +int(-1) +int(0) + +Arg value 10.5 +int(-1) +int(0) + +Arg value -10.5 +int(-1) +int(0) + +Arg value 101234567000 +int(-1) +int(0) + +Arg value 1.07654321E-9 +int(0) +int(3) + +Arg value 0.5 +int(0) +int(3) + +Arg value +int(0) +int(3) + +Arg value +int(0) +int(3) + +Arg value 1 +int(0) +int(6) + +Arg value +int(0) +int(3) + +Arg value 1 +int(0) +int(6) + +Arg value +int(0) +int(3) + +Arg value + +Warning: fseek() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) +int(3) + +Arg value + +Warning: fseek() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) +int(3) + +Arg value string + +Warning: fseek() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) +int(3) + +Arg value string + +Warning: fseek() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) +int(3) + +Arg value +int(0) +int(3) + +Arg value +int(0) +int(3) +Done + diff --git a/ext/standard/tests/file/fseek_variation3.phpt b/ext/standard/tests/file/fseek_variation3.phpt new file mode 100644 index 0000000000..b79c0ce00d --- /dev/null +++ b/ext/standard/tests/file/fseek_variation3.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test fseek() function : variation functionality beyond file boundaries +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : proto int fseek(resource fp, int offset [, int whence]) + * Description: Seek on a file pointer + * Source code: ext/standard/file.c + * Alias to functions: gzseek + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing fseek() : variation - beyond file boundaries ***\n"; + +$outputfile = __FILE__.".tmp"; + +$h = fopen($outputfile, "wb+"); +for ($i = 1; $i < 10; $i++) { + fwrite($h, chr(0x30 + $i)); +} + +echo "--- fseek beyond start of file ---\n"; +var_dump(fseek($h, -4, SEEK_SET)); +echo "after -4 seek: ".bin2hex(fread($h,1))."\n"; +var_dump(fseek($h, -1, SEEK_CUR)); +echo "after seek back 1: ".bin2hex(fread($h,1))."\n"; +var_dump(fseek($h, -20, SEEK_CUR)); +echo "after seek back 20: ".bin2hex(fread($h,1))."\n"; + +echo "--- fseek beyond end of file ---\n"; +var_dump(fseek($h, 16, SEEK_SET)); +fwrite($h, b"end"); +fseek($h ,0, SEEK_SET); +$data = fread($h, 4096); +echo bin2hex($data)."\n"; + +fclose($h); +unlink($outputfile); + +echo "Done"; +?> +--EXPECTF-- +*** Testing fseek() : variation - beyond file boundaries *** +--- fseek beyond start of file --- +int(-1) +after -4 seek: +int(0) +after seek back 1: 39 +int(-1) +after seek back 20: +--- fseek beyond end of file --- +int(0) +31323334353637383900000000000000656e64 +Done diff --git a/ext/standard/tests/file/ftruncate_error.phpt b/ext/standard/tests/file/ftruncate_error.phpt index 444d18d4f6..a792b72662 100644 --- a/ext/standard/tests/file/ftruncate_error.phpt +++ b/ext/standard/tests/file/ftruncate_error.phpt @@ -1,5 +1,7 @@ --TEST-- Test ftruncate() function : error conditions +--XFAIL-- +Pending completion of Unicode streams --FILE-- <?php /* @@ -11,7 +13,7 @@ echo "*** Testing ftruncate() : error conditions ***\n"; $filename = dirname(__FILE__)."/ftruncate_error.tmp"; $file_handle = fopen($filename, "w" ); -fwrite($file_handle, (binary)"Testing ftruncate error conditions \n"); +fwrite($file_handle, "Testing ftruncate error conditions \n"); fflush($file_handle); echo "\n Initial file size = ".filesize($filename)."\n"; @@ -23,12 +25,14 @@ var_dump( ftruncate() ); // arguments less than expected numbers var_dump( ftruncate( $file_handle ) ); // check the first size +clearstatcache(); var_dump( filesize($filename) ); echo "-- Testing ftruncate() with more than expected number of arguments --\n"; // more than expected number of arguments var_dump( ftruncate($file_handle, 10, 20) ); -// check the first size +// check the first size +clearstatcache(); var_dump( filesize($filename) ); // test invalid arguments : non-resources @@ -53,14 +57,16 @@ echo "-- Testing ftruncate() with closed/unset file handle --\n"; // ftruncate on close file handle fclose($file_handle); var_dump( ftruncate($file_handle,10) ); -// check the first size +// check the first size +clearstatcache(); var_dump( filesize($filename) ); // ftruncate on a file handle which is unset $fp = fopen($filename, "w"); unset($fp); //unset file handle var_dump( ftruncate(@$fp,10)); -// check the first size +// check the first size +clearstatcache(); var_dump( filesize($filename) ); echo "Done\n"; @@ -77,41 +83,41 @@ unlink( $filename ); -- Testing ftruncate() with less than expected number of arguments -- Warning: ftruncate() expects exactly 2 parameters, 0 given in %s on line %d -NULL +bool(false) Warning: ftruncate() expects exactly 2 parameters, 1 given in %s on line %d -NULL +bool(false) int(36) -- Testing ftruncate() with more than expected number of arguments -- Warning: ftruncate() expects exactly 2 parameters, 3 given in %s on line %d -NULL +bool(false) int(36) -- Testing ftruncate() with invalid file pointer -- -- Iteration 1 -- Warning: ftruncate() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: ftruncate() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: ftruncate() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: ftruncate() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: ftruncate() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: ftruncate() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing ftruncate() with closed/unset file handle -- Warning: ftruncate(): %d is not a valid stream resource in %s on line %d @@ -119,6 +125,7 @@ bool(false) int(36) Warning: ftruncate() expects parameter 1 to be resource, null given in %s on line %d -NULL -int(36) +bool(false) +int(0) Done + diff --git a/ext/standard/tests/file/fwrite_error.phpt b/ext/standard/tests/file/fwrite_error.phpt index 6b78fcd5bd..555d31a095 100644 --- a/ext/standard/tests/file/fwrite_error.phpt +++ b/ext/standard/tests/file/fwrite_error.phpt @@ -1,5 +1,7 @@ --TEST-- -Test fwrite() function : error conditions (Bug #42057) +Test fwrite() function : error conditions +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) --FILE-- <?php /* @@ -34,7 +36,7 @@ echo "-- Testing fwrite() with invalid length arguments --\n"; $len = 0; var_dump( fwrite($file_handle, $data, $len) ); $len = -10; -var_dump( fwrite($file_handle, (binary)$data, $len) ); +var_dump( fwrite($file_handle, $data, $len) ); // test invalid arguments : non-resources echo "-- Testing fwrite() with invalid arguments --\n"; @@ -74,14 +76,14 @@ unlink( $filename ); -- Testing fwrite() with less than expected number of arguments -- Warning: fwrite() expects at least 2 parameters, 0 given in %s on line %d -NULL +bool(false) Warning: fwrite() expects at least 2 parameters, 1 given in %s on line %d -NULL +bool(false) -- Testing fwrite() with more than expected number of arguments -- Warning: fwrite() expects at most 3 parameters, 4 given in %s on line %d -NULL +bool(false) -- Testing fwrite() with invalid length arguments -- int(0) int(0) @@ -89,32 +91,33 @@ int(0) -- Iteration 1 -- Warning: fwrite() expects parameter 1 to be resource, Unicode string given in %s on line %d -NULL +bool(false) -- Iteration 2 -- Warning: fwrite() expects parameter 1 to be resource, integer given in %s on line %d -NULL +bool(false) -- Iteration 3 -- Warning: fwrite() expects parameter 1 to be resource, double given in %s on line %d -NULL +bool(false) -- Iteration 4 -- Warning: fwrite() expects parameter 1 to be resource, boolean given in %s on line %d -NULL +bool(false) -- Iteration 5 -- Warning: fwrite() expects parameter 1 to be resource, array given in %s on line %d -NULL +bool(false) -- Iteration 6 -- Warning: fwrite() expects parameter 1 to be resource, object given in %s on line %d -NULL +bool(false) -- Testing fwrite() with closed/unset file handle -- -Warning: fwrite(): 6 is not a valid stream resource in %s on line %d +Warning: fwrite(): %d is not a valid stream resource in %s on line %d bool(false) Warning: fwrite() expects parameter 1 to be resource, null given in %s on line %d -NULL +bool(false) Done + diff --git a/ext/standard/tests/file/fwrite_variation5.phpt b/ext/standard/tests/file/fwrite_variation5.phpt new file mode 100644 index 0000000000..c0628b0b24 --- /dev/null +++ b/ext/standard/tests/file/fwrite_variation5.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test fwrite() function : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int fwrite(resource fp, string str [, int length]) + * Description: Binary-safe file write + * Source code: ext/standard/file.c + * Alias to functions: bzwrite fputs gzwrite + */ + +echo "*** Testing fwrite() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +$filename = 'fwriteVar5.tmp'; + + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for str + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $fp = fopen($filename,'w'); + fwrite($fp, $value); + fclose($fp); + readfile($filename); +}; +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing fwrite() : usage variation *** + +--int 0-- +0 +--int 1-- +1 +--int 12345-- +12345 +--int -12345-- +-2345 +--float 10.5-- +10.5 +--float -10.5-- +-10.5 +--float 12.3456789000e10-- +123456789000 +--float -12.3456789000e10-- +-123456789000 +--float .5-- +0.5 +--empty array-- +Error: 8 - Array to string conversion, %s(%d) +Array +--int indexed array-- +Error: 8 - Array to string conversion, %s(%d) +Array +--associative array-- +Error: 8 - Array to string conversion, %s(%d) +Array +--nested arrays-- +Error: 8 - Array to string conversion, %s(%d) +Array +--uppercase NULL-- + +--lowercase null-- + +--lowercase true-- +1 +--lowercase false-- + +--uppercase TRUE-- +1 +--uppercase FALSE-- + +--empty string DQ-- + +--empty string SQ-- + +--instance of classWithToString-- +Class A object +--instance of classWithoutToString-- +Error: 4096 - Object of class classWithoutToString could not be converted to binary string, %s(%d) +Error: 8 - Object of class classWithoutToString to string conversion, %s(%d) +Object +--undefined var-- + +--unset var-- +===DONE=== + diff --git a/ext/standard/tests/file/glob_basic.phpt b/ext/standard/tests/file/glob_basic.phpt index 3a7d9c5fd2..b96bd79be7 100755 --- a/ext/standard/tests/file/glob_basic.phpt +++ b/ext/standard/tests/file/glob_basic.phpt @@ -25,14 +25,19 @@ $fp = fopen("$dirname/file.text", "w"); fclose($fp); // glob() with default arguments -var_dump( glob($dirname."/*") ); -var_dump( glob($dirname."/*.txt") ); -var_dump( glob($dirname."/*.t?t") ); -var_dump( glob($dirname."/*.t*t") ); -var_dump( glob($dirname."/*.?") ); -var_dump( glob($dirname."/*.*") ); +sort_var_dump( glob($dirname."/*") ); +sort_var_dump( glob($dirname."/*.txt") ); +sort_var_dump( glob($dirname."/*.t?t") ); +sort_var_dump( glob($dirname."/*.t*t") ); +sort_var_dump( glob($dirname."/*.?") ); +sort_var_dump( glob($dirname."/*.*") ); echo "Done\n"; + +function sort_var_dump($results) { + sort($results); + var_dump($results); +} ?> --CLEAN-- <?php diff --git a/ext/standard/tests/file/glob_error_002-win32.phpt b/ext/standard/tests/file/glob_error_002-win32.phpt new file mode 100644 index 0000000000..a61efd108c --- /dev/null +++ b/ext/standard/tests/file/glob_error_002-win32.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test glob() function: error condition - pattern too long. +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: array glob ( string $pattern [, int $flags] ); + Description: Find pathnames matching a pattern +*/ + +echo "*** Testing glob() : error condition - pattern too long. ***\n"; + +var_dump(glob(str_repeat('x', 3000))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing glob() : error condition - pattern too long. *** + +Warning: glob(): Pattern exceeds the maximum allowed length of %d characters in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/file/glob_error_002.phpt b/ext/standard/tests/file/glob_error_002.phpt new file mode 100644 index 0000000000..f5bad73694 --- /dev/null +++ b/ext/standard/tests/file/glob_error_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test glob() function: long pattern. +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: array glob ( string $pattern [, int $flags] ); + Description: Find pathnames matching a pattern +*/ + +echo "*** Testing glob() : long pattern. ***\n"; + +var_dump(glob(str_repeat('x', 3000))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing glob() : long pattern. *** +array(0) { +} +Done + diff --git a/ext/standard/tests/file/is_dir_variation2.phpt b/ext/standard/tests/file/is_dir_variation2.phpt index 022e06bb40..8817256793 100644 --- a/ext/standard/tests/file/is_dir_variation2.phpt +++ b/ext/standard/tests/file/is_dir_variation2.phpt @@ -14,7 +14,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { /* Testing is_dir() with dir, soft & hard link to dir, and with file, soft & hard link to file */ - + $file_path = dirname(__FILE__); echo "*** Testing is_dir() with dir and links to dir ***\n"; @@ -70,7 +70,7 @@ bool(true) -- With symlink -- bool(true) -- With hardlink -- -Warning: link(): %s in %s on line %d +Warning: link(): %s bool(false) *** Testing is_dir() with file and links to a file *** diff --git a/ext/standard/tests/file/is_dir_variation3.phpt b/ext/standard/tests/file/is_dir_variation3.phpt index eab2cdc702..6453868a79 100644 --- a/ext/standard/tests/file/is_dir_variation3.phpt +++ b/ext/standard/tests/file/is_dir_variation3.phpt @@ -1,5 +1,5 @@ --TEST-- -Test is_dir() function: usage variations - invalid arguments +Test is_dir() function: usage variations - invalid arguments --FILE-- <?php /* Prototype: bool is_dir ( string $dirname ); @@ -18,9 +18,10 @@ $dirnames = array( TRUE, FALSE, NULL, + " ", $dir_handle, - /* Non-existing dirnames */ + /* scalars */ 0, 1234 ); @@ -39,6 +40,7 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) Warning: is_dir() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d NULL @@ -46,3 +48,4 @@ bool(false) bool(false) *** Done *** + diff --git a/ext/standard/tests/file/is_executable_variation3.phpt b/ext/standard/tests/file/is_executable_variation3.phpt index 82853d2cf6..df349644da 100644 --- a/ext/standard/tests/file/is_executable_variation3.phpt +++ b/ext/standard/tests/file/is_executable_variation3.phpt @@ -5,6 +5,16 @@ Test is_executable() function: usage variations - invalid file names if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for windows'); } +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__)."/is_executable_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip cannot be run as root'); +} + +unlink($filename); ?> --FILE-- <?php @@ -27,6 +37,7 @@ $invalid_files = array( TRUE, FALSE, NULL, + " ", @array(), @$file_handle ); @@ -49,8 +60,10 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) Warning: is_executable() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d NULL bool(false) Done + diff --git a/ext/standard/tests/file/is_file_variation3.phpt b/ext/standard/tests/file/is_file_variation3.phpt index b97ea3143e..0bf43cf19e 100644 --- a/ext/standard/tests/file/is_file_variation3.phpt +++ b/ext/standard/tests/file/is_file_variation3.phpt @@ -1,5 +1,5 @@ --TEST-- -Test is_file() function: usage variations - invalid arguments +Test is_file() function: usage variations - invalid filenames --FILE-- <?php /* Prototype: bool is_file ( string $filename ); @@ -16,17 +16,18 @@ echo "*** Testing Invalid file types ***\n"; $filenames = array( /* Invalid filenames */ -2.34555, + " ", "", TRUE, FALSE, NULL, $file_handle, - + /* scalars */ 1234, 0 ); - + /* loop through to test each element the above array */ foreach( $filenames as $filename ) { var_dump( is_file($filename) ); @@ -48,6 +49,7 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) Warning: is_file() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d NULL @@ -55,3 +57,4 @@ bool(false) bool(false) *** Done *** + diff --git a/ext/standard/tests/file/is_file_variation4.phpt b/ext/standard/tests/file/is_file_variation4.phpt index 1030349fc2..55aeedfaad 100644 --- a/ext/standard/tests/file/is_file_variation4.phpt +++ b/ext/standard/tests/file/is_file_variation4.phpt @@ -1,5 +1,5 @@ --TEST-- -Test is_file() function: usage variations - diff. path notations (Bug #42027, #42638) +Test is_file() function: usage variations - diff. path notations (Bug #42027) --FILE-- <?php /* Prototype: bool is_file ( string $filename ); @@ -52,7 +52,7 @@ $dir_name = $file_path."/is_file_variation4"; unlink($dir_name."/is_file_variation4.tmp"); rmdir($dir_name); ?> ---EXPECT-- +--EXPECTF-- *** Testing is_file() with different notations of file names *** - Iteration 1 - bool(true) diff --git a/ext/standard/tests/file/is_readable_variation1.phpt b/ext/standard/tests/file/is_readable_variation1.phpt index 76eafd0b5a..a1310327b8 100644 --- a/ext/standard/tests/file/is_readable_variation1.phpt +++ b/ext/standard/tests/file/is_readable_variation1.phpt @@ -2,8 +2,16 @@ Test is_readable() function: usage variations - diff. file notations --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip not for windows'); +if (substr(PHP_OS, 0, 3) != 'WIN') { + // Skip if being run by root (files are always readable, writeable and executable) + $filename = dirname(__FILE__)."/is_readable_root_check.tmp"; + $fp = fopen($filename, 'w'); + fclose($fp); + if(fileowner($filename) == 0) { + unlink ($filename); + die('skip cannot be run as root'); + } + unlink($filename); } ?> --FILE-- diff --git a/ext/standard/tests/file/is_readable_variation3.phpt b/ext/standard/tests/file/is_readable_variation3.phpt index 35691b88d0..40d88a0202 100644 --- a/ext/standard/tests/file/is_readable_variation3.phpt +++ b/ext/standard/tests/file/is_readable_variation3.phpt @@ -2,8 +2,17 @@ Test is_readable() function: usage variations - invalid file names --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip not for windows'); +if (substr(PHP_OS, 0, 3) != 'WIN') { + + // Skip if being run by root (files are always readable, writeable and executable) + $filename = dirname(__FILE__)."/is_readable_root_check.tmp"; + $fp = fopen($filename, 'w'); + fclose($fp); + if(fileowner($filename) == 0) { + unlink ($filename); + die('skip cannot be run as root'); + } + unlink($filename); } ?> --FILE-- @@ -27,6 +36,7 @@ $misc_files = array( TRUE, FALSE, NULL, + " ", @array(), @$file_handle ); @@ -49,8 +59,10 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) Warning: is_readable() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d NULL bool(false) Done + diff --git a/ext/standard/tests/file/is_uploaded_file_basic.phpt b/ext/standard/tests/file/is_uploaded_file_basic.phpt new file mode 100644 index 0000000000..355125e830 --- /dev/null +++ b/ext/standard/tests/file/is_uploaded_file_basic.phpt @@ -0,0 +1,50 @@ +--TEST-- +is_uploaded_file() function +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php if (php_sapi_name()=='cli') die('skip'); ?> +--POST_RAW-- +Content-type: multipart/form-data, boundary=AaB03x + +--AaB03x +content-disposition: form-data; name="field1" + +Joe Blow +--AaB03x +content-disposition: form-data; name="pics"; filename="file1.txt" +Content-Type: text/plain + +abcdef123456789 +--AaB03x-- +--FILE-- +<?php +// uploaded file +var_dump(is_uploaded_file($_FILES['pics']['tmp_name'])); + +// not an uploaded file +var_dump(is_uploaded_file($_FILES['pics']['name'])); + +// not an uploaded file +var_dump(is_uploaded_file('random_filename.txt')); + +// not an uploaded file +var_dump(is_uploaded_file('__FILE__')); + +// Error cases +var_dump(is_uploaded_file()); +var_dump(is_uploaded_file('a', 'b')); + +?> +--EXPECTF-- +bool(true) +bool(false) +bool(false) +bool(false) + +Warning: is_uploaded_file() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: is_uploaded_file() expects exactly 1 parameter, 2 given in %s on line %d +NULL + diff --git a/ext/standard/tests/file/is_writable_variation1.phpt b/ext/standard/tests/file/is_writable_variation1.phpt index 97232b4320..bf3e7e1171 100644 --- a/ext/standard/tests/file/is_writable_variation1.phpt +++ b/ext/standard/tests/file/is_writable_variation1.phpt @@ -2,8 +2,18 @@ Test is_writable() and its alias is_writeable() function: usage variations - diff. path notations --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip.. only on LINUX'); +if (substr(PHP_OS, 0, 3) != 'WIN') { + + // Skip if being run by root (files are always readable, writeable and executable) + $filename = dirname(__FILE__)."/is_writable_root_check.tmp"; + $fp = fopen($filename, 'w'); + fclose($fp); + if(fileowner($filename) == 0) { + unlink ($filename); + die('skip cannot be run as root'); + } + + unlink($filename); } ?> --FILE-- @@ -100,4 +110,4 @@ bool(true) -- Iteration 11 -- bool(true) bool(true) -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/is_writable_variation3.phpt b/ext/standard/tests/file/is_writable_variation3.phpt index eae552fea2..d781fa4917 100644 --- a/ext/standard/tests/file/is_writable_variation3.phpt +++ b/ext/standard/tests/file/is_writable_variation3.phpt @@ -2,8 +2,16 @@ Test is_writable() and its alias is_writeable() function: usage variations - invalid file names --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip.. only on LINUX'); +if (substr(PHP_OS, 0, 3) != 'WIN') { + // Skip if being run by root (files are always readable, writeable and executable) + $filename = dirname(__FILE__)."/is_writable_root_check.tmp"; + $fp = fopen($filename, 'w'); + fclose($fp); + if(fileowner($filename) == 0) { + unlink ($filename); + die('skip cannot be run as root'); + } + unlink($filename); } ?> --FILE-- @@ -26,6 +34,7 @@ $misc_files = array( TRUE, FALSE, NULL, + " ", @array(), @$file_handle ); @@ -55,6 +64,8 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) +bool(false) Warning: is_writable() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d NULL @@ -64,3 +75,4 @@ NULL bool(false) bool(false) Done + diff --git a/ext/standard/tests/file/lstat_stat_variation2.phpt b/ext/standard/tests/file/lstat_stat_variation2.phpt index 73ab385120..e7d704a20b 100755 --- a/ext/standard/tests/file/lstat_stat_variation2.phpt +++ b/ext/standard/tests/file/lstat_stat_variation2.phpt @@ -21,13 +21,12 @@ $file_path = dirname(__FILE__); require("file.inc"); /* create temp directory */ -@rmdir("$file_path/lstat_stat_variation2/"); //ensure that dir doesn't exists -mkdir("$file_path/lstat_stat_variation2/"); // temp dir +mkdir("$file_path/lstat_stat_variation1/"); // temp dir // renaming a directory and check stat echo "*** Testing stat() for directory after being renamed ***\n"; -$old_dirname = "$file_path/lstat_stat_variation2"; -$new_dirname = "$file_path/lstat_stat_variation2a"; +$old_dirname = "$file_path/lstat_stat_variation1"; +$new_dirname = "$file_path/lstat_stat_variation1a"; $old_stat = stat($old_dirname); clearstatcache(); var_dump( rename($old_dirname, $new_dirname) ); @@ -37,8 +36,11 @@ $new_stat = stat($new_dirname); var_dump( compare_self_stat($old_stat) ); var_dump( compare_self_stat($new_stat) ); -// compare the two stats -var_dump( compare_stats($old_stat, $new_stat, $all_stat_keys) ); +// compare the two stats - all except ctime +$keys_to_compare = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, + "dev", "ino", "mode", "nlink", "uid", "gid", + "rdev", "size", "atime", "mtime", "blksize", "blocks"); +var_dump( compare_stats($old_stat, $new_stat, $keys_to_compare) ); // clear the cache clearstatcache(); @@ -48,9 +50,9 @@ echo "\n--- Done ---"; --CLEAN-- <?php $file_path = dirname(__FILE__); -rmdir("$file_path/lstat_stat_variation2a"); +rmdir("$file_path/lstat_stat_variation1a"); ?> ---EXPECT-- +--EXPECTF-- *** Testing stat() for directory after being renamed *** bool(true) bool(true) diff --git a/ext/standard/tests/file/lstat_stat_variation22.phpt b/ext/standard/tests/file/lstat_stat_variation22.phpt new file mode 100644 index 0000000000..c9072ce013 --- /dev/null +++ b/ext/standard/tests/file/lstat_stat_variation22.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test lstat() and stat() functions: usage variations - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype: array lstat ( string $filename ); + Description: Gives information about a file or symbolic link + + Prototype: array stat ( string $filename ); + Description: Gives information about a file +*/ +echo "*** testing stat ***\n"; +var_dump(stat(NULL)); +var_dump(stat(false)); +var_dump(stat('')); +var_dump(stat(' ')); +var_dump(stat('|')); + +echo "*** testing lstat ***\n"; +var_dump(lstat(NULL)); +var_dump(lstat(false)); +var_dump(lstat('')); +var_dump(lstat(' ')); +var_dump(lstat('|')); +echo "Done"; +?> +--EXPECTF-- +*** testing stat *** +bool(false) +bool(false) +bool(false) + +Warning: stat(): stat failed for in %s on line %d +bool(false) + +Warning: stat(): stat failed for | in %s on line %d +bool(false) +*** testing lstat *** +bool(false) +bool(false) +bool(false) + +Warning: lstat(): Lstat failed for in %s on line %d +bool(false) + +Warning: lstat(): Lstat failed for | in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/mkdir_variation1-win32.phpt b/ext/standard/tests/file/mkdir_variation1-win32.phpt new file mode 100644 index 0000000000..507a97b4ee --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation1-win32.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test mkdir() function : usage variation: try invalid pathname +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--XFAIL-- +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase false' =>false, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // other + // php.net bug outputs message File Exists + 'single space' => ' ', +); + +// loop through each element of the array for pathname + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $res = mkdir($value); + if ($res == true) { + echo "directory created\n"; + rmdir($value); + } +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : usage variation *** + +--uppercase NULL-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--lowercase null-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--lowercase false-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--uppercase FALSE-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--empty string DQ-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--empty string SQ-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--undefined var-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--unset var-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--single space-- +Error: 2 - mkdir(): %s, %s(%d) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/mkdir_variation1.phpt b/ext/standard/tests/file/mkdir_variation1.phpt new file mode 100644 index 0000000000..e8c500661c --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation1.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test mkdir() function : usage variation: try invalid pathname +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--XFAIL-- +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase false' =>false, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // other + 'single space' => ' ', +); + +// loop through each element of the array for pathname + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $res = mkdir($value); + if ($res == true) { + echo "directory created\n"; + rmdir($value); + } +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : usage variation *** + +--uppercase NULL-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--lowercase null-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--lowercase false-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--uppercase FALSE-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--empty string DQ-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--empty string SQ-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--undefined var-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--unset var-- +Error: 2 - mkdir(): No such file or directory, %s(%d) + +--single space-- +directory created +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/mkdir_variation2.phpt b/ext/standard/tests/file/mkdir_variation2.phpt new file mode 100644 index 0000000000..48a70b3089 --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation2.phpt @@ -0,0 +1,189 @@ +--TEST-- +Test mkdir() function : usage variation: different types for mode +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$pathname = 'mkdirVar2.tmp'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for mode + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $h = mkdir($pathname, $value); + if ($h === true) { + echo "Directory created\n"; + rmdir($pathname); + } +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : usage variation *** + +--float 10.5-- +Directory created + +--float -10.5-- +Directory created + +--float 12.3456789000e10-- +Directory created + +--float -12.3456789000e10-- +Directory created + +--float .5-- +Directory created + +--empty array-- +Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d) + +--int indexed array-- +Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d) + +--associative array-- +Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d) + +--nested arrays-- +Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d) + +--uppercase NULL-- +Directory created + +--lowercase null-- +Directory created + +--lowercase true-- +Directory created + +--lowercase false-- +Directory created + +--uppercase TRUE-- +Directory created + +--uppercase FALSE-- +Directory created + +--empty string DQ-- +Error: 2 - mkdir() expects parameter 2 to be long, Unicode string given, %s(%d) + +--empty string SQ-- +Error: 2 - mkdir() expects parameter 2 to be long, Unicode string given, %s(%d) + +--string DQ-- +Error: 2 - mkdir() expects parameter 2 to be long, Unicode string given, %s(%d) + +--string SQ-- +Error: 2 - mkdir() expects parameter 2 to be long, Unicode string given, %s(%d) + +--mixed case string-- +Error: 2 - mkdir() expects parameter 2 to be long, Unicode string given, %s(%d) + +--heredoc-- +Error: 2 - mkdir() expects parameter 2 to be long, Unicode string given, %s(%d) + +--instance of classWithToString-- +Error: 2 - mkdir() expects parameter 2 to be long, object given, %s(%d) + +--instance of classWithoutToString-- +Error: 2 - mkdir() expects parameter 2 to be long, object given, %s(%d) + +--undefined var-- +Directory created + +--unset var-- +Directory created +===DONE=== diff --git a/ext/standard/tests/file/mkdir_variation3.phpt b/ext/standard/tests/file/mkdir_variation3.phpt new file mode 100644 index 0000000000..7622e5f612 --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation3.phpt @@ -0,0 +1,208 @@ +--TEST-- +Test mkdir() function : usage variation: different types for recursive +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$pathname = 'mkdirVar3.tmp'; +$mode = 0777; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for recursive + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $h = mkdir($pathname, $mode, $value); + if ($h === true) { + echo "Directory created\n"; + rmdir($pathname); + } +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : usage variation *** + +--int 0-- +Directory created + +--int 1-- +Directory created + +--int 12345-- +Directory created + +--int -12345-- +Directory created + +--float 10.5-- +Directory created + +--float -10.5-- +Directory created + +--float 12.3456789000e10-- +Directory created + +--float -12.3456789000e10-- +Directory created + +--float .5-- +Directory created + +--empty array-- +Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d) + +--int indexed array-- +Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d) + +--associative array-- +Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d) + +--nested arrays-- +Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d) + +--uppercase NULL-- +Directory created + +--lowercase null-- +Directory created + +--lowercase true-- +Directory created + +--lowercase false-- +Directory created + +--uppercase TRUE-- +Directory created + +--uppercase FALSE-- +Directory created + +--empty string DQ-- +Directory created + +--empty string SQ-- +Directory created + +--string DQ-- +Directory created + +--string SQ-- +Directory created + +--mixed case string-- +Directory created + +--heredoc-- +Directory created + +--instance of classWithToString-- +Error: 2 - mkdir() expects parameter 3 to be boolean, object given, %s(%d) + +--instance of classWithoutToString-- +Error: 2 - mkdir() expects parameter 3 to be boolean, object given, %s(%d) + +--undefined var-- +Directory created + +--unset var-- +Directory created +===DONE=== diff --git a/ext/standard/tests/file/mkdir_variation4.phpt b/ext/standard/tests/file/mkdir_variation4.phpt new file mode 100644 index 0000000000..8ed906a228 --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation4.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test mkdir() function : usage variation: different types for context +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$pathname = 'mkdirVar4.tmp'; +$mode = 0777; +$recursive = false; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +$fileRes = fopen(__FILE__,'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // non stream context resource + 'file resource' => $fileRes, +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $h = mkdir($pathname, $mode, $recursive, $value); + if ($h === true) { + echo "Directory created\n"; + rmdir($pathname); + } +}; + +fclose($fileRes); + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : usage variation *** + +--int 0-- +Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) + +--int 1-- +Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) + +--int 12345-- +Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) + +--int -12345-- +Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) + +--float 10.5-- +Error: 2 - mkdir() expects parameter 4 to be resource, double given, %s(%d) + +--float -10.5-- +Error: 2 - mkdir() expects parameter 4 to be resource, double given, %s(%d) + +--float 12.3456789000e10-- +Error: 2 - mkdir() expects parameter 4 to be resource, double given, %s(%d) + +--float -12.3456789000e10-- +Error: 2 - mkdir() expects parameter 4 to be resource, double given, %s(%d) + +--float .5-- +Error: 2 - mkdir() expects parameter 4 to be resource, double given, %s(%d) + +--empty array-- +Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) + +--int indexed array-- +Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) + +--associative array-- +Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) + +--nested arrays-- +Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) + +--uppercase NULL-- +Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) + +--lowercase null-- +Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) + +--lowercase true-- +Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) + +--lowercase false-- +Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) + +--uppercase TRUE-- +Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) + +--uppercase FALSE-- +Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) + +--empty string DQ-- +Error: 2 - mkdir() expects parameter 4 to be resource, Unicode string given, %s(%d) + +--empty string SQ-- +Error: 2 - mkdir() expects parameter 4 to be resource, Unicode string given, %s(%d) + +--string DQ-- +Error: 2 - mkdir() expects parameter 4 to be resource, Unicode string given, %s(%d) + +--string SQ-- +Error: 2 - mkdir() expects parameter 4 to be resource, Unicode string given, %s(%d) + +--mixed case string-- +Error: 2 - mkdir() expects parameter 4 to be resource, Unicode string given, %s(%d) + +--heredoc-- +Error: 2 - mkdir() expects parameter 4 to be resource, Unicode string given, %s(%d) + +--instance of classWithToString-- +Error: 2 - mkdir() expects parameter 4 to be resource, object given, %s(%d) + +--instance of classWithoutToString-- +Error: 2 - mkdir() expects parameter 4 to be resource, object given, %s(%d) + +--undefined var-- +Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) + +--unset var-- +Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) + +--file resource-- +Error: 2 - mkdir(): supplied resource is not a valid Stream-Context resource, %s(%d) +Directory created +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/mkdir_variation5-win32.phpt b/ext/standard/tests/file/mkdir_variation5-win32.phpt new file mode 100644 index 0000000000..d93f6c6a9b --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation5-win32.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test mkdir() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--XFAIL-- +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : variation ***\n"; + +$workDir = "mkdirVar5.tmp"; +$subDir = "aSubDir"; +mkdir($workDir); +$cwd = getcwd(); + +$unixifiedDir = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$subDir, 3); + +$dirs = array( + // relative + $workDir.'\\'.$subDir, + '.\\'.$workDir.'\\'.$subDir, + $workDir.'\\..\\'.$workDir.'\\'.$subDir, + + // relative bad path + $workDir.'\\..\\BADDIR\\'.$subDir, + 'BADDIR\\'.$subDir, + + //absolute + $cwd.'\\'.$workDir.'\\'.$subDir, + $cwd.'\\.\\'.$workDir.'\\'.$subDir, + $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$subDir, + + //absolute bad path + $cwd.'\\BADDIR\\'.$subDir, + + //trailing separators + $workDir.'\\'.$subDir.'\\', + $cwd.'\\'.$workDir.'\\'.$subDir.'\\', + + // multiple separators + $workDir.'\\\\'.$subDir, + $cwd.'\\\\'.$workDir.'\\\\'.$subDir, + + // Unixified Dir + $unixifiedDir, + + ); + + +foreach($dirs as $dir) { + echo "-- creating $dir --\n"; + $res = mkdir($dir); + if ($res === true) { + echo "Directory created\n"; + rmdir($workDir.'\\'.$subDir); + } +} + +rmdir($workDir); + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : variation *** +-- creating mkdirVar5.tmp\aSubDir -- +Directory created +-- creating .\mkdirVar5.tmp\aSubDir -- +Directory created +-- creating mkdirVar5.tmp\..\mkdirVar5.tmp\aSubDir -- +Directory created +-- creating mkdirVar5.tmp\..\BADDIR\aSubDir -- + +Warning: mkdir(): No such file or directory in %s on line %d +-- creating BADDIR\aSubDir -- + +Warning: mkdir(): No such file or directory in %s on line %d +-- creating %s\mkdirVar5.tmp\aSubDir -- +Directory created +-- creating %s\.\mkdirVar5.tmp\aSubDir -- +Directory created +-- creating %s\mkdirVar5.tmp\..\mkdirVar5.tmp\aSubDir -- +Directory created +-- creating %s\BADDIR\aSubDir -- + +Warning: mkdir(): No such file or directory in %s on line %d +-- creating mkdirVar5.tmp\aSubDir\ -- +Directory created +-- creating %s\mkdirVar5.tmp\aSubDir\ -- +Directory created +-- creating mkdirVar5.tmp\\aSubDir -- +Directory created +-- creating %s\\mkdirVar5.tmp\\aSubDir -- +Directory created +-- creating /%s/mkdirVar5.tmp/aSubDir -- +Directory created +===DONE=== diff --git a/ext/standard/tests/file/mkdir_variation5.phpt b/ext/standard/tests/file/mkdir_variation5.phpt new file mode 100644 index 0000000000..51fb8260c1 --- /dev/null +++ b/ext/standard/tests/file/mkdir_variation5.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test mkdir() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--XFAIL-- +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) + * Description: Create a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing mkdir() : variation ***\n"; + +$workDir = "mkdirVar5.tmp"; +$subDir = "aSubDir"; +mkdir($workDir); +$cwd = getcwd(); + +$dirs = array( + // relative + $workDir.'/'.$subDir, + './'.$workDir.'/'.$subDir, + $workDir.'/../'.$workDir.'/'.$subDir, + + // relative bad path + $workDir.'/../BADDIR/'.$subDir, + 'BADDIR/'.$subDir, + + //absolute + $cwd.'/'.$workDir.'/'.$subDir, + $cwd.'/./'.$workDir.'/'.$subDir, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDir, + + //absolute bad path + $cwd.'/BADDIR/'.$subDir, + + //trailing separators + $workDir.'/'.$subDir.'/', + $cwd.'/'.$workDir.'/'.$subDir.'/', + + // multiple separators + $workDir.'//'.$subDir, + $cwd.'//'.$workDir.'//'.$subDir, + + ); + + +foreach($dirs as $dir) { + echo "-- creating $dir --\n"; + $res = mkdir($dir); + if ($res === true) { + echo "Directory created\n"; + rmdir($dir); + } +} + +rmdir($workDir); + +?> +===DONE=== +--EXPECTF-- +*** Testing mkdir() : variation *** +-- creating mkdirVar5.tmp/aSubDir -- +Directory created +-- creating ./mkdirVar5.tmp/aSubDir -- +Directory created +-- creating mkdirVar5.tmp/../mkdirVar5.tmp/aSubDir -- +Directory created +-- creating mkdirVar5.tmp/../BADDIR/aSubDir -- + +Warning: mkdir(): No such file or directory in %s on line %d +-- creating BADDIR/aSubDir -- + +Warning: mkdir(): No such file or directory in %s on line %d +-- creating %s/mkdirVar5.tmp/aSubDir -- +Directory created +-- creating %s/./mkdirVar5.tmp/aSubDir -- +Directory created +-- creating %s/mkdirVar5.tmp/../mkdirVar5.tmp/aSubDir -- +Directory created +-- creating %s/BADDIR/aSubDir -- + +Warning: mkdir(): No such file or directory in %s on line %d +-- creating mkdirVar5.tmp/aSubDir/ -- +Directory created +-- creating %s/mkdirVar5.tmp/aSubDir/ -- +Directory created +-- creating mkdirVar5.tmp//aSubDir -- +Directory created +-- creating %s//mkdirVar5.tmp//aSubDir -- +Directory created +===DONE=== diff --git a/ext/standard/tests/file/move_uploaded_file_basic.phpt b/ext/standard/tests/file/move_uploaded_file_basic.phpt new file mode 100644 index 0000000000..f008304f35 --- /dev/null +++ b/ext/standard/tests/file/move_uploaded_file_basic.phpt @@ -0,0 +1,78 @@ +--TEST-- +move_uploaded_file() function +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php if (php_sapi_name()=='cli') die('skip'); ?> +--POST_RAW-- +Content-type: multipart/form-data, boundary=AaB03x + +--AaB03x +content-disposition: form-data; name="field1" + +Joe Blow +--AaB03x +content-disposition: form-data; name="file1"; filename="file1.txt" +Content-Type: text/plain + +abcdef123456789xxxDDDxxxDDDxxxDDD +--AaB03x +content-disposition: form-data; name="file2"; filename="file2.txt" +Content-Type: text/plain + +abcdef123456789 +--AaB03x-- +--FILE-- +<?php + +echo "Valid move\n"; +$destination1 = __FILE__ . ".tmp"; + +var_dump(move_uploaded_file($_FILES['file1']['tmp_name'], $destination1)); +$file_contents = file_get_contents($destination1); +$contents_matches = ($file_contents == b"abcdef123456789xxxDDDxxxDDDxxxDDD"); +var_dump($contents_matches); +unlink($destination1); +echo "\n"; + +echo "Original name of uploaded file\n"; +$destination2 = __FILE__ . ".tmp2"; +var_dump(move_uploaded_file($_FILES['file1']['name'], $destination2)); + +echo "Non-uploaded source file\n"; +$source = __FILE__; +$destination3 = __FILE__ . ".tmp3"; +var_dump(move_uploaded_file($source, $destination3)); + +echo "Valid move to existing file\n"; +$destination4 = __FILE__ . ".tmp4"; +$fd = fopen($destination4, "w"); +fclose($fd); +var_dump(move_uploaded_file($_FILES['file2']['tmp_name'], $destination4)); +unlink($destination4); + +echo "Wrong parameters\n"; +var_dump(move_uploaded_file()); +var_dump(move_uploaded_file(1, 2, 3)); + + +?> +--EXPECTF-- +Valid move +bool(true) +bool(true) + +Original name of uploaded file +bool(false) +Non-uploaded source file +bool(false) +Valid move to existing file +bool(true) +Wrong parameters + +Warning: move_uploaded_file() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +Warning: move_uploaded_file() expects exactly 2 parameters, 3 given in %s on line %d +NULL + diff --git a/ext/standard/tests/file/parse_ini_file_variation1.phpt b/ext/standard/tests/file/parse_ini_file_variation1.phpt new file mode 100644 index 0000000000..fafc5af37c --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation1.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test parse_ini_file() function : variation: identical properties and values are not referenced. +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : variation ***\n"; +$output_file = __FILE__.".ini"; +$iniFile = <<<FILE +[section1] +value1=original +value2=original +[section2] +value1=original +value2=different +FILE; + +file_put_contents($output_file, $iniFile); + +$a = parse_ini_file($output_file, true); +var_dump($a); +$a['section1']['value1'] = 'changed'; +var_dump($a); + +unlink($output_file); +?> +===DONE=== +--EXPECT-- +*** Testing parse_ini_file() : variation *** +array(2) { + [u"section1"]=> + array(2) { + [u"value1"]=> + unicode(8) "original" + [u"value2"]=> + unicode(8) "original" + } + [u"section2"]=> + array(2) { + [u"value1"]=> + unicode(8) "original" + [u"value2"]=> + unicode(9) "different" + } +} +array(2) { + [u"section1"]=> + array(2) { + [u"value1"]=> + unicode(7) "changed" + [u"value2"]=> + unicode(8) "original" + } + [u"section2"]=> + array(2) { + [u"value1"]=> + unicode(8) "original" + [u"value2"]=> + unicode(9) "different" + } +} +===DONE=== + diff --git a/ext/standard/tests/file/parse_ini_file_variation2.phpt b/ext/standard/tests/file/parse_ini_file_variation2.phpt new file mode 100644 index 0000000000..c60ece24a3 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation2.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test parse_ini_file() function : variation: handling different boolean values +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : variation ***\n"; +$output_file = __FILE__.".ini"; +$iniFile = <<<FILE +[section1] +value1=on +value2=off +[section2] +value1=true +value2=false +[section3] +value1=yes +value2=no +[section4] +value1=null +value2= + +[section5] +value1="on" +value2="off" +[section6] +value1="true" +value2="false" +[section7] +value1="yes" +value2="no" +[section8] +value1="null" +value2="" + +FILE; + +file_put_contents($output_file, $iniFile); + +$a = parse_ini_file($output_file, true); +var_dump($a); +unlink($output_file); +?> +===DONE=== +--EXPECT-- +*** Testing parse_ini_file() : variation *** +array(8) { + [u"section1"]=> + array(2) { + [u"value1"]=> + unicode(1) "1" + [u"value2"]=> + unicode(0) "" + } + [u"section2"]=> + array(2) { + [u"value1"]=> + unicode(1) "1" + [u"value2"]=> + unicode(0) "" + } + [u"section3"]=> + array(2) { + [u"value1"]=> + unicode(1) "1" + [u"value2"]=> + unicode(0) "" + } + [u"section4"]=> + array(2) { + [u"value1"]=> + unicode(0) "" + [u"value2"]=> + unicode(0) "" + } + [u"section5"]=> + array(2) { + [u"value1"]=> + unicode(2) "on" + [u"value2"]=> + unicode(3) "off" + } + [u"section6"]=> + array(2) { + [u"value1"]=> + unicode(4) "true" + [u"value2"]=> + unicode(5) "false" + } + [u"section7"]=> + array(2) { + [u"value1"]=> + unicode(3) "yes" + [u"value2"]=> + unicode(2) "no" + } + [u"section8"]=> + array(2) { + [u"value1"]=> + unicode(4) "null" + [u"value2"]=> + unicode(0) "" + } +} +===DONE=== + diff --git a/ext/standard/tests/file/parse_ini_file_variation3.phpt b/ext/standard/tests/file/parse_ini_file_variation3.phpt new file mode 100644 index 0000000000..2bd4fb1549 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation3.phpt @@ -0,0 +1,100 @@ +--TEST-- +Test parse_ini_file() function : variation: include path searching +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : variation ***\n"; +$pwd = getcwd(); +$f = basename(__FILE__); +$dir1 = $pwd."/".$f.".dir1"; +$dir2 = $pwd."/".$f.".dir2"; +$dir3 = $pwd."/".$f.".dir3"; +$iniFile = "php.ini"; + +$newdirs = array($dir1, $dir2, $dir3); +$pathSep = ":"; +$newIncludePath = ""; +if(substr(PHP_OS, 0, 3) == 'WIN' ) { + $pathSep = ";"; +} +foreach($newdirs as $newdir) { + mkdir($newdir); + $newIncludePath .= $newdir.$pathSep; +} + + +var_dump(parse_ini_file($iniFile)); +set_include_path($newIncludePath); +var_dump(parse_ini_file($iniFile)); + + +$output_file = $dir2."/".$iniFile; +$iniContent = <<<FILE +error_reporting = E_ALL +display_errors = On +display_startup_errors = Off +log_errors = Off +log_errors_max_len = 1024 +ignore_repeated_errors = Off +ignore_repeated_source = Off +report_memleaks = On +track_errors = Off +docref_root = "/phpmanual/" +docref_ext = .html + +FILE; + +file_put_contents($output_file, $iniContent); +var_dump(parse_ini_file($iniFile)); + +unlink($output_file); +foreach($newdirs as $newdir) { + rmdir($newdir); +} + + + + +?> +===DONE=== +--EXPECTF-- +*** Testing parse_ini_file() : variation *** + +Warning: parse_ini_file(php.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +Warning: parse_ini_file(php.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) +array(11) { + [u"error_reporting"]=> + unicode(%d) "%d" + [u"display_errors"]=> + unicode(1) "1" + [u"display_startup_errors"]=> + unicode(0) "" + [u"log_errors"]=> + unicode(0) "" + [u"log_errors_max_len"]=> + unicode(4) "1024" + [u"ignore_repeated_errors"]=> + unicode(0) "" + [u"ignore_repeated_source"]=> + unicode(0) "" + [u"report_memleaks"]=> + unicode(1) "1" + [u"track_errors"]=> + unicode(0) "" + [u"docref_root"]=> + unicode(11) "/phpmanual/" + [u"docref_ext"]=> + unicode(5) ".html" +} +===DONE=== + diff --git a/ext/standard/tests/file/parse_ini_file_variation4.phpt b/ext/standard/tests/file/parse_ini_file_variation4.phpt new file mode 100644 index 0000000000..0032c6a2d4 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation4.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test parse_ini_file() function : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$process_sections = false; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for filename + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( parse_ini_file($value, $process_sections) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing parse_ini_file() : usage variation *** + +--int 0-- +Error: 2 - parse_ini_file(0): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--int 1-- +Error: 2 - parse_ini_file(1): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - parse_ini_file(12345): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - parse_ini_file(-2345): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - parse_ini_file(10.5): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - parse_ini_file(-10.5): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - parse_ini_file(123456789000): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - parse_ini_file(-123456789000): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--float .5-- +Error: 2 - parse_ini_file(0.5): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--empty array-- +Error: 8 - Array to string conversion, %s(%d) +Error: 2 - parse_ini_file(Array): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--int indexed array-- +Error: 8 - Array to string conversion, %s(%d) +Error: 2 - parse_ini_file(Array): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--associative array-- +Error: 8 - Array to string conversion, %s(%d) +Error: 2 - parse_ini_file(Array): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--nested arrays-- +Error: 8 - Array to string conversion, %s(%d) +Error: 2 - parse_ini_file(Array): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - parse_ini_file(1): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - parse_ini_file(1): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - parse_ini_file(Class A object): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 4096 - Object of class classWithoutToString could not be converted to binary string, %s(%d) +Error: 8 - Object of class classWithoutToString to string conversion, %s(%d) +Error: 2 - parse_ini_file(Object): failed to open stream: No such file or directory, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) + +--unset var-- +Error: 2 - parse_ini_file(): Filename can not be empty!, %s(%d) +bool(false) +===DONE=== + diff --git a/ext/standard/tests/file/parse_ini_file_variation5.phpt b/ext/standard/tests/file/parse_ini_file_variation5.phpt new file mode 100644 index 0000000000..87a672d349 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation5.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test parse_ini_file() function : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = __FILE__."ParseIniFileVar5.ini"; +$contents = "a=test"; +@unlink($filename); +file_put_contents($filename, $contents); + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for process_sections + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( parse_ini_file($filename, $value) ); +}; + +unlink($filename); +?> +===DONE=== +--EXPECTF-- +*** Testing parse_ini_file() : usage variation *** + +--int 0-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--int 1-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--int 12345-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--int -12345-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--float 10.5-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--float -10.5-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--float 12.3456789000e10-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--float -12.3456789000e10-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--float .5-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--empty array-- +Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d) +bool(false) + +--uppercase NULL-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--lowercase null-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--empty string DQ-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--empty string SQ-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--string DQ-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--string SQ-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--mixed case string-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--heredoc-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--instance of classWithToString-- +Error: 2 - parse_ini_file() expects parameter 2 to be boolean, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - parse_ini_file() expects parameter 2 to be boolean, object given, %s(%d) +bool(false) + +--undefined var-- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +--unset var-- +array(1) { + [u"a"]=> + unicode(4) "test" +} +===DONE=== + diff --git a/ext/standard/tests/file/parse_ini_file_variation6-win32.phpt b/ext/standard/tests/file/parse_ini_file_variation6-win32.phpt new file mode 100644 index 0000000000..57922475d4 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation6-win32.phpt @@ -0,0 +1,146 @@ +--TEST-- +Test parse_ini_file() function : variation - various absolute and relative paths +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only run on Windows"); +?> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : variation ***\n"; +$mainDir = "parseIniFileVar6.dir"; +$subDir = "parseIniFileVar6Sub"; +$absMainDir = dirname(__FILE__)."\\".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."\\".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); +$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3); + +$allDirs = array( + // absolute paths + "$absSubDir\\", + "$absSubDir\\..\\".$subDir, + "$absSubDir\\\\..\\.\\".$subDir, + "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir, + "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir, + "$absSubDir\\BADDIR", + + // relative paths + $mainDir."\\".$subDir, + $mainDir."\\\\".$subDir, + $mainDir."\\\\\\".$subDir, + ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir, + "BADDIR", + + // unixifed path + $unixifiedDir, +); + +$filename = 'ParseIniFileVar6.ini'; +$content="a=test"; +$absFile = $absSubDir.'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, $content); +fclose($h); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + var_dump(parse_ini_file($dir."\\".$filename)); +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing parse_ini_file() : variation *** + +-- Iteration 1 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 2 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 3 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 4 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 5 -- + +Warning: parse_ini_file(%s\parseIniFileVar6.dir\parseIniFileVar6Sub\..\\\parseIniFileVar6Sub\\..\\..\parseIniFileVar6Sub\ParseIniFileVar6.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: parse_ini_file(%s\parseIniFileVar6.dir\parseIniFileVar6Sub\BADDIR\ParseIniFileVar6.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 8 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 9 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 10 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 11 -- + +Warning: parse_ini_file(BADDIR\ParseIniFileVar6.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 12 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +*** Done *** + diff --git a/ext/standard/tests/file/parse_ini_file_variation6.phpt b/ext/standard/tests/file/parse_ini_file_variation6.phpt new file mode 100644 index 0000000000..2659d1b69c --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_variation6.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test parse_ini_file() function : variation - various absolute and relative paths +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing parse_ini_file() : variation ***\n"; +$mainDir = "parseIniFileVar6.dir"; +$subDir = "parseIniFileVar6Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."/".$subDir; +mkdir($absSubDir); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + +$allDirs = array( + // absolute paths + "$absSubDir/", + "$absSubDir/../".$subDir, + "$absSubDir//.././".$subDir, + "$absSubDir/../../".$mainDir."/./".$subDir, + "$absSubDir/..///".$subDir."//..//../".$subDir, + "$absSubDir/BADDIR", + + // relative paths + $mainDir."/".$subDir, + $mainDir."//".$subDir, + $mainDir."///".$subDir, + "./".$mainDir."/../".$mainDir."/".$subDir, + "BADDIR", + +); + +$filename = 'ParseIniFileVar6.ini'; +$content="a=test"; +$absFile = $absSubDir.'/'.$filename; +$h = fopen($absFile,"w"); +fwrite($h, $content); +fclose($h); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + var_dump(parse_ini_file($dir."/".$filename)); +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing parse_ini_file() : variation *** + +-- Iteration 1 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 2 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 3 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 4 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 5 -- + +Warning: parse_ini_file(%s/parseIniFileVar6.dir/parseIniFileVar6Sub/..///parseIniFileVar6Sub//..//../parseIniFileVar6Sub/ParseIniFileVar6.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: parse_ini_file(%s/parseIniFileVar6.dir/parseIniFileVar6Sub/BADDIR/ParseIniFileVar6.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 8 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 9 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 10 -- +array(1) { + [u"a"]=> + unicode(4) "test" +} + +-- Iteration 11 -- + +Warning: parse_ini_file(BADDIR/ParseIniFileVar6.ini): failed to open stream: No such file or directory in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/pathinfo_basic1-win32.phpt b/ext/standard/tests/file/pathinfo_basic1-win32.phpt new file mode 100644 index 0000000000..a4ddec0fb7 --- /dev/null +++ b/ext/standard/tests/file/pathinfo_basic1-win32.phpt @@ -0,0 +1,610 @@ +--TEST-- +Test pathinfo() function: basic functionality +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: mixed pathinfo ( string $path [, int $options] ); + Description: Returns information about a file path +*/ + +echo "*** Testing basic functions of pathinfo() ***\n"; + +$paths = array ( + '', + ' ', + 'c:', + 'c:\\', + 'c:/', + 'afile', + 'c:\test\adir', + 'c:\test\adir\\', + '/usr/include/arpa', + '/usr/include/arpa/', + 'usr/include/arpa', + 'usr/include/arpa/', + 'c:\test\afile', + 'c:\\test\\afile', + 'c://test//afile', + 'c:\test\afile\\', + 'c:\test\prog.exe', + 'c:\\test\\prog.exe', + 'c:/test/prog.exe', + '/usr/include/arpa/inet.h', + '//usr/include//arpa/inet.h', + '\\', + '\\\\', + '/', + '//', + '///', + '/usr/include/arpa/inet.h', + 'c:\windows/system32\drivers/etc\hosts', + '/usr\include/arpa\inet.h', + ' c:\test\adir\afile.txt', + 'c:\test\adir\afile.txt ', + ' c:\test\adir\afile.txt ', + ' /usr/include/arpa/inet.h', + '/usr/include/arpa/inet.h ', + ' /usr/include/arpa/inet.h ', + ' c:', + ' c:\test\adir\afile.txt', + '/usr', + '/usr/' +); + +$counter = 1; +/* loop through $paths to test each $path in the above array */ +foreach($paths as $path) { + echo "-- Iteration $counter --\n"; + var_dump( pathinfo($path, PATHINFO_DIRNAME) ); + var_dump( pathinfo($path, PATHINFO_BASENAME) ); + var_dump( pathinfo($path, PATHINFO_EXTENSION) ); + var_dump( pathinfo($path, PATHINFO_FILENAME) ); + var_dump( pathinfo($path) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing basic functions of pathinfo() *** +-- Iteration 1 -- +string(0) "" +unicode(0) "" +string(0) "" +unicode(0) "" +array(2) { + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 2 -- +unicode(1) "." +unicode(1) " " +string(0) "" +unicode(1) " " +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(1) " " + [u"filename"]=> + unicode(1) " " +} +-- Iteration 3 -- +unicode(2) "c:" +unicode(2) "c:" +string(0) "" +unicode(2) "c:" +array(3) { + [u"dirname"]=> + unicode(2) "c:" + [u"basename"]=> + unicode(2) "c:" + [u"filename"]=> + unicode(2) "c:" +} +-- Iteration 4 -- +unicode(3) "c:\" +unicode(2) "c:" +string(0) "" +unicode(2) "c:" +array(3) { + [u"dirname"]=> + unicode(3) "c:\" + [u"basename"]=> + unicode(2) "c:" + [u"filename"]=> + unicode(2) "c:" +} +-- Iteration 5 -- +unicode(3) "c:\" +unicode(2) "c:" +string(0) "" +unicode(2) "c:" +array(3) { + [u"dirname"]=> + unicode(3) "c:\" + [u"basename"]=> + unicode(2) "c:" + [u"filename"]=> + unicode(2) "c:" +} +-- Iteration 6 -- +unicode(1) "." +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 7 -- +unicode(7) "c:\test" +unicode(4) "adir" +string(0) "" +unicode(4) "adir" +array(3) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(4) "adir" + [u"filename"]=> + unicode(4) "adir" +} +-- Iteration 8 -- +unicode(7) "c:\test" +unicode(4) "adir" +string(0) "" +unicode(4) "adir" +array(3) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(4) "adir" + [u"filename"]=> + unicode(4) "adir" +} +-- Iteration 9 -- +unicode(12) "/usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(12) "/usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 10 -- +unicode(12) "/usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(12) "/usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 11 -- +unicode(11) "usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(11) "usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 12 -- +unicode(11) "usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(11) "usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 13 -- +unicode(7) "c:\test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 14 -- +unicode(7) "c:\test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 15 -- +unicode(8) "c://test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(8) "c://test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 16 -- +unicode(7) "c:\test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 17 -- +unicode(7) "c:\test" +unicode(8) "prog.exe" +unicode(3) "exe" +unicode(4) "prog" +array(4) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(8) "prog.exe" + [u"extension"]=> + unicode(3) "exe" + [u"filename"]=> + unicode(4) "prog" +} +-- Iteration 18 -- +unicode(7) "c:\test" +unicode(8) "prog.exe" +unicode(3) "exe" +unicode(4) "prog" +array(4) { + [u"dirname"]=> + unicode(7) "c:\test" + [u"basename"]=> + unicode(8) "prog.exe" + [u"extension"]=> + unicode(3) "exe" + [u"filename"]=> + unicode(4) "prog" +} +-- Iteration 19 -- +unicode(7) "c:/test" +unicode(8) "prog.exe" +unicode(3) "exe" +unicode(4) "prog" +array(4) { + [u"dirname"]=> + unicode(7) "c:/test" + [u"basename"]=> + unicode(8) "prog.exe" + [u"extension"]=> + unicode(3) "exe" + [u"filename"]=> + unicode(4) "prog" +} +-- Iteration 20 -- +unicode(17) "/usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 21 -- +unicode(19) "//usr/include//arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(19) "//usr/include//arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 22 -- +unicode(1) "\" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 23 -- +unicode(1) "\" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 24 -- +unicode(1) "\" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 25 -- +unicode(1) "\" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 26 -- +unicode(1) "\" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 27 -- +unicode(17) "/usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 28 -- +unicode(31) "c:\windows/system32\drivers/etc" +unicode(5) "hosts" +string(0) "" +unicode(5) "hosts" +array(3) { + [u"dirname"]=> + unicode(31) "c:\windows/system32\drivers/etc" + [u"basename"]=> + unicode(5) "hosts" + [u"filename"]=> + unicode(5) "hosts" +} +-- Iteration 29 -- +unicode(17) "/usr\include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr\include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 30 -- +unicode(15) " c:\test\adir" +unicode(9) "afile.txt" +unicode(3) "txt" +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(15) " c:\test\adir" + [u"basename"]=> + unicode(9) "afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 31 -- +unicode(12) "c:\test\adir" +unicode(12) "afile.txt " +unicode(6) "txt " +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(12) "c:\test\adir" + [u"basename"]=> + unicode(12) "afile.txt " + [u"extension"]=> + unicode(6) "txt " + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 32 -- +unicode(15) " c:\test\adir" +unicode(12) "afile.txt " +unicode(6) "txt " +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(15) " c:\test\adir" + [u"basename"]=> + unicode(12) "afile.txt " + [u"extension"]=> + unicode(6) "txt " + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 33 -- +unicode(20) " /usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(20) " /usr/include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 34 -- +unicode(17) "/usr/include/arpa" +unicode(9) "inet.h " +unicode(4) "h " +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(9) "inet.h " + [u"extension"]=> + unicode(4) "h " + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 35 -- +unicode(20) " /usr/include/arpa" +unicode(9) "inet.h " +unicode(4) "h " +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(20) " /usr/include/arpa" + [u"basename"]=> + unicode(9) "inet.h " + [u"extension"]=> + unicode(4) "h " + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 36 -- +unicode(1) "." +unicode(3) " c:" +string(0) "" +unicode(3) " c:" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(3) " c:" + [u"filename"]=> + unicode(3) " c:" +} +-- Iteration 37 -- +unicode(14) " c:\test\adir" +unicode(9) "afile.txt" +unicode(3) "txt" +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(14) " c:\test\adir" + [u"basename"]=> + unicode(9) "afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 38 -- +unicode(1) "\" +unicode(3) "usr" +string(0) "" +unicode(3) "usr" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(3) "usr" + [u"filename"]=> + unicode(3) "usr" +} +-- Iteration 39 -- +unicode(1) "\" +unicode(3) "usr" +string(0) "" +unicode(3) "usr" +array(3) { + [u"dirname"]=> + unicode(1) "\" + [u"basename"]=> + unicode(3) "usr" + [u"filename"]=> + unicode(3) "usr" +} +Done + diff --git a/ext/standard/tests/file/pathinfo_basic1.phpt b/ext/standard/tests/file/pathinfo_basic1.phpt new file mode 100644 index 0000000000..18d1f68acc --- /dev/null +++ b/ext/standard/tests/file/pathinfo_basic1.phpt @@ -0,0 +1,610 @@ +--TEST-- +Test pathinfo() function: basic functionality +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: mixed pathinfo ( string $path [, int $options] ); + Description: Returns information about a file path +*/ + +echo "*** Testing basic functions of pathinfo() ***\n"; + +$paths = array ( + '', + ' ', + 'c:', + 'c:\\', + 'c:/', + 'afile', + 'c:\test\adir', + 'c:\test\adir\\', + '/usr/include/arpa', + '/usr/include/arpa/', + 'usr/include/arpa', + 'usr/include/arpa/', + 'c:\test\afile', + 'c:\\test\\afile', + 'c://test//afile', + 'c:\test\afile\\', + 'c:\test\prog.exe', + 'c:\\test\\prog.exe', + 'c:/test/prog.exe', + '/usr/include/arpa/inet.h', + '//usr/include//arpa/inet.h', + '\\', + '\\\\', + '/', + '//', + '///', + '/usr/include/arpa/inet.h', + 'c:\windows/system32\drivers/etc\hosts', + '/usr\include/arpa\inet.h', + ' c:\test\adir\afile.txt', + 'c:\test\adir\afile.txt ', + ' c:\test\adir\afile.txt ', + ' /usr/include/arpa/inet.h', + '/usr/include/arpa/inet.h ', + ' /usr/include/arpa/inet.h ', + ' c:', + ' c:\test\adir\afile.txt', + '/usr', + '/usr/' +); + +$counter = 1; +/* loop through $paths to test each $path in the above array */ +foreach($paths as $path) { + echo "-- Iteration $counter --\n"; + var_dump( pathinfo($path, PATHINFO_DIRNAME) ); + var_dump( pathinfo($path, PATHINFO_BASENAME) ); + var_dump( pathinfo($path, PATHINFO_EXTENSION) ); + var_dump( pathinfo($path, PATHINFO_FILENAME) ); + var_dump( pathinfo($path) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing basic functions of pathinfo() *** +-- Iteration 1 -- +string(0) "" +unicode(0) "" +string(0) "" +unicode(0) "" +array(2) { + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 2 -- +unicode(1) "." +unicode(1) " " +string(0) "" +unicode(1) " " +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(1) " " + [u"filename"]=> + unicode(1) " " +} +-- Iteration 3 -- +unicode(1) "." +unicode(2) "c:" +string(0) "" +unicode(2) "c:" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(2) "c:" + [u"filename"]=> + unicode(2) "c:" +} +-- Iteration 4 -- +unicode(1) "." +unicode(3) "c:\" +string(0) "" +unicode(3) "c:\" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(3) "c:\" + [u"filename"]=> + unicode(3) "c:\" +} +-- Iteration 5 -- +unicode(1) "." +unicode(2) "c:" +string(0) "" +unicode(2) "c:" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(2) "c:" + [u"filename"]=> + unicode(2) "c:" +} +-- Iteration 6 -- +unicode(1) "." +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 7 -- +unicode(1) "." +unicode(12) "c:\test\adir" +string(0) "" +unicode(12) "c:\test\adir" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(12) "c:\test\adir" + [u"filename"]=> + unicode(12) "c:\test\adir" +} +-- Iteration 8 -- +unicode(1) "." +unicode(13) "c:\test\adir\" +string(0) "" +unicode(13) "c:\test\adir\" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(13) "c:\test\adir\" + [u"filename"]=> + unicode(13) "c:\test\adir\" +} +-- Iteration 9 -- +unicode(12) "/usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(12) "/usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 10 -- +unicode(12) "/usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(12) "/usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 11 -- +unicode(11) "usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(11) "usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 12 -- +unicode(11) "usr/include" +unicode(4) "arpa" +string(0) "" +unicode(4) "arpa" +array(3) { + [u"dirname"]=> + unicode(11) "usr/include" + [u"basename"]=> + unicode(4) "arpa" + [u"filename"]=> + unicode(4) "arpa" +} +-- Iteration 13 -- +unicode(1) "." +unicode(13) "c:\test\afile" +string(0) "" +unicode(13) "c:\test\afile" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(13) "c:\test\afile" + [u"filename"]=> + unicode(13) "c:\test\afile" +} +-- Iteration 14 -- +unicode(1) "." +unicode(13) "c:\test\afile" +string(0) "" +unicode(13) "c:\test\afile" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(13) "c:\test\afile" + [u"filename"]=> + unicode(13) "c:\test\afile" +} +-- Iteration 15 -- +unicode(8) "c://test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(8) "c://test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 16 -- +unicode(1) "." +unicode(14) "c:\test\afile\" +string(0) "" +unicode(14) "c:\test\afile\" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(14) "c:\test\afile\" + [u"filename"]=> + unicode(14) "c:\test\afile\" +} +-- Iteration 17 -- +unicode(1) "." +unicode(16) "c:\test\prog.exe" +unicode(3) "exe" +unicode(12) "c:\test\prog" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(16) "c:\test\prog.exe" + [u"extension"]=> + unicode(3) "exe" + [u"filename"]=> + unicode(12) "c:\test\prog" +} +-- Iteration 18 -- +unicode(1) "." +unicode(16) "c:\test\prog.exe" +unicode(3) "exe" +unicode(12) "c:\test\prog" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(16) "c:\test\prog.exe" + [u"extension"]=> + unicode(3) "exe" + [u"filename"]=> + unicode(12) "c:\test\prog" +} +-- Iteration 19 -- +unicode(7) "c:/test" +unicode(8) "prog.exe" +unicode(3) "exe" +unicode(4) "prog" +array(4) { + [u"dirname"]=> + unicode(7) "c:/test" + [u"basename"]=> + unicode(8) "prog.exe" + [u"extension"]=> + unicode(3) "exe" + [u"filename"]=> + unicode(4) "prog" +} +-- Iteration 20 -- +unicode(17) "/usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 21 -- +unicode(19) "//usr/include//arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(19) "//usr/include//arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 22 -- +unicode(1) "." +unicode(1) "\" +string(0) "" +unicode(1) "\" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(1) "\" + [u"filename"]=> + unicode(1) "\" +} +-- Iteration 23 -- +unicode(1) "." +unicode(2) "\\" +string(0) "" +unicode(2) "\\" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(2) "\\" + [u"filename"]=> + unicode(2) "\\" +} +-- Iteration 24 -- +unicode(1) "/" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "/" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 25 -- +unicode(1) "/" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "/" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 26 -- +unicode(1) "/" +unicode(0) "" +string(0) "" +unicode(0) "" +array(3) { + [u"dirname"]=> + unicode(1) "/" + [u"basename"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 27 -- +unicode(17) "/usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 28 -- +unicode(27) "c:\windows/system32\drivers" +unicode(9) "etc\hosts" +string(0) "" +unicode(9) "etc\hosts" +array(3) { + [u"dirname"]=> + unicode(27) "c:\windows/system32\drivers" + [u"basename"]=> + unicode(9) "etc\hosts" + [u"filename"]=> + unicode(9) "etc\hosts" +} +-- Iteration 29 -- +unicode(12) "/usr\include" +unicode(11) "arpa\inet.h" +unicode(1) "h" +unicode(9) "arpa\inet" +array(4) { + [u"dirname"]=> + unicode(12) "/usr\include" + [u"basename"]=> + unicode(11) "arpa\inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(9) "arpa\inet" +} +-- Iteration 30 -- +unicode(1) "." +unicode(25) " c:\test\adir\afile.txt" +unicode(3) "txt" +unicode(21) " c:\test\adir\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(25) " c:\test\adir\afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(21) " c:\test\adir\afile" +} +-- Iteration 31 -- +unicode(1) "." +unicode(25) "c:\test\adir\afile.txt " +unicode(6) "txt " +unicode(18) "c:\test\adir\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(25) "c:\test\adir\afile.txt " + [u"extension"]=> + unicode(6) "txt " + [u"filename"]=> + unicode(18) "c:\test\adir\afile" +} +-- Iteration 32 -- +unicode(1) "." +unicode(28) " c:\test\adir\afile.txt " +unicode(6) "txt " +unicode(21) " c:\test\adir\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(28) " c:\test\adir\afile.txt " + [u"extension"]=> + unicode(6) "txt " + [u"filename"]=> + unicode(21) " c:\test\adir\afile" +} +-- Iteration 33 -- +unicode(20) " /usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(20) " /usr/include/arpa" + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 34 -- +unicode(17) "/usr/include/arpa" +unicode(9) "inet.h " +unicode(4) "h " +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(9) "inet.h " + [u"extension"]=> + unicode(4) "h " + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 35 -- +unicode(20) " /usr/include/arpa" +unicode(9) "inet.h " +unicode(4) "h " +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(20) " /usr/include/arpa" + [u"basename"]=> + unicode(9) "inet.h " + [u"extension"]=> + unicode(4) "h " + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 36 -- +unicode(1) "." +unicode(3) " c:" +string(0) "" +unicode(3) " c:" +array(3) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(3) " c:" + [u"filename"]=> + unicode(3) " c:" +} +-- Iteration 37 -- +unicode(1) "." +unicode(24) " c:\test\adir\afile.txt" +unicode(3) "txt" +unicode(20) " c:\test\adir\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(24) " c:\test\adir\afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(20) " c:\test\adir\afile" +} +-- Iteration 38 -- +unicode(1) "/" +unicode(3) "usr" +string(0) "" +unicode(3) "usr" +array(3) { + [u"dirname"]=> + unicode(1) "/" + [u"basename"]=> + unicode(3) "usr" + [u"filename"]=> + unicode(3) "usr" +} +-- Iteration 39 -- +unicode(1) "/" +unicode(3) "usr" +string(0) "" +unicode(3) "usr" +array(3) { + [u"dirname"]=> + unicode(1) "/" + [u"basename"]=> + unicode(3) "usr" + [u"filename"]=> + unicode(3) "usr" +} +Done + diff --git a/ext/standard/tests/file/pathinfo_basic2-win32.phpt b/ext/standard/tests/file/pathinfo_basic2-win32.phpt new file mode 100644 index 0000000000..c8ef805497 --- /dev/null +++ b/ext/standard/tests/file/pathinfo_basic2-win32.phpt @@ -0,0 +1,271 @@ +--TEST-- +Test pathinfo() function: basic functionality +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: mixed pathinfo ( string $path [, int $options] ); + Description: Returns information about a file path +*/ + +echo "*** Testing basic functions of pathinfo() ***\n"; + +$paths = array ( + 'c:\..\dir1', + 'c:\test\..\test2\.\adir\afile.txt', + '/usr/include/../arpa/./inet.h', + 'c:\test\adir\afile..txt', + '/usr/include/arpa/inet..h', + 'c:\test\adir\afile.', + '/usr/include/arpa/inet.', + '/usr/include/arpa/inet,h', + 'c:afile.txt', + '..\.\..\test\afile.txt', + '.././../test/afile', + '.', + '..', + '...', + '/usr/lib/.../afile' + +); + +$counter = 1; +/* loop through $paths to test each $path in the above array */ +foreach($paths as $path) { + echo "-- Iteration $counter --\n"; + var_dump( pathinfo($path, PATHINFO_DIRNAME) ); + var_dump( pathinfo($path, PATHINFO_BASENAME) ); + var_dump( pathinfo($path, PATHINFO_EXTENSION) ); + var_dump( pathinfo($path, PATHINFO_FILENAME) ); + var_dump( pathinfo($path) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing basic functions of pathinfo() *** +-- Iteration 1 -- +unicode(5) "c:\.." +unicode(4) "dir1" +string(0) "" +unicode(4) "dir1" +array(3) { + [u"dirname"]=> + unicode(5) "c:\.." + [u"basename"]=> + unicode(4) "dir1" + [u"filename"]=> + unicode(4) "dir1" +} +-- Iteration 2 -- +unicode(23) "c:\test\..\test2\.\adir" +unicode(9) "afile.txt" +unicode(3) "txt" +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(23) "c:\test\..\test2\.\adir" + [u"basename"]=> + unicode(9) "afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 3 -- +unicode(22) "/usr/include/../arpa/." +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(22) "/usr/include/../arpa/." + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 4 -- +unicode(12) "c:\test\adir" +unicode(10) "afile..txt" +unicode(3) "txt" +unicode(6) "afile." +array(4) { + [u"dirname"]=> + unicode(12) "c:\test\adir" + [u"basename"]=> + unicode(10) "afile..txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(6) "afile." +} +-- Iteration 5 -- +unicode(17) "/usr/include/arpa" +unicode(7) "inet..h" +unicode(1) "h" +unicode(5) "inet." +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(7) "inet..h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(5) "inet." +} +-- Iteration 6 -- +unicode(12) "c:\test\adir" +unicode(6) "afile." +unicode(0) "" +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(12) "c:\test\adir" + [u"basename"]=> + unicode(6) "afile." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 7 -- +unicode(17) "/usr/include/arpa" +unicode(5) "inet." +unicode(0) "" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(5) "inet." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 8 -- +unicode(17) "/usr/include/arpa" +unicode(6) "inet,h" +string(0) "" +unicode(6) "inet,h" +array(3) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(6) "inet,h" + [u"filename"]=> + unicode(6) "inet,h" +} +-- Iteration 9 -- +unicode(3) "c:." +unicode(11) "c:afile.txt" +unicode(3) "txt" +unicode(7) "c:afile" +array(4) { + [u"dirname"]=> + unicode(3) "c:." + [u"basename"]=> + unicode(11) "c:afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(7) "c:afile" +} +-- Iteration 10 -- +unicode(12) "..\.\..\test" +unicode(9) "afile.txt" +unicode(3) "txt" +unicode(5) "afile" +array(4) { + [u"dirname"]=> + unicode(12) "..\.\..\test" + [u"basename"]=> + unicode(9) "afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 11 -- +unicode(12) ".././../test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(12) ".././../test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 12 -- +unicode(1) "." +unicode(1) "." +unicode(0) "" +unicode(0) "" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(1) "." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 13 -- +unicode(1) "." +unicode(2) ".." +unicode(0) "" +unicode(1) "." +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(2) ".." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(1) "." +} +-- Iteration 14 -- +unicode(1) "." +unicode(3) "..." +unicode(0) "" +unicode(2) ".." +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(3) "..." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(2) ".." +} +-- Iteration 15 -- +unicode(12) "/usr/lib/..." +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(12) "/usr/lib/..." + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +Done + diff --git a/ext/standard/tests/file/pathinfo_basic2.phpt b/ext/standard/tests/file/pathinfo_basic2.phpt new file mode 100644 index 0000000000..45dc545093 --- /dev/null +++ b/ext/standard/tests/file/pathinfo_basic2.phpt @@ -0,0 +1,273 @@ +--TEST-- +Test pathinfo() function: basic functionality +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: mixed pathinfo ( string $path [, int $options] ); + Description: Returns information about a file path +*/ + +echo "*** Testing basic functions of pathinfo() ***\n"; + +$paths = array ( + 'c:\..\dir1', + 'c:\test\..\test2\.\adir\afile.txt', + '/usr/include/../arpa/./inet.h', + 'c:\test\adir\afile..txt', + '/usr/include/arpa/inet..h', + 'c:\test\adir\afile.', + '/usr/include/arpa/inet.', + '/usr/include/arpa/inet,h', + 'c:afile.txt', + '..\.\..\test\afile.txt', + '.././../test/afile', + '.', + '..', + '...', + '/usr/lib/.../afile' + +); + +$counter = 1; +/* loop through $paths to test each $path in the above array */ +foreach($paths as $path) { + echo "-- Iteration $counter --\n"; + var_dump( pathinfo($path, PATHINFO_DIRNAME) ); + var_dump( pathinfo($path, PATHINFO_BASENAME) ); + var_dump( pathinfo($path, PATHINFO_EXTENSION) ); + var_dump( pathinfo($path, PATHINFO_FILENAME) ); + var_dump( pathinfo($path) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing basic functions of pathinfo() *** +-- Iteration 1 -- +unicode(1) "." +unicode(10) "c:\..\dir1" +unicode(5) "\dir1" +unicode(4) "c:\." +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(10) "c:\..\dir1" + [u"extension"]=> + unicode(5) "\dir1" + [u"filename"]=> + unicode(4) "c:\." +} +-- Iteration 2 -- +unicode(1) "." +unicode(33) "c:\test\..\test2\.\adir\afile.txt" +unicode(3) "txt" +unicode(29) "c:\test\..\test2\.\adir\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(33) "c:\test\..\test2\.\adir\afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(29) "c:\test\..\test2\.\adir\afile" +} +-- Iteration 3 -- +unicode(22) "/usr/include/../arpa/." +unicode(6) "inet.h" +unicode(1) "h" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(22) "/usr/include/../arpa/." + [u"basename"]=> + unicode(6) "inet.h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 4 -- +unicode(1) "." +unicode(23) "c:\test\adir\afile..txt" +unicode(3) "txt" +unicode(19) "c:\test\adir\afile." +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(23) "c:\test\adir\afile..txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(19) "c:\test\adir\afile." +} +-- Iteration 5 -- +unicode(17) "/usr/include/arpa" +unicode(7) "inet..h" +unicode(1) "h" +unicode(5) "inet." +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(7) "inet..h" + [u"extension"]=> + unicode(1) "h" + [u"filename"]=> + unicode(5) "inet." +} +-- Iteration 6 -- +unicode(1) "." +unicode(19) "c:\test\adir\afile." +unicode(0) "" +unicode(18) "c:\test\adir\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(19) "c:\test\adir\afile." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(18) "c:\test\adir\afile" +} +-- Iteration 7 -- +unicode(17) "/usr/include/arpa" +unicode(5) "inet." +unicode(0) "" +unicode(4) "inet" +array(4) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(5) "inet." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(4) "inet" +} +-- Iteration 8 -- +unicode(17) "/usr/include/arpa" +unicode(6) "inet,h" +string(0) "" +unicode(6) "inet,h" +array(3) { + [u"dirname"]=> + unicode(17) "/usr/include/arpa" + [u"basename"]=> + unicode(6) "inet,h" + [u"filename"]=> + unicode(6) "inet,h" +} +-- Iteration 9 -- +unicode(1) "." +unicode(11) "c:afile.txt" +unicode(3) "txt" +unicode(7) "c:afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(11) "c:afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(7) "c:afile" +} +-- Iteration 10 -- +unicode(1) "." +unicode(22) "..\.\..\test\afile.txt" +unicode(3) "txt" +unicode(18) "..\.\..\test\afile" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(22) "..\.\..\test\afile.txt" + [u"extension"]=> + unicode(3) "txt" + [u"filename"]=> + unicode(18) "..\.\..\test\afile" +} +-- Iteration 11 -- +unicode(12) ".././../test" +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(12) ".././../test" + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +-- Iteration 12 -- +unicode(1) "." +unicode(1) "." +unicode(0) "" +unicode(0) "" +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(1) "." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +-- Iteration 13 -- +unicode(1) "." +unicode(2) ".." +unicode(0) "" +unicode(1) "." +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(2) ".." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(1) "." +} +-- Iteration 14 -- +unicode(1) "." +unicode(3) "..." +unicode(0) "" +unicode(2) ".." +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(3) "..." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(2) ".." +} +-- Iteration 15 -- +unicode(12) "/usr/lib/..." +unicode(5) "afile" +string(0) "" +unicode(5) "afile" +array(3) { + [u"dirname"]=> + unicode(12) "/usr/lib/..." + [u"basename"]=> + unicode(5) "afile" + [u"filename"]=> + unicode(5) "afile" +} +Done + diff --git a/ext/standard/tests/file/pathinfo_variation1.phpt b/ext/standard/tests/file/pathinfo_variation1.phpt new file mode 100644 index 0000000000..717a992799 --- /dev/null +++ b/ext/standard/tests/file/pathinfo_variation1.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test pathinfo() function : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array pathinfo(string path[, int options]) + * Description: Returns information about a certain string + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing pathinfo() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$options = PATHINFO_DIRNAME; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for path + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( pathinfo($value, $options) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing pathinfo() : usage variation *** + +--int 0-- +unicode(1) "." + +--int 1-- +unicode(1) "." + +--int 12345-- +unicode(1) "." + +--int -12345-- +unicode(1) "." + +--float 10.5-- +unicode(1) "." + +--float -10.5-- +unicode(1) "." + +--float 12.3456789000e10-- +unicode(1) "." + +--float -12.3456789000e10-- +unicode(1) "." + +--float .5-- +unicode(1) "." + +--empty array-- +Error: 2 - pathinfo() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - pathinfo() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--associative array-- +Error: 2 - pathinfo() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - pathinfo() expects parameter 1 to be string (Unicode or binary), array given, %s(%d) +NULL + +--uppercase NULL-- +string(0) "" + +--lowercase null-- +string(0) "" + +--lowercase true-- +unicode(1) "." + +--lowercase false-- +string(0) "" + +--uppercase TRUE-- +unicode(1) "." + +--uppercase FALSE-- +string(0) "" + +--empty string DQ-- +string(0) "" + +--empty string SQ-- +string(0) "" + +--instance of classWithToString-- +unicode(1) "." + +--instance of classWithoutToString-- +Error: 2 - pathinfo() expects parameter 1 to be string (Unicode or binary), object given, %s(%d) +NULL + +--undefined var-- +string(0) "" + +--unset var-- +string(0) "" +===DONE=== + diff --git a/ext/standard/tests/file/pathinfo_variation2.phpt b/ext/standard/tests/file/pathinfo_variation2.phpt new file mode 100644 index 0000000000..d2d5b2b612 --- /dev/null +++ b/ext/standard/tests/file/pathinfo_variation2.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test pathinfo() function : usage variation +--XFAIL-- +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array pathinfo(string path[, int options]) + * Description: Returns information about a certain string + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing pathinfo() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$path = '/usr/include/arpa/inet.h'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for options + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( pathinfo($path, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing pathinfo() : usage variation *** + +--float 10.5-- +unicode(6) "inet.h" + +--float -10.5-- +unicode(6) "inet.h" + +--float 12.3456789000e10-- +unicode(%d) %s + +--float -12.3456789000e10-- +unicode(%d) %s + +--float .5-- +string(0) "" + +--empty array-- +Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +string(0) "" + +--lowercase null-- +string(0) "" + +--lowercase true-- +unicode(17) "/usr/include/arpa" + +--lowercase false-- +string(0) "" + +--uppercase TRUE-- +unicode(17) "/usr/include/arpa" + +--uppercase FALSE-- +string(0) "" + +--empty string DQ-- +Error: 2 - pathinfo() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - pathinfo() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - pathinfo() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - pathinfo() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - pathinfo() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - pathinfo() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - pathinfo() expects parameter 2 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - pathinfo() expects parameter 2 to be long, object given, %s(%d) +NULL + +--undefined var-- +string(0) "" + +--unset var-- +string(0) "" +===DONE=== + diff --git a/ext/standard/tests/file/pathinfo_variation3.phpt b/ext/standard/tests/file/pathinfo_variation3.phpt new file mode 100644 index 0000000000..4092527e37 --- /dev/null +++ b/ext/standard/tests/file/pathinfo_variation3.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test pathinfo() function : usage variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : array pathinfo(string path[, int options]) + * Description: Returns information about a certain string + * Source code: ext/standard/string.c + * Alias to functions: + */ + +echo "*** Testing pathinfo() : usage variation ***\n"; + +$testfile = "/usr/include/arpa/inet.h"; + +var_dump(pathinfo("./")); +var_dump(pathinfo("/.")); +var_dump(pathinfo(".cvsignore")); +var_dump(pathinfo($testfile, PATHINFO_BASENAME)); +var_dump(pathinfo($testfile, PATHINFO_FILENAME)); +var_dump(pathinfo($testfile, PATHINFO_EXTENSION)); +var_dump(pathinfo($testfile, PATHINFO_DIRNAME)); +var_dump(pathinfo($testfile, PATHINFO_EXTENSION|PATHINFO_FILENAME|PATHINFO_DIRNAME)); +var_dump(pathinfo($testfile, PATHINFO_EXTENSION|PATHINFO_FILENAME|PATHINFO_BASENAME)); +var_dump(pathinfo($testfile, PATHINFO_EXTENSION|PATHINFO_FILENAME)); +var_dump(pathinfo($testfile, PATHINFO_EXTENSION|PATHINFO_BASENAME)); +var_dump(pathinfo($testfile, PATHINFO_FILENAME|PATHINFO_DIRNAME)); +var_dump(pathinfo($testfile, PATHINFO_FILENAME|PATHINFO_BASENAME)); +var_dump(pathinfo($testfile, PATHINFO_DIRNAME|PATHINFO_EXTENSION)); +var_dump(pathinfo($testfile, PATHINFO_DIRNAME|PATHINFO_BASENAME)); + + +?> +===DONE=== +--EXPECTF-- +*** Testing pathinfo() : usage variation *** +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(1) "." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +array(4) { + [u"dirname"]=> + unicode(1) "%s" + [u"basename"]=> + unicode(1) "." + [u"extension"]=> + unicode(0) "" + [u"filename"]=> + unicode(0) "" +} +array(4) { + [u"dirname"]=> + unicode(1) "." + [u"basename"]=> + unicode(10) ".cvsignore" + [u"extension"]=> + unicode(9) "cvsignore" + [u"filename"]=> + unicode(0) "" +} +unicode(6) "inet.h" +unicode(4) "inet" +unicode(1) "h" +unicode(17) "/usr/include/arpa" +unicode(17) "/usr/include/arpa" +unicode(6) "inet.h" +unicode(1) "h" +unicode(6) "inet.h" +unicode(17) "/usr/include/arpa" +unicode(6) "inet.h" +unicode(17) "/usr/include/arpa" +unicode(17) "/usr/include/arpa" +===DONE=== + diff --git a/ext/standard/tests/file/pclose_variation1.phpt b/ext/standard/tests/file/pclose_variation1.phpt new file mode 100644 index 0000000000..ca4c4297ef --- /dev/null +++ b/ext/standard/tests/file/pclose_variation1.phpt @@ -0,0 +1,234 @@ +--TEST-- +Test pclose() function : usage variation +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int pclose(resource fp) + * Description: Close a file pointer opened by popen() + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing pclose() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for fp + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( pclose($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing pclose() : usage variation *** + +--int 0-- +Error: 2 - pclose() expects parameter 1 to be resource, integer given, %s(%d) +bool(false) + +--int 1-- +Error: 2 - pclose() expects parameter 1 to be resource, integer given, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - pclose() expects parameter 1 to be resource, integer given, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - pclose() expects parameter 1 to be resource, integer given, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - pclose() expects parameter 1 to be resource, double given, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - pclose() expects parameter 1 to be resource, double given, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - pclose() expects parameter 1 to be resource, double given, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - pclose() expects parameter 1 to be resource, double given, %s(%d) +bool(false) + +--float .5-- +Error: 2 - pclose() expects parameter 1 to be resource, double given, %s(%d) +bool(false) + +--empty array-- +Error: 2 - pclose() expects parameter 1 to be resource, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - pclose() expects parameter 1 to be resource, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - pclose() expects parameter 1 to be resource, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - pclose() expects parameter 1 to be resource, array given, %s(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - pclose() expects parameter 1 to be resource, null given, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - pclose() expects parameter 1 to be resource, null given, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - pclose() expects parameter 1 to be resource, boolean given, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - pclose() expects parameter 1 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - pclose() expects parameter 1 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - pclose() expects parameter 1 to be resource, boolean given, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - pclose() expects parameter 1 to be resource, Unicode string given, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - pclose() expects parameter 1 to be resource, Unicode string given, %s(%d) +bool(false) + +--string DQ-- +Error: 2 - pclose() expects parameter 1 to be resource, Unicode string given, %s(%d) +bool(false) + +--string SQ-- +Error: 2 - pclose() expects parameter 1 to be resource, Unicode string given, %s(%d) +bool(false) + +--mixed case string-- +Error: 2 - pclose() expects parameter 1 to be resource, Unicode string given, %s(%d) +bool(false) + +--heredoc-- +Error: 2 - pclose() expects parameter 1 to be resource, Unicode string given, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - pclose() expects parameter 1 to be resource, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - pclose() expects parameter 1 to be resource, object given, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - pclose() expects parameter 1 to be resource, null given, %s(%d) +bool(false) + +--unset var-- +Error: 2 - pclose() expects parameter 1 to be resource, null given, %s(%d) +bool(false) +===DONE=== + diff --git a/ext/standard/tests/file/popen_pclose_error-sunos.phpt b/ext/standard/tests/file/popen_pclose_error-sunos.phpt index 4c85c9e494..b63dbeb7ea 100644 --- a/ext/standard/tests/file/popen_pclose_error-sunos.phpt +++ b/ext/standard/tests/file/popen_pclose_error-sunos.phpt @@ -2,8 +2,8 @@ Test popen() and pclose function: error conditions --SKIPIF-- <?php -if(substr(PHP_OS, 0, 3) != 'Sun' ) - die("skip Only Valid for Sun Solaris"); +if( substr(PHP_OS, 0, 3) != 'Sun') + die("skip Only valid for Sun Solaris"); ?> --FILE-- @@ -35,13 +35,13 @@ unlink($file_path."/popen.tmp"); --EXPECTF-- *** Testing for error conditions *** -Warning: popen() expects exactly 2 parameters, 0 given in %s on line %d +Warning: Wrong parameter count for popen() in %s on line %d NULL -Warning: popen() expects exactly 2 parameters, 1 given in %s on line %d +Warning: Wrong parameter count for popen() in %s on line %d NULL -resource(%d) of type (stream) sh: abc.txt: not found +resource(%d) of type (stream) Warning: Wrong parameter count for pclose() in %s on line %d NULL diff --git a/ext/standard/tests/file/readfile_variation10-win32.phpt b/ext/standard/tests/file/readfile_variation10-win32.phpt Binary files differnew file mode 100644 index 0000000000..d9073a76f3 --- /dev/null +++ b/ext/standard/tests/file/readfile_variation10-win32.phpt diff --git a/ext/standard/tests/file/readfile_variation10.phpt b/ext/standard/tests/file/readfile_variation10.phpt Binary files differnew file mode 100644 index 0000000000..e53a788982 --- /dev/null +++ b/ext/standard/tests/file/readfile_variation10.phpt diff --git a/ext/standard/tests/file/readfile_variation4.phpt b/ext/standard/tests/file/readfile_variation4.phpt new file mode 100644 index 0000000000..7ece3855b3 --- /dev/null +++ b/ext/standard/tests/file/readfile_variation4.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test readfile() function : usage variation +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) + * Description: Output a file or a URL + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing readfile() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'readFileVar4.tmp'; +$use_include_path = false; +$h = fopen($filename,'wb'); +fwrite($h, "testing readfile"); +fclose($h); + + +$fileRes = fopen(__FILE__, 'r'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // file resource + 'file resource' => $fileRes, +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $h = readfile($filename, $use_include_path, $value); + if ($h == false) { + echo "file not read\n"; + } + else { + echo "\n"; + } +}; + +unlink($filename); +fclose($fileRes); + +?> +===DONE=== +--EXPECTF-- +*** Testing readfile() : usage variation *** + +--int 0-- +Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d) +file not read + +--int 1-- +Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d) +file not read + +--int 12345-- +Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d) +file not read + +--int -12345-- +Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d) +file not read + +--float 10.5-- +Error: 2 - readfile() expects parameter 3 to be resource, double given, %s(%d) +file not read + +--float -10.5-- +Error: 2 - readfile() expects parameter 3 to be resource, double given, %s(%d) +file not read + +--float 12.3456789000e10-- +Error: 2 - readfile() expects parameter 3 to be resource, double given, %s(%d) +file not read + +--float -12.3456789000e10-- +Error: 2 - readfile() expects parameter 3 to be resource, double given, %s(%d) +file not read + +--float .5-- +Error: 2 - readfile() expects parameter 3 to be resource, double given, %s(%d) +file not read + +--empty array-- +Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d) +file not read + +--int indexed array-- +Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d) +file not read + +--associative array-- +Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d) +file not read + +--nested arrays-- +Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d) +file not read + +--uppercase NULL-- +testing readfile + +--lowercase null-- +testing readfile + +--lowercase true-- +Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d) +file not read + +--lowercase false-- +Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d) +file not read + +--uppercase TRUE-- +Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d) +file not read + +--uppercase FALSE-- +Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d) +file not read + +--empty string DQ-- +Error: 2 - readfile() expects parameter 3 to be resource, Unicode string given, %s(%d) +file not read + +--empty string SQ-- +Error: 2 - readfile() expects parameter 3 to be resource, Unicode string given, %s(%d) +file not read + +--string DQ-- +Error: 2 - readfile() expects parameter 3 to be resource, Unicode string given, %s(%d) +file not read + +--string SQ-- +Error: 2 - readfile() expects parameter 3 to be resource, Unicode string given, %s(%d) +file not read + +--mixed case string-- +Error: 2 - readfile() expects parameter 3 to be resource, Unicode string given, %s(%d) +file not read + +--heredoc-- +Error: 2 - readfile() expects parameter 3 to be resource, Unicode string given, %s(%d) +file not read + +--instance of classWithToString-- +Error: 2 - readfile() expects parameter 3 to be resource, object given, %s(%d) +file not read + +--instance of classWithoutToString-- +Error: 2 - readfile() expects parameter 3 to be resource, object given, %s(%d) +file not read + +--undefined var-- +testing readfile + +--unset var-- +testing readfile + +--file resource-- +Error: 2 - readfile(): supplied resource is not a valid Stream-Context resource, %s(%d) +testing readfile +===DONE=== diff --git a/ext/standard/tests/file/readfile_variation5.phpt b/ext/standard/tests/file/readfile_variation5.phpt new file mode 100644 index 0000000000..cf8a9cd416 --- /dev/null +++ b/ext/standard/tests/file/readfile_variation5.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test readfile() function : usage variation +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) + * Description: Output a file or a URL + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing readfile() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'readFileVar5.tmp'; +$use_include_path = false; +$h = fopen($filename,'wb'); +fwrite($h, "testing readfile"); +fclose($h); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for use_include_path + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + $res = readfile($filename, $value); + if ($res == false) { + echo "File not read\n"; + } + else { + echo "\n"; + } +}; + +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing readfile() : usage variation *** + +--int 0-- +testing readfile + +--int 1-- +testing readfile + +--int 12345-- +testing readfile + +--int -12345-- +testing readfile + +--float 10.5-- +testing readfile + +--float -10.5-- +testing readfile + +--float 12.3456789000e10-- +testing readfile + +--float -12.3456789000e10-- +testing readfile + +--float .5-- +testing readfile + +--empty array-- +Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) +File not read + +--int indexed array-- +Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) +File not read + +--associative array-- +Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) +File not read + +--nested arrays-- +Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) +File not read + +--uppercase NULL-- +testing readfile + +--lowercase null-- +testing readfile + +--lowercase true-- +testing readfile + +--lowercase false-- +testing readfile + +--uppercase TRUE-- +testing readfile + +--uppercase FALSE-- +testing readfile + +--empty string DQ-- +testing readfile + +--empty string SQ-- +testing readfile + +--string DQ-- +testing readfile + +--string SQ-- +testing readfile + +--mixed case string-- +testing readfile + +--heredoc-- +testing readfile + +--instance of classWithToString-- +Error: 2 - readfile() expects parameter 2 to be boolean, object given, %s(%d) +File not read + +--instance of classWithoutToString-- +Error: 2 - readfile() expects parameter 2 to be boolean, object given, %s(%d) +File not read + +--undefined var-- +testing readfile + +--unset var-- +testing readfile +===DONE=== diff --git a/ext/standard/tests/file/readfile_variation6.phpt b/ext/standard/tests/file/readfile_variation6.phpt new file mode 100644 index 0000000000..513e94240f --- /dev/null +++ b/ext/standard/tests/file/readfile_variation6.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test readfile() function : variation - test include path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) + * Description: Output a file or a URL + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing readfile() : variation ***\n"; +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "readfileVar6.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = "afile.txt"; +$secondFile = $dir2."/".$filename; + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $secondFile, $filename; + $h = fopen($secondFile, "w"); + fwrite($h, "File in include path"); + fclose($h); + readfile($filename, true); + echo "\n"; + unlink($secondFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing readfile() : variation *** +File in include path +===DONE=== diff --git a/ext/standard/tests/file/readfile_variation7.phpt b/ext/standard/tests/file/readfile_variation7.phpt new file mode 100644 index 0000000000..dc20f0b4fc --- /dev/null +++ b/ext/standard/tests/file/readfile_variation7.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test readfile() function : variation +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) + * Description: Output a file or a URL + * Source code: ext/standard/file.c + * Alias to functions: + */ + +require_once('fopen_include_path.inc'); + +echo "*** Testing readfile() : variation ***\n"; +// this doesn't create the include dirs in this directory +// we change to this to ensure we are not part of the +// include paths. +$thisTestDir = "readfileVar7.dir"; +mkdir($thisTestDir); +chdir($thisTestDir); + +$filename = "readFileVar7.tmp"; +$scriptLocFile = dirname(__FILE__)."/".$filename; + +$newpath = create_include_path(); +set_include_path($newpath); +runtest(); +teardown_include_path(); +restore_include_path(); +chdir(".."); +rmdir($thisTestDir); + + +function runtest() { + global $scriptLocFile, $filename; + $h = fopen($scriptLocFile, "w"); + fwrite($h, "File in script location"); + fclose($h); + readfile($filename, true); + echo "\n"; + unlink($scriptLocFile); +} + +?> +===DONE=== +--EXPECT-- +*** Testing readfile() : variation *** +File in script location +===DONE=== diff --git a/ext/standard/tests/file/readfile_variation8-win32.phpt b/ext/standard/tests/file/readfile_variation8-win32.phpt new file mode 100644 index 0000000000..094a7349cf --- /dev/null +++ b/ext/standard/tests/file/readfile_variation8-win32.phpt @@ -0,0 +1,111 @@ +--TEST-- +Test readfile() function : variation +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) + * Description: Output a file or a URL + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing readfile() : variation ***\n"; +$mainDir = "readfileVar8"; +$subDir = "readfileVar8Sub"; +$absMainDir = dirname(__FILE__)."\\".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."\\".$subDir; +mkdir($absSubDir); + +$theFile = "fileToRead.tmp"; +$absFile = $absSubDir.'/'.$theFile; + +// create the file +$h = fopen($absFile,"w"); +fwrite($h, "The File Contents"); +fclose($h); + + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); +$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3); + +$allDirs = array( + // absolute paths + "$absSubDir\\", + "$absSubDir\\..\\".$subDir, + "$absSubDir\\\\..\\.\\".$subDir, + "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir, + "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir, + "$absSubDir\\BADDIR", + + // relative paths + $mainDir."\\".$subDir, + $mainDir."\\\\".$subDir, + $mainDir."\\\\\\".$subDir, + ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir, + "BADDIR", + + // unixifed path + $unixifiedDir, +); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- $dir --\n"; + $ok = readfile($dir.'\\'.$theFile); + if ($ok === 1) { + echo "\n"; + } +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing readfile() : variation *** + +-- %s\readfileVar8\readfileVar8Sub\ -- +The File Contents +-- %s\readfileVar8\readfileVar8Sub\..\readfileVar8Sub -- +The File Contents +-- %s\readfileVar8\readfileVar8Sub\\..\.\readfileVar8Sub -- +The File Contents +-- %s\readfileVar8\readfileVar8Sub\..\..\readfileVar8\.\readfileVar8Sub -- +The File Contents +-- %s\readfileVar8\readfileVar8Sub\..\\\readfileVar8Sub\\..\\..\readfileVar8Sub -- + +Warning: readfile(%s\readfileVar8\readfileVar8Sub\..\\\readfileVar8Sub\\..\\..\readfileVar8Sub\fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d + +-- %s\readfileVar8\readfileVar8Sub\BADDIR -- + +Warning: readfile(%s\readfileVar8\readfileVar8Sub\BADDIR\fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d + +-- readfileVar8\readfileVar8Sub -- +The File Contents +-- readfileVar8\\readfileVar8Sub -- +The File Contents +-- readfileVar8\\\readfileVar8Sub -- +The File Contents +-- .\readfileVar8\..\readfileVar8\readfileVar8Sub -- +The File Contents +-- BADDIR -- + +Warning: readfile(BADDIR\fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d + +-- /%s/readfileVar8/readfileVar8Sub -- +The File Contents +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/readfile_variation9.phpt b/ext/standard/tests/file/readfile_variation9.phpt new file mode 100644 index 0000000000..b3eb85b65f --- /dev/null +++ b/ext/standard/tests/file/readfile_variation9.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test readfile() function : variation - variable types of path +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) + * Description: Output a file or a URL + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing readfile() : variation ***\n"; +$mainDir = "readfileVar8"; +$subDir = "readfileVar8Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."/".$subDir; +mkdir($absSubDir); + +$theFile = "fileToRead.tmp"; +$absFile = $absSubDir.'/'.$theFile; + +// create the file +$h = fopen($absFile,"w"); +fwrite($h, "The File Contents"); +fclose($h); + + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + +$allDirs = array( + // absolute paths + "$absSubDir/", + "$absSubDir/../".$subDir, + "$absSubDir//.././".$subDir, + "$absSubDir/../../".$mainDir."/./".$subDir, + "$absSubDir/..///".$subDir."//..//../".$subDir, + "$absSubDir/BADDIR", + + + // relative paths + $mainDir."/".$subDir, + $mainDir."//".$subDir, + $mainDir."///".$subDir, + "./".$mainDir."/../".$mainDir."/".$subDir, + "BADDIR", +); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + $ok = readfile($dir.'/'.$theFile); + if ($ok === 1) { + echo "\n"; + } +} + +unlink($absFile); +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing readfile() : variation *** + +-- Iteration 1 -- +The File Contents +-- Iteration 2 -- +The File Contents +-- Iteration 3 -- +The File Contents +-- Iteration 4 -- +The File Contents +-- Iteration 5 -- + +Warning: readfile(%sreadfileVar8Sub/..///readfileVar8Sub//..//../readfileVar8Sub/fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d + +-- Iteration 6 -- + +Warning: readfile(%sreadfileVar8Sub/BADDIR/fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d + +-- Iteration 7 -- +The File Contents +-- Iteration 8 -- +The File Contents +-- Iteration 9 -- +The File Contents +-- Iteration 10 -- +The File Contents +-- Iteration 11 -- + +Warning: readfile(BADDIR/fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/readlink_realpath_basic1.phpt b/ext/standard/tests/file/readlink_realpath_basic1.phpt index 22c2ca8af4..bdbd2f7596 100644 --- a/ext/standard/tests/file/readlink_realpath_basic1.phpt +++ b/ext/standard/tests/file/readlink_realpath_basic1.phpt @@ -39,9 +39,6 @@ $linknames = array ( "$file_path/readlink_realpath_basic1/home/test/readlink_realpath_basic1_link.tmp", "$file_path/readlink_realpath_basic1//home/test//../test/./readlink_realpath_basic1_link.tmp", - // checking for binary safe - b"$file_path/readlink_realpath_basic1/home/readlink_realpath_basic1_link.tmp", - /* linknames with invalid linkpath */ "$file_path///readlink_realpath_basic1/home//..//././test//readlink_realpath_basic1_link.tmp", "$file_path/readlink_realpath_basic1/home/../home/../test/../readlink_realpath_basic1_link.tmp", @@ -89,28 +86,24 @@ unicode(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp" unicode(%d) "%s/readlink_realpath_basic1/home/test/readlink_realpath_basic1.tmp" -- Iteration 4 -- -unicode(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp" -unicode(%d) "%s/readlink_realpath_basic1/home/readlink_realpath_basic1.tmp" - --- Iteration 5 -- Warning: readlink(): No such file or directory in %s on line %d bool(false) bool(false) --- Iteration 6 -- +-- Iteration 5 -- Warning: readlink(): No such file or directory in %s on line %d bool(false) bool(false) --- Iteration 7 -- +-- Iteration 6 -- Warning: readlink(): No such file or directory in %s on line %d bool(false) %s --- Iteration 8 -- +-- Iteration 7 -- Warning: readlink(): %s in %s on line %d bool(false) diff --git a/ext/standard/tests/file/readlink_realpath_basic2.phpt b/ext/standard/tests/file/readlink_realpath_basic2.phpt index 8e5023315a..20583038a7 100644 --- a/ext/standard/tests/file/readlink_realpath_basic2.phpt +++ b/ext/standard/tests/file/readlink_realpath_basic2.phpt @@ -34,9 +34,6 @@ $filenames = array ( "$file_path/readlink_realpath_basic2//home/test//../test/./readlink_realpath_basic2.tmp", "$file_path/readlink_realpath_basic2/home//../././readlink_realpath_basic2.tmp", - // checking for binary safe - b"$file_path/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp", - /* filenames with invalid path */ "$file_path///readlink_realpath_basic2/home//..//././test//readlink_realpath_basic2.tmp", "$file_path/readlink_realpath_basic2/home/../home/../test/../readlink_realpath_basic2.tmp", @@ -79,14 +76,11 @@ unicode(%d) "%s/readlink_realpath_basic2/home/test/readlink_realpath_basic2.tmp" unicode(%d) "%s/readlink_realpath_basic2/readlink_realpath_basic2.tmp" -- Iteration 5 -- -unicode(%d) "%s/readlink_realpath_basic2/home/readlink_realpath_basic2.tmp" +bool(false) -- Iteration 6 -- bool(false) -- Iteration 7 -- -bool(false) - --- Iteration 8 -- %s Done diff --git a/ext/standard/tests/file/readlink_variation1.phpt b/ext/standard/tests/file/readlink_variation1.phpt new file mode 100644 index 0000000000..1d15377941 --- /dev/null +++ b/ext/standard/tests/file/readlink_variation1.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test readlink() function: usage variations - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no links on Windows'); +} +?> +--FILE-- +<?php +/* Prototype: string readlink ( string $path ); + Description: Returns the target of a symbolic link */ + +/* Testing readlink() with invalid arguments -int, float, bool, NULL, resource */ + +$file_path = dirname(__FILE__); +$file_handle = fopen($file_path."/readlink_variation2.tmp", "w"); + +echo "*** Testing Invalid file types ***\n"; +$filenames = array( + /* Invalid filenames */ + -2.34555, + "", + TRUE, + FALSE, + NULL, + $file_handle, + + /* scalars */ + 1234, + 0 +); + +/* loop through to test each element the above array */ +foreach( $filenames as $filename ) { + var_dump( readlink($filename) ); + clearstatcache(); +} +fclose($file_handle); + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/readlink_variation2.tmp"); +?> +--EXPECTF-- +*** Testing Invalid file types *** + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +Warning: readlink(): No such file or directory in %s on line %d +bool(false) + +*** Done *** + diff --git a/ext/standard/tests/file/realpath_variation2.phpt b/ext/standard/tests/file/realpath_variation2.phpt new file mode 100644 index 0000000000..68d3c02a1f --- /dev/null +++ b/ext/standard/tests/file/realpath_variation2.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test realpath() function : variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == 'WIN' ) + die("skip Not Valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : string realpath(string path) + * Description: Return the resolved path + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing realpath() : variation ***\n"; + +$paths = array('c:\\', + 'c:', + 'c' , + '\\' , + '/', + 'c:temp', + 'c:\\/', + '/tmp/', + '/tmp/\\', + '\\tmp', + '\\tmp\\'); + +foreach($paths as $path) { + echo "\n--$path--\n"; + var_dump( realpath($path) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing realpath() : variation *** + +--c:\-- +bool(false) + +--c:-- +bool(false) + +--c-- +bool(false) + +--\-- +bool(false) + +--/-- +unicode(1) "/" + +--c:temp-- +bool(false) + +--c:\/-- +bool(false) + +--/tmp/-- +unicode(%d) %s/tmp" + +--/tmp/\-- +bool(false) + +--\tmp-- +bool(false) + +--\tmp\-- +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/rename_basic.phpt b/ext/standard/tests/file/rename_basic.phpt index a8df55b845..28d3b19889 100755 --- a/ext/standard/tests/file/rename_basic.phpt +++ b/ext/standard/tests/file/rename_basic.phpt @@ -36,9 +36,10 @@ echo "Done\n"; unlink(dirname(__FILE__)."/rename_basic.tmp"); unlink(dirname(__FILE__)."/rename_basic_new.tmp"); ?> ---EXPECT-- +--EXPECTF-- *** Testing rename() on non-existing file *** bool(true) bool(false) bool(true) Done + diff --git a/ext/standard/tests/file/rename_variation-win32.phpt b/ext/standard/tests/file/rename_variation-win32.phpt index 8ca68d88b9..cebf0334c5 100644 --- a/ext/standard/tests/file/rename_variation-win32.phpt +++ b/ext/standard/tests/file/rename_variation-win32.phpt @@ -71,7 +71,7 @@ bool(true) Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): No such file or directory in %s on line %d bool(false) -bool(true) +bool(false) bool(false) Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d @@ -84,3 +84,4 @@ bool(true) bool(false) bool(true) Done + diff --git a/ext/standard/tests/file/rename_variation10.phpt b/ext/standard/tests/file/rename_variation10.phpt new file mode 100644 index 0000000000..ae662885de --- /dev/null +++ b/ext/standard/tests/file/rename_variation10.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test rename() function : usage variation - different types for context +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool rename(string old_name, string new_name[, resource context]) + * Description: Rename a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rename() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$old_name = __FILE__.'.tmp'; +$new_name = __FILE__.'.renamed'; + +//file resource +$fileRes = fopen(__FILE__, 'r'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // file resource + 'file resource' => $fileRes, +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + touch($old_name); + $res = rename($old_name, $new_name, $value); + var_dump($res); + if ($res == true) { + unlink($new_name); + } + else { + unlink($old_name); + } +}; + +fclose($fileRes); + +?> +===DONE=== +--EXPECTF-- +*** Testing rename() : usage variation *** + +--int 0-- +Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d) +bool(false) + +--int 1-- +Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - rename() expects parameter 3 to be resource, double given, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - rename() expects parameter 3 to be resource, double given, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - rename() expects parameter 3 to be resource, double given, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - rename() expects parameter 3 to be resource, double given, %s(%d) +bool(false) + +--float .5-- +Error: 2 - rename() expects parameter 3 to be resource, double given, %s(%d) +bool(false) + +--empty array-- +Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - rename() expects parameter 3 to be resource, Unicode string given, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - rename() expects parameter 3 to be resource, Unicode string given, %s(%d) +bool(false) + +--string DQ-- +Error: 2 - rename() expects parameter 3 to be resource, Unicode string given, %s(%d) +bool(false) + +--string SQ-- +Error: 2 - rename() expects parameter 3 to be resource, Unicode string given, %s(%d) +bool(false) + +--mixed case string-- +Error: 2 - rename() expects parameter 3 to be resource, Unicode string given, %s(%d) +bool(false) + +--heredoc-- +Error: 2 - rename() expects parameter 3 to be resource, Unicode string given, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - rename() expects parameter 3 to be resource, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - rename() expects parameter 3 to be resource, object given, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) +bool(false) + +--unset var-- +Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) +bool(false) + +--file resource-- +Error: 2 - rename(): supplied resource is not a valid Stream-Context resource, %s(%d) +bool(true) +===DONE=== diff --git a/ext/standard/tests/file/rename_variation11-win32.phpt b/ext/standard/tests/file/rename_variation11-win32.phpt new file mode 100644 index 0000000000..d17b0d283c --- /dev/null +++ b/ext/standard/tests/file/rename_variation11-win32.phpt @@ -0,0 +1,128 @@ +--TEST-- +Test rename() function : variation - various relative, absolute paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool rename(string old_name, string new_name[, resource context]) + * Description: Rename a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rename() with absolute and relative paths ***\n"; +$mainDir = "renameVar11"; +$subDir = "renameVar11Sub"; +$absMainDir = dirname(__FILE__)."\\".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."\\".$subDir; +mkdir($absSubDir); + +$fromFile = "renameMe.tmp"; +$toFile = "IwasRenamed.tmp"; + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); +$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3); + + +$allDirs = array( + // absolute paths + "$absSubDir\\", + "$absSubDir\\..\\".$subDir, + "$absSubDir\\\\..\\.\\".$subDir, + "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir, + "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir, + "$absSubDir\\BADDIR", + + // relative paths + $mainDir."\\".$subDir, + $mainDir."\\\\".$subDir, + $mainDir."\\\\\\".$subDir, + ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir, + "BADDIR", + + // unixifed path + $unixifiedDir, +); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + touch($absSubDir."\\".$fromFile); + $res = rename($dir."\\".$fromFile, $dir."\\".$toFile); + var_dump($res); + if ($res == true) { + $res = rename($dir."\\".$toFile, $dir."\\".$fromFile); + var_dump($res); + } + unlink($absSubDir."\\".$fromFile); +} + +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing rename() with absolute and relative paths *** + +-- Iteration 1 -- +bool(true) +bool(true) + +-- Iteration 2 -- +bool(true) +bool(true) + +-- Iteration 3 -- +bool(true) +bool(true) + +-- Iteration 4 -- +bool(true) +bool(true) + +-- Iteration 5 -- + +Warning: rename(%s\renameVar11\renameVar11Sub\..\\\renameVar11Sub\\..\\..\renameVar11Sub\renameMe.tmp,%s\renameVar11\renameVar11Sub\..\\\renameVar11Sub\\..\\..\renameVar11Sub\IwasRenamed.tmp): No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: rename(%s\renameVar11\renameVar11Sub\BADDIR\renameMe.tmp,%s\renameVar11\renameVar11Sub\BADDIR\IwasRenamed.tmp): No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +bool(true) +bool(true) + +-- Iteration 8 -- +bool(true) +bool(true) + +-- Iteration 9 -- +bool(true) +bool(true) + +-- Iteration 10 -- +bool(true) +bool(true) + +-- Iteration 11 -- + +Warning: rename(BADDIR\renameMe.tmp,BADDIR\IwasRenamed.tmp): No such file or directory in %s on line %d +bool(false) + +-- Iteration 12 -- +bool(true) +bool(true) + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/rename_variation12.phpt b/ext/standard/tests/file/rename_variation12.phpt new file mode 100644 index 0000000000..11274f03d2 --- /dev/null +++ b/ext/standard/tests/file/rename_variation12.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test rename() function : variation - various relative, absolute paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool rename(string old_name, string new_name[, resource context]) + * Description: Rename a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +/* Creating unique files in various dirs by passing relative paths to $dir arg */ + +echo "*** Testing rename() with absolute and relative paths ***\n"; +$mainDir = "renameVar11"; +$subDir = "renameVar11Sub"; +$absMainDir = dirname(__FILE__)."/".$mainDir; +mkdir($absMainDir); +$absSubDir = $absMainDir."/".$subDir; +mkdir($absSubDir); + +$fromFile = "renameMe.tmp"; +$toFile = "IwasRenamed.tmp"; + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + +$allDirs = array( + // absolute paths + "$absSubDir/", + "$absSubDir/../".$subDir, + "$absSubDir//.././".$subDir, + "$absSubDir/../../".$mainDir."/./".$subDir, + "$absSubDir/..///".$subDir."//..//../".$subDir, + "$absSubDir/BADDIR", + + + // relative paths + $mainDir."/".$subDir, + $mainDir."//".$subDir, + $mainDir."///".$subDir, + "./".$mainDir."/../".$mainDir."/".$subDir, + "BADDIR", +); + +for($i = 0; $i<count($allDirs); $i++) { + $j = $i+1; + $dir = $allDirs[$i]; + echo "\n-- Iteration $j --\n"; + touch($absSubDir."/".$fromFile); + $res = rename($dir."/".$fromFile, $dir."/".$toFile); + var_dump($res); + if ($res == true) { + $res = rename($dir."/".$toFile, $dir."/".$fromFile); + var_dump($res); + } + unlink($absSubDir."/".$fromFile); +} + +chdir($old_dir_path); +rmdir($absSubDir); +rmdir($absMainDir); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing rename() with absolute and relative paths *** + +-- Iteration 1 -- +bool(true) +bool(true) + +-- Iteration 2 -- +bool(true) +bool(true) + +-- Iteration 3 -- +bool(true) +bool(true) + +-- Iteration 4 -- +bool(true) +bool(true) + +-- Iteration 5 -- + +Warning: rename(%s/renameVar11/renameVar11Sub/..///renameVar11Sub//..//../renameVar11Sub/renameMe.tmp,%s/renameVar11/renameVar11Sub/..///renameVar11Sub//..//../renameVar11Sub/IwasRenamed.tmp): No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: rename(%s/renameVar11/renameVar11Sub/BADDIR/renameMe.tmp,%s/renameVar11/renameVar11Sub/BADDIR/IwasRenamed.tmp): No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- +bool(true) +bool(true) + +-- Iteration 8 -- +bool(true) +bool(true) + +-- Iteration 9 -- +bool(true) +bool(true) + +-- Iteration 10 -- +bool(true) +bool(true) + +-- Iteration 11 -- + +Warning: rename(BADDIR/renameMe.tmp,BADDIR/IwasRenamed.tmp): No such file or directory in %s on line %d +bool(false) + +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/rename_variation13-win32.phpt b/ext/standard/tests/file/rename_variation13-win32.phpt Binary files differnew file mode 100644 index 0000000000..717529eea8 --- /dev/null +++ b/ext/standard/tests/file/rename_variation13-win32.phpt diff --git a/ext/standard/tests/file/rename_variation13.phpt b/ext/standard/tests/file/rename_variation13.phpt Binary files differnew file mode 100644 index 0000000000..d089c97deb --- /dev/null +++ b/ext/standard/tests/file/rename_variation13.phpt diff --git a/ext/standard/tests/file/rmdir_variation1-win32.phpt b/ext/standard/tests/file/rmdir_variation1-win32.phpt new file mode 100644 index 0000000000..0732821c54 --- /dev/null +++ b/ext/standard/tests/file/rmdir_variation1-win32.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test rmdir() function : usage variation - invalid filenames +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool rmdir(string dirname[, resource context]) + * Description: Remove a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rmdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase false' =>false, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // other + // php outputs Permission Denied, p8 outputs no suck file or dir + 'single space' => ' ', +); + +// loop through each element of the array for dirname + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( rmdir($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing rmdir() : usage variation *** + +--uppercase NULL-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--unset var-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--single space-- +Error: 2 - rmdir( ): %s, %s(%d) +bool(false) +===DONE=== diff --git a/ext/standard/tests/file/rmdir_variation1.phpt b/ext/standard/tests/file/rmdir_variation1.phpt new file mode 100644 index 0000000000..d219e6cdf3 --- /dev/null +++ b/ext/standard/tests/file/rmdir_variation1.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test rmdir() function : usage variation - invalid file names +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Not valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool rmdir(string dirname[, resource context]) + * Description: Remove a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rmdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase false' =>false, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // other + 'single space' => ' ', +); + +// loop through each element of the array for dirname + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( rmdir($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing rmdir() : usage variation *** + +--uppercase NULL-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--unset var-- +Error: 2 - rmdir(): No such file or directory, %s(%d) +bool(false) + +--single space-- +Error: 2 - rmdir( ): No such file or directory, %s(%d) +bool(false) +===DONE=== diff --git a/ext/standard/tests/file/rmdir_variation2.phpt b/ext/standard/tests/file/rmdir_variation2.phpt new file mode 100644 index 0000000000..b9148aadaf --- /dev/null +++ b/ext/standard/tests/file/rmdir_variation2.phpt @@ -0,0 +1,244 @@ +--TEST-- +Test rmdir() function : usage variation - different types for context +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool rmdir(string dirname[, resource context]) + * Description: Remove a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rmdir() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$dirname = 'rmdirVar2.tmp'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +$fileres = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // non stream context resource + $fileres, +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + @mkdir($dirname); + var_dump( rmdir($dirname, $value) ); +}; + +@rmdir($dirname); +fclose($fileres); +?> +===DONE=== +--EXPECTF-- +*** Testing rmdir() : usage variation *** + +--int 0-- +Error: 2 - rmdir() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--int 1-- +Error: 2 - rmdir() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - rmdir() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - rmdir() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - rmdir() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - rmdir() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - rmdir() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - rmdir() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float .5-- +Error: 2 - rmdir() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--empty array-- +Error: 2 - rmdir() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - rmdir() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - rmdir() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - rmdir() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - rmdir() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - rmdir() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - rmdir() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - rmdir() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - rmdir() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - rmdir() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--string DQ-- +Error: 2 - rmdir() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--string SQ-- +Error: 2 - rmdir() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--mixed case string-- +Error: 2 - rmdir() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--heredoc-- +Error: 2 - rmdir() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - rmdir() expects parameter 2 to be resource, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - rmdir() expects parameter 2 to be resource, object given, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--unset var-- +Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--0-- +Error: 2 - rmdir(): supplied resource is not a valid Stream-Context resource, %s(%d) +bool(true) +===DONE=== diff --git a/ext/standard/tests/file/rmdir_variation3-win32.phpt b/ext/standard/tests/file/rmdir_variation3-win32.phpt new file mode 100644 index 0000000000..e6b3eaabb6 --- /dev/null +++ b/ext/standard/tests/file/rmdir_variation3-win32.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test rmdir() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype : bool rmdir(string dirname[, resource context]) + * Description: Remove a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rmdir() : variation ***\n"; + +$workDir = "rmdirVar3.tmp"; +$subDir = "aSubDir"; +mkdir($workDir); +$cwd = getcwd(); + +$unixifiedDir = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$subDir, 3); + +$dirs = array( + // relative + $workDir.'\\'.$subDir, + '.\\'.$workDir.'\\'.$subDir, + $workDir.'\\..\\'.$workDir.'\\'.$subDir, + + // relative bad path + $workDir.'\\..\\BADDIR\\'.$subDir, + 'BADDIR\\'.$subDir, + + //absolute + $cwd.'\\'.$workDir.'\\'.$subDir, + $cwd.'\\.\\'.$workDir.'\\'.$subDir, + $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$subDir, + + //absolute bad path + $cwd.'\\BADDIR\\'.$subDir, + + //trailing separators + $workDir.'\\'.$subDir.'\\', + $cwd.'\\'.$workDir.'\\'.$subDir.'\\', + + // multiple separators + $workDir.'\\\\'.$subDir, + $cwd.'\\\\'.$workDir.'\\\\'.$subDir, + + // Unixified Dir + $unixifiedDir, + + ); + + +foreach($dirs as $dir) { + mkdir($workDir.'/'.$subDir); + echo "-- removing $dir --\n"; + $res = rmdir($dir); + if ($res === true) { + echo "Directory removed\n"; + } + else { + rmdir($workDir.'/'.$subDir); + } +} + +rmdir($workDir); + +?> +===DONE=== +--EXPECTF-- +*** Testing rmdir() : variation *** +-- removing rmdirVar3.tmp\aSubDir -- +Directory removed +-- removing .\rmdirVar3.tmp\aSubDir -- +Directory removed +-- removing rmdirVar3.tmp\..\rmdirVar3.tmp\aSubDir -- +Directory removed +-- removing rmdirVar3.tmp\..\BADDIR\aSubDir -- + +Warning: rmdir(rmdirVar3.tmp\..\BADDIR\aSubDir): No such file or directory in %s on line %d +-- removing BADDIR\aSubDir -- + +Warning: rmdir(BADDIR\aSubDir): No such file or directory in %s on line %d +-- removing %s\rmdirVar3.tmp\aSubDir -- +Directory removed +-- removing %s\.\rmdirVar3.tmp\aSubDir -- +Directory removed +-- removing %s\rmdirVar3.tmp\..\rmdirVar3.tmp\aSubDir -- +Directory removed +-- removing %s\BADDIR\aSubDir -- + +Warning: rmdir(%s\BADDIR\aSubDir): No such file or directory in %s on line %d +-- removing rmdirVar3.tmp\aSubDir\ -- +Directory removed +-- removing %s\rmdirVar3.tmp\aSubDir\ -- +Directory removed +-- removing rmdirVar3.tmp\\aSubDir -- +Directory removed +-- removing %s\\rmdirVar3.tmp\\aSubDir -- +Directory removed +-- removing /%s/rmdirVar3.tmp/aSubDir -- +Directory removed +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/rmdir_variation3.phpt b/ext/standard/tests/file/rmdir_variation3.phpt new file mode 100644 index 0000000000..5848007395 --- /dev/null +++ b/ext/standard/tests/file/rmdir_variation3.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test rmdir() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool rmdir(string dirname[, resource context]) + * Description: Remove a directory + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing rmdir() : variation ***\n"; + +$workDir = "rmdirVar3.tmp"; +$subDir = "aSubDir"; +mkdir($workDir); +$cwd = getcwd(); + +$dirs = array( + // relative + $workDir.'/'.$subDir, + './'.$workDir.'/'.$subDir, + $workDir.'/../'.$workDir.'/'.$subDir, + + // relative bad path + $workDir.'/../BADDIR/'.$subDir, + 'BADDIR/'.$subDir, + + //absolute + $cwd.'/'.$workDir.'/'.$subDir, + $cwd.'/./'.$workDir.'/'.$subDir, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDir, + + //absolute bad path + $cwd.'/BADDIR/'.$subDir, + + //trailing separators + $workDir.'/'.$subDir.'/', + $cwd.'/'.$workDir.'/'.$subDir.'/', + + // multiple separators + $workDir.'//'.$subDir, + $cwd.'//'.$workDir.'//'.$subDir, + + ); + + +foreach($dirs as $dir) { + mkdir($workDir.'/'.$subDir); + echo "-- removing $dir --\n"; + $res = rmdir($dir); + if ($res === true) { + echo "Directory removed\n"; + } + else { + rmdir($workDir.'/'.$subDir); + } +} + +rmdir($workDir); + +?> +===DONE=== +--EXPECTF-- +*** Testing rmdir() : variation *** +-- removing rmdirVar3.tmp/aSubDir -- +Directory removed +-- removing ./rmdirVar3.tmp/aSubDir -- +Directory removed +-- removing rmdirVar3.tmp/../rmdirVar3.tmp/aSubDir -- +Directory removed +-- removing rmdirVar3.tmp/../BADDIR/aSubDir -- + +Warning: rmdir(rmdirVar3.tmp/../BADDIR/aSubDir): No such file or directory in %s on line %d +-- removing BADDIR/aSubDir -- + +Warning: rmdir(BADDIR/aSubDir): No such file or directory in %s on line %d +-- removing %s/rmdirVar3.tmp/aSubDir -- +Directory removed +-- removing %s/./rmdirVar3.tmp/aSubDir -- +Directory removed +-- removing %s/rmdirVar3.tmp/../rmdirVar3.tmp/aSubDir -- +Directory removed +-- removing %s/BADDIR/aSubDir -- + +Warning: rmdir(%s/BADDIR/aSubDir): No such file or directory in %s on line %d +-- removing rmdirVar3.tmp/aSubDir/ -- +Directory removed +-- removing %s/rmdirVar3.tmp/aSubDir/ -- +Directory removed +-- removing rmdirVar3.tmp//aSubDir -- +Directory removed +-- removing %s//rmdirVar3.tmp//aSubDir -- +Directory removed +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/symlink_link_linkinfo_is_link_error2.phpt b/ext/standard/tests/file/symlink_link_linkinfo_is_link_error2.phpt index 3bee688d87..98ce6211da 100644 --- a/ext/standard/tests/file/symlink_link_linkinfo_is_link_error2.phpt +++ b/ext/standard/tests/file/symlink_link_linkinfo_is_link_error2.phpt @@ -5,7 +5,7 @@ Test symlink(), linkinfo(), link() and is_link() functions : error conditions - if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip no symlinks on Windows'); } -if (PHP_INT_SIZE != 4 ) { +if (PHP_INT_SIZE != 4) { die("skip this test is for 32bit platform only"); } ?> @@ -42,6 +42,7 @@ var_dump( link($filename, $linkname, false) ); //invalid arguments var_dump( link(NULL, $linkname) ); // NULL as filename var_dump( link('', $linkname) ); // empty string as filename +var_dump( link(' ', $linkname) ); // space as filename var_dump( link(false, $linkname) ); // boolean false as filename var_dump( link($filename, NULL) ); // NULL as linkname var_dump( link($filename, '') ); // '' as linkname @@ -57,6 +58,7 @@ var_dump( is_link($linkname, "/") ); //invalid arguments var_dump( is_link(NULL) ); // NULL as linkname var_dump( is_link('') ); // empty string as linkname +var_dump( is_link(' ') ); // space as linkname var_dump( is_link(false) ); // boolean false as linkname var_dump( is_link($filename) ); // file given to is_link @@ -75,22 +77,25 @@ NULL Warning: link() expects exactly 2 parameters, 3 given in %s on line %d NULL -Warning: link(): %s in %s on line %d +Warning: link(): No such file or directory in %s on line %d bool(false) -Warning: link(): %s in %s on line %d +Warning: link(): No such file or directory in %s on line %d bool(false) -Warning: link(): %s in %s on line %d +Warning: link(): No such file or directory in %s on line %d bool(false) -Warning: link(): %s in %s on line %d +Warning: link(): No such file or directory in %s on line %d bool(false) -Warning: link(): %s in %s on line %d +Warning: link(): No such file or directory in %s on line %d bool(false) -Warning: link(): %s in %s on line %d +Warning: link(): No such file or directory in %s on line %d +bool(false) + +Warning: link(): No such file or directory in %s on line %d bool(false) *** Testing is_link() for error conditions *** @@ -104,4 +109,6 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) Done + diff --git a/ext/standard/tests/file/tempnam_variation1-win32.phpt b/ext/standard/tests/file/tempnam_variation1-win32.phpt index 9075950330..a3dd7e9d62 100644 --- a/ext/standard/tests/file/tempnam_variation1-win32.phpt +++ b/ext/standard/tests/file/tempnam_variation1-win32.phpt @@ -3,7 +3,7 @@ Test tempnam() function: usage variations - creating files --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) != "WIN") - die("skip Run only on Windows"); + die("skip Only valid for Windows"); ?> --FILE-- <?php @@ -13,7 +13,8 @@ if(substr(PHP_OS, 0, 3) != "WIN") /* Creating number of unique files by passing a file name as prefix */ -$file_path = dirname(__FILE__); +$file_path = dirname(__FILE__)."/tempnamVar1"; +mkdir($file_path); echo "*** Testing tempnam() in creation of unique files ***\n"; for($i=1; $i<=10; $i++) { @@ -31,6 +32,19 @@ for($i=1; $i<=10; $i++) { echo "\n"; clearstatcache(); + echo "File created in => "; + $file_dir = dirname($files[$i]); + + if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else if (realpath($file_dir) == realpath($file_path) || realpath($file_dir."\\") == realpath($file_path)) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + clearstatcache(); } else { print("- File is not created -"); @@ -39,39 +53,51 @@ for($i=1; $i<=10; $i++) { for($i=1; $i<=10; $i++) { unlink($files[$i]); } +rmdir($file_path); + echo "*** Done ***\n"; ?> --EXPECTF-- *** Testing tempnam() in creation of unique files *** -- Iteration 1 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 4 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 5 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 6 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 7 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 8 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 9 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified -- Iteration 10 -- -File name is => %s +File name is => %s%et%s File permissions are => 100666 +File created in => directory specified *** Done *** diff --git a/ext/standard/tests/file/tempnam_variation1.phpt b/ext/standard/tests/file/tempnam_variation1.phpt index c94a65ba21..0745f5397c 100644 --- a/ext/standard/tests/file/tempnam_variation1.phpt +++ b/ext/standard/tests/file/tempnam_variation1.phpt @@ -13,7 +13,8 @@ if(substr(PHP_OS, 0, 3) == "WIN") /* Creating number of unique files by passing a file name as prefix */ -$file_path = dirname(__FILE__); +$file_path = dirname(__FILE__)."/tempnamVar1"; +mkdir($file_path); echo "*** Testing tempnam() in creation of unique files ***\n"; for($i=1; $i<=10; $i++) { @@ -34,6 +35,19 @@ for($i=1; $i<=10; $i++) { echo "File inode is => "; print_r( fileinode($files[$i]) ); //checking inodes echo "\n"; + + echo "File created in => "; + $file_dir = dirname($files[$i]); + + if ($file_dir == sys_get_temp_dir()) { + echo "temp dir\n"; + } + else if ($file_dir == $file_path) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } clearstatcache(); } else { @@ -44,48 +58,59 @@ for($i=1; $i<=10; $i++) { unlink($files[$i]); } +rmdir($file_path); echo "*** Done ***\n"; ?> --EXPECTF-- *** Testing tempnam() in creation of unique files *** -- Iteration 1 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 4 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 5 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 6 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 7 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 8 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 9 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified -- Iteration 10 -- -File name is => %s +File name is => %s%etempnam_variation1.tmp%s File permissions are => 100600 File inode is => %d +File created in => directory specified *** Done *** diff --git a/ext/standard/tests/file/tempnam_variation2-win32.phpt b/ext/standard/tests/file/tempnam_variation2-win32.phpt index a9fe4fd2d6..4224966daf 100644 --- a/ext/standard/tests/file/tempnam_variation2-win32.phpt +++ b/ext/standard/tests/file/tempnam_variation2-win32.phpt @@ -1,9 +1,9 @@ --TEST-- -Test tempnam() function: usage variations - relative paths +Test tempnam() function: usage variations - various absolute and relative paths --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) != "WIN") - die("skip Run only on Windows"); + die("skip Only valid for Windows"); ?> --FILE-- <?php @@ -13,7 +13,7 @@ if(substr(PHP_OS, 0, 3) != "WIN") /* Creating unique files in various dirs by passing relative paths to $dir arg */ -echo "*** Testing tempnam() with relative paths ***\n"; +echo "*** Testing tempnam() with absolute and relative paths ***\n"; $dir_name = dirname(__FILE__)."/tempnam_variation2"; mkdir($dir_name); $dir_path = $dir_name."/tempnam_variation2_sub"; @@ -23,14 +23,24 @@ $old_dir_path = getcwd(); chdir(dirname(__FILE__)); $dir_paths = array( + // absolute paths "$dir_path", "$dir_path/", "$dir_path/..", "$dir_path//../", "$dir_path/../.././tempnam_variation2", "$dir_path/..///tempnam_variation2_sub//..//../tempnam_variation2", + "$dir_path/BADDIR", + + + // relative paths ".", - "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub" + "tempname_variation2", + "tempname_variation2/", + "tempnam_variation2/tempnam_variation2_sub", + "tempnam_variation2//tempnam_variation2_sub", + "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub", + "BADDIR", ); for($i = 0; $i<count($dir_paths); $i++) { @@ -47,10 +57,28 @@ for($i = 0; $i<count($dir_paths); $i++) { echo "File permissions are => "; printf("%o", fileperms($file_name) ); echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + $dir_req = $dir_paths[$i]; + + if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else if (realpath($file_dir) == realpath($dir_req) || realpath($file_dir."\\") == realpath($dir_req)) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + + } - else + else { echo "-- File is not created --"; - unlink($file_name); + } + + unlink($file_name); } chdir($old_dir_path); @@ -60,38 +88,76 @@ rmdir($dir_name); echo "\n*** Done ***\n"; ?> --EXPECTF-- -*** Testing tempnam() with relative paths *** +*** Testing tempnam() with absolute and relative paths *** -- Iteration 1 -- -File name is => %s +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s File permissions are => 100666 +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s File permissions are => 100666 +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s\tempnam_variation2\t%s File permissions are => 100666 +File created in => directory specified -- Iteration 4 -- -File name is => %s +File name is => %s\tempnam_variation2\t%s File permissions are => 100666 +File created in => directory specified -- Iteration 5 -- -File name is => %s +File name is => %s\tempnam_variation2\t%s File permissions are => 100666 +File created in => directory specified -- Iteration 6 -- -File name is => %s +File name is => %s\tempnam_variation2\t%s File permissions are => 100666 +File created in => directory specified -- Iteration 7 -- -File name is => %s +File name is => %s\t%s File permissions are => 100666 +File created in => temp dir -- Iteration 8 -- -File name is => %s +File name is => %s\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 9 -- +File name is => %s\t%s +File permissions are => 100666 +File created in => temp dir + +-- Iteration 10 -- +File name is => %s\t%s +File permissions are => 100666 +File created in => temp dir + +-- Iteration 11 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 12 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 13 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 14 -- +File name is => %s\t%s File permissions are => 100666 +File created in => temp dir -*** Done *** +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/tempnam_variation2.phpt b/ext/standard/tests/file/tempnam_variation2.phpt index 6d85e25628..b7e5cdc058 100644 --- a/ext/standard/tests/file/tempnam_variation2.phpt +++ b/ext/standard/tests/file/tempnam_variation2.phpt @@ -1,5 +1,5 @@ --TEST-- -Test tempnam() function: usage variations - relative paths +Test tempnam() function: usage variations - various absolute and relative paths --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) == "WIN") @@ -13,7 +13,7 @@ if(substr(PHP_OS, 0, 3) == "WIN") /* Creating unique files in various dirs by passing relative paths to $dir arg */ -echo "*** Testing tempnam() with relative paths ***\n"; +echo "*** Testing tempnam() with absolute and relative paths ***\n"; $dir_name = dirname(__FILE__)."/tempnam_variation2"; mkdir($dir_name); $dir_path = $dir_name."/tempnam_variation2_sub"; @@ -23,14 +23,24 @@ $old_dir_path = getcwd(); chdir(dirname(__FILE__)); $dir_paths = array( + // absolute paths "$dir_path", "$dir_path/", "$dir_path/..", "$dir_path//../", "$dir_path/../.././tempnam_variation2", "$dir_path/..///tempnam_variation2_sub//..//../tempnam_variation2", + "$dir_path/BADDIR", + + + // relative paths ".", - "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub" + "tempname_variation2", + "tempname_variation2/", + "tempnam_variation2/tempnam_variation2_sub", + "tempnam_variation2//tempnam_variation2_sub", + "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub", + "BADDIR", ); for($i = 0; $i<count($dir_paths); $i++) { @@ -47,10 +57,28 @@ for($i = 0; $i<count($dir_paths); $i++) { echo "File permissions are => "; printf("%o", fileperms($file_name) ); echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + $dir_req = $dir_paths[$i]; + + if (realpath($file_dir) == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else if ($file_dir == realpath($dir_req)) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + + } - else + else { echo "-- File is not created --"; - unlink($file_name); + } + + unlink($file_name); } chdir($old_dir_path); @@ -60,38 +88,76 @@ rmdir($dir_name); echo "\n*** Done ***\n"; ?> --EXPECTF-- -*** Testing tempnam() with relative paths *** +*** Testing tempnam() with absolute and relative paths *** -- Iteration 1 -- -File name is => %s +File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => directory specified -- Iteration 4 -- -File name is => %s +File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => directory specified -- Iteration 5 -- -File name is => %s +File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => directory specified -- Iteration 6 -- -File name is => %s +File name is => %s/tempnam_variation2/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => directory specified -- Iteration 7 -- -File name is => %s +File name is => %s/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 8 -- -File name is => %s +File name is => %s/tempnam_variation2.tmp%s +File permissions are => 100600 +File created in => directory specified + +-- Iteration 9 -- +File name is => %s/tempnam_variation2.tmp%s +File permissions are => 100600 +File created in => temp dir + +-- Iteration 10 -- +File name is => %s/tempnam_variation2.tmp%s +File permissions are => 100600 +File created in => temp dir + +-- Iteration 11 -- +File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s +File permissions are => 100600 +File created in => directory specified + +-- Iteration 12 -- +File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s +File permissions are => 100600 +File created in => directory specified + +-- Iteration 13 -- +File name is => %s/tempnam_variation2/tempnam_variation2_sub/tempnam_variation2.tmp%s +File permissions are => 100600 +File created in => directory specified + +-- Iteration 14 -- +File name is => %s/tempnam_variation2.tmp%s File permissions are => 100600 +File created in => temp dir -*** Done *** +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/tempnam_variation3-win32.phpt b/ext/standard/tests/file/tempnam_variation3-win32.phpt index 4e9eb76b5c..423cbf1624 100644 --- a/ext/standard/tests/file/tempnam_variation3-win32.phpt +++ b/ext/standard/tests/file/tempnam_variation3-win32.phpt @@ -1,9 +1,9 @@ --TEST-- -Test tempnam() function: usage variations - invalid/non-existing file +Test tempnam() function: usage variations - obscure prefixes --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) != "WIN") - die("skip Run only on Windows"); + die("skip run only on Windows"); ?> --FILE-- <?php @@ -13,10 +13,11 @@ if(substr(PHP_OS, 0, 3) != "WIN") /* Passing invalid/non-existing args for $prefix */ -echo "*** Testing tempnam() with invalid/non-existing file names ***\n"; -$file_path = dirname(__FILE__); +echo "*** Testing tempnam() with obscure prefixes ***\n"; +$file_path = dirname(__FILE__)."/tempnamVar3"; +mkdir($file_path); -/* An array of names, which will be passed as a file name */ +/* An array of prefixes */ $names_arr = array( /* Invalid args */ -1, @@ -25,16 +26,16 @@ $names_arr = array( NULL, "", " ", - "/0", + "\0", array(), - /* Non-existing dirs */ + /* prefix with path separator of a non existing directory*/ "/no/such/file/dir", - "php" + "php/php" ); -for( $i=1; $i<count($names_arr); $i++ ) { +for( $i=0; $i<count($names_arr); $i++ ) { echo "-- Iteration $i --\n"; $file_name = tempnam("$file_path", $names_arr[$i]); @@ -47,46 +48,73 @@ for( $i=1; $i<count($names_arr); $i++ ) { echo "File permissions are => "; printf("%o", fileperms($file_name) ); echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else if (realpath($file_dir) == realpath($file_path) || realpath($file_dir."\\") == realpath($file_path)) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } } - else + else { echo "-- File is not created --\n"; + } unlink($file_name); } +rmdir($file_path); echo "\n*** Done ***\n"; ?> --EXPECTF-- -*** Testing tempnam() with invalid/non-existing file names *** +*** Testing tempnam() with obscure prefixes *** +-- Iteration 0 -- +File name is => %s\%s +File permissions are => 100666 +File created in => directory specified -- Iteration 1 -- -File name is => %s +File name is => %s\%s File permissions are => 100666 +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s\%s File permissions are => 100666 +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s\%s File permissions are => 100666 +File created in => directory specified -- Iteration 4 -- -File name is => %s +File name is => %s\%s File permissions are => 100666 +File created in => directory specified -- Iteration 5 -- -File name is => %s +File name is => %s\%s File permissions are => 100666 +File created in => directory specified -- Iteration 6 -- -File name is => %s +File name is => %s\%s File permissions are => 100666 +File created in => directory specified -- Iteration 7 -- -Warning: tempnam() expects parameter 2 to be string, array given in %s on line %d --- File is not created -- - -Warning: unlink(): %s in %s on line %d +Notice: Array to string conversion in %sp on line %d +File name is => %s\%s +File permissions are => 100666 +File created in => directory specified -- Iteration 8 -- -File name is => %s +File name is => %s\di%s File permissions are => 100666 +File created in => directory specified -- Iteration 9 -- -File name is => %s +File name is => %s\ph%s File permissions are => 100666 +File created in => directory specified *** Done *** + diff --git a/ext/standard/tests/file/tempnam_variation3.phpt b/ext/standard/tests/file/tempnam_variation3.phpt index 3f4c73b6a8..c3895b9e1d 100644 --- a/ext/standard/tests/file/tempnam_variation3.phpt +++ b/ext/standard/tests/file/tempnam_variation3.phpt @@ -1,9 +1,9 @@ --TEST-- -Test tempnam() function: usage variations - invalid/non-existing file +Test tempnam() function: usage variations - obscure prefixes --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) == "WIN") - die("skip DO not run on Windows"); + die("skip Do not run on Windows"); ?> --FILE-- <?php @@ -13,10 +13,11 @@ if(substr(PHP_OS, 0, 3) == "WIN") /* Passing invalid/non-existing args for $prefix */ -echo "*** Testing tempnam() with invalid/non-existing file names ***\n"; -$file_path = dirname(__FILE__); +echo "*** Testing tempnam() with obscure prefixes ***\n"; +$file_path = dirname(__FILE__)."/tempnamVar3"; +mkdir($file_path); -/* An array of names, which will be passed as a file name */ +/* An array of prefixes */ $names_arr = array( /* Invalid args */ -1, @@ -25,16 +26,16 @@ $names_arr = array( NULL, "", " ", - "/0", + "\0", array(), - /* Non-existing dirs */ + /* prefix with path separator of a non existing directory*/ "/no/such/file/dir", - "php" + "php/php" ); -for( $i=1; $i<count($names_arr); $i++ ) { +for( $i=0; $i<count($names_arr); $i++ ) { echo "-- Iteration $i --\n"; $file_name = tempnam("$file_path", $names_arr[$i]); @@ -47,46 +48,75 @@ for( $i=1; $i<count($names_arr); $i++ ) { echo "File permissions are => "; printf("%o", fileperms($file_name) ); echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + + if ($file_dir == sys_get_temp_dir()) { + echo "temp dir\n"; + } + else if ($file_dir == $file_path) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + } - else + else { echo "-- File is not created --\n"; + } unlink($file_name); } +rmdir($file_path); echo "\n*** Done ***\n"; ?> --EXPECTF-- -*** Testing tempnam() with invalid/non-existing file names *** +*** Testing tempnam() with obscure prefixes *** +-- Iteration 0 -- +File name is => %s/%s +File permissions are => 100600 +File created in => directory specified -- Iteration 1 -- -File name is => %s +File name is => %s/%s File permissions are => 100600 +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s/%s File permissions are => 100600 +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s/%s File permissions are => 100600 +File created in => directory specified -- Iteration 4 -- -File name is => %s +File name is => %s/%s File permissions are => 100600 +File created in => directory specified -- Iteration 5 -- -File name is => %s +File name is => %s/%s File permissions are => 100600 +File created in => directory specified -- Iteration 6 -- -File name is => %s +File name is => %s/%s File permissions are => 100600 +File created in => directory specified -- Iteration 7 -- -Warning: tempnam() expects parameter 2 to be string, array given in %s on line %d --- File is not created -- - -Warning: unlink(): %s in %s on line %d +Notice: Array to string conversion in %sp on line %d +File name is => %s/%s +File permissions are => 100600 +File created in => directory specified -- Iteration 8 -- -File name is => %s +File name is => %s/dir%s File permissions are => 100600 +File created in => directory specified -- Iteration 9 -- -File name is => %s +File name is => %s/php%s File permissions are => 100600 +File created in => directory specified *** Done *** + diff --git a/ext/standard/tests/file/tempnam_variation4.phpt b/ext/standard/tests/file/tempnam_variation4.phpt index 491eae7343..8fec4019fc 100644 --- a/ext/standard/tests/file/tempnam_variation4.phpt +++ b/ext/standard/tests/file/tempnam_variation4.phpt @@ -20,22 +20,34 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { echo "*** Testing tempnam() with dir of permissions from 0000 to 0777 ***\n"; $file_path = dirname(__FILE__); $dir_name = $file_path."/tempnam_variation4"; +$prefix = "tempnamVar4."; + mkdir($dir_name); -for($mode = 0000; $mode<=0777; $mode++) { +for($mode = 0000; $mode <= 0777; $mode++) { echo "-- dir perms "; printf("%o", $mode); echo " --\n"; chmod($dir_name, $mode); - $file_name = tempnam($dir_name, "tempnam_variation4.tmp"); + $file_name = tempnam($dir_name, $prefix); if(file_exists($file_name) ) { - print($file_name); - echo "\n"; + if (realpath(dirname($file_name)) == realpath(sys_get_temp_dir())) { + $msg = " created in temp directory"; + } + else if (dirname($file_name) == $dir_name) { + $msg = " created in requested directory"; + } + else { + $msg = " created in unexpected directory"; + } + + echo basename($file_name).$msg."\n"; + unlink($file_name); + } + else { + print("FAILED: File is not created\n"); } - else - print("-- File is not created --"); - unlink($file_name); } rmdir($dir_name); @@ -45,1027 +57,1027 @@ echo "*** Done ***\n"; --EXPECTF-- *** Testing tempnam() with dir of permissions from 0000 to 0777 *** -- dir perms 0 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 1 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 2 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 3 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 4 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 5 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 6 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 7 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 10 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 11 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 12 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 13 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 14 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 15 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 16 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 17 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 20 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 21 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 22 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 23 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 24 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 25 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 26 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 27 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 30 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 31 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 32 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 33 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 34 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 35 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 36 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 37 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 40 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 41 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 42 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 43 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 44 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 45 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 46 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 47 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 50 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 51 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 52 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 53 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 54 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 55 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 56 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 57 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 60 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 61 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 62 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 63 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 64 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 65 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 66 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 67 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 70 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 71 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 72 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 73 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 74 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 75 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 76 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 77 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 100 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 101 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 102 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 103 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 104 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 105 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 106 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 107 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 110 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 111 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 112 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 113 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 114 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 115 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 116 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 117 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 120 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 121 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 122 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 123 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 124 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 125 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 126 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 127 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 130 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 131 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 132 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 133 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 134 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 135 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 136 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 137 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 140 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 141 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 142 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 143 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 144 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 145 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 146 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 147 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 150 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 151 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 152 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 153 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 154 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 155 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 156 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 157 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 160 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 161 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 162 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 163 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 164 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 165 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 166 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 167 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 170 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 171 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 172 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 173 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 174 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 175 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 176 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 177 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 200 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 201 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 202 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 203 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 204 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 205 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 206 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 207 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 210 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 211 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 212 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 213 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 214 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 215 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 216 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 217 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 220 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 221 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 222 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 223 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 224 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 225 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 226 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 227 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 230 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 231 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 232 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 233 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 234 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 235 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 236 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 237 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 240 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 241 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 242 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 243 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 244 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 245 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 246 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 247 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 250 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 251 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 252 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 253 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 254 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 255 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 256 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 257 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 260 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 261 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 262 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 263 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 264 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 265 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 266 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 267 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 270 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 271 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 272 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 273 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 274 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 275 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 276 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 277 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 300 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 301 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 302 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 303 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 304 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 305 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 306 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 307 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 310 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 311 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 312 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 313 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 314 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 315 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 316 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 317 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 320 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 321 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 322 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 323 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 324 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 325 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 326 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 327 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 330 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 331 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 332 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 333 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 334 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 335 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 336 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 337 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 340 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 341 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 342 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 343 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 344 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 345 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 346 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 347 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 350 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 351 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 352 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 353 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 354 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 355 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 356 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 357 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 360 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 361 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 362 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 363 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 364 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 365 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 366 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 367 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 370 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 371 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 372 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 373 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 374 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 375 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 376 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 377 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 400 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 401 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 402 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 403 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 404 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 405 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 406 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 407 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 410 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 411 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 412 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 413 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 414 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 415 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 416 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 417 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 420 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 421 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 422 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 423 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 424 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 425 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 426 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 427 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 430 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 431 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 432 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 433 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 434 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 435 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 436 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 437 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 440 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 441 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 442 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 443 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 444 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 445 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 446 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 447 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 450 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 451 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 452 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 453 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 454 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 455 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 456 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 457 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 460 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 461 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 462 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 463 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 464 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 465 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 466 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 467 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 470 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 471 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 472 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 473 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 474 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 475 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 476 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 477 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 500 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 501 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 502 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 503 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 504 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 505 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 506 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 507 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 510 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 511 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 512 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 513 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 514 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 515 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 516 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 517 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 520 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 521 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 522 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 523 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 524 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 525 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 526 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 527 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 530 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 531 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 532 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 533 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 534 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 535 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 536 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 537 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 540 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 541 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 542 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 543 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 544 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 545 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 546 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 547 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 550 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 551 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 552 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 553 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 554 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 555 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 556 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 557 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 560 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 561 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 562 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 563 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 564 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 565 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 566 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 567 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 570 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 571 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 572 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 573 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 574 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 575 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 576 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 577 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 600 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 601 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 602 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 603 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 604 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 605 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 606 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 607 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 610 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 611 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 612 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 613 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 614 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 615 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 616 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 617 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 620 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 621 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 622 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 623 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 624 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 625 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 626 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 627 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 630 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 631 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 632 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 633 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 634 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 635 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 636 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 637 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 640 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 641 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 642 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 643 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 644 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 645 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 646 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 647 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 650 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 651 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 652 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 653 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 654 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 655 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 656 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 657 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 660 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 661 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 662 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 663 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 664 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 665 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 666 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 667 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 670 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 671 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 672 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 673 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 674 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 675 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 676 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 677 -- -%s +tempnamVar4.%s created in temp directory -- dir perms 700 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 701 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 702 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 703 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 704 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 705 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 706 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 707 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 710 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 711 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 712 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 713 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 714 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 715 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 716 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 717 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 720 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 721 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 722 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 723 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 724 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 725 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 726 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 727 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 730 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 731 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 732 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 733 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 734 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 735 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 736 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 737 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 740 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 741 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 742 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 743 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 744 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 745 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 746 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 747 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 750 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 751 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 752 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 753 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 754 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 755 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 756 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 757 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 760 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 761 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 762 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 763 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 764 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 765 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 766 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 767 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 770 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 771 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 772 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 773 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 774 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 775 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 776 -- -%s +tempnamVar4.%s created in requested directory -- dir perms 777 -- -%s -*** Done *** +tempnamVar4.%s created in requested directory +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/tempnam_variation5-win32.phpt b/ext/standard/tests/file/tempnam_variation5-win32.phpt new file mode 100644 index 0000000000..3e39352fe1 --- /dev/null +++ b/ext/standard/tests/file/tempnam_variation5-win32.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test tempnam() function: usage variations - existing file +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Windows only"); +?> +--FILE-- +<?php +/* Prototype: string tempnam ( string $dir, string $prefix ); + Description: Create file with unique file name. +*/ + +/* Passing an existing file as $prefix for tempnam() fn */ + +$file_path = dirname(__FILE__); + +echo "*** Test tempnam() function: by passing an existing filename as prefix ***\n"; +$dir_name = $file_path."/tempnam_variation6"; +mkdir($dir_name); +$h = fopen($dir_name."/tempnam_variation6.tmp", "w"); + +for($i=1; $i<=3; $i++) { + echo "-- Iteration $i --\n"; + $created_file = tempnam("$dir_name", "tempnam_variation6.tmp"); + + if( file_exists($created_file) ) { + echo "File name is => "; + print($created_file); + echo "\n"; + } + else + print("File is not created"); + + unlink($created_file); +} +fclose($h); +unlink($dir_name."/tempnam_variation6.tmp"); +rmdir($dir_name); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Test tempnam() function: by passing an existing filename as prefix *** +-- Iteration 1 -- +File name is => %stempnam_variation6%et%s +-- Iteration 2 -- +File name is => %stempnam_variation6%et%s +-- Iteration 3 -- +File name is => %stempnam_variation6%et%s + +*** Done *** diff --git a/ext/standard/tests/file/tempnam_variation5.phpt b/ext/standard/tests/file/tempnam_variation5.phpt index 2d5f53dcd3..26c3f91f1f 100644 --- a/ext/standard/tests/file/tempnam_variation5.phpt +++ b/ext/standard/tests/file/tempnam_variation5.phpt @@ -1,5 +1,10 @@ --TEST-- Test tempnam() function: usage variations - existing file +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Do not run on Windows"); +?> --FILE-- <?php /* Prototype: string tempnam ( string $dir, string $prefix ); @@ -13,7 +18,7 @@ $file_path = dirname(__FILE__); echo "*** Test tempnam() function: by passing an existing filename as prefix ***\n"; $dir_name = $file_path."/tempnam_variation6"; mkdir($dir_name); -fopen($dir_name."/tempnam_variation6.tmp", "w"); +$h = fopen($dir_name."/tempnam_variation6.tmp", "w"); for($i=1; $i<=3; $i++) { echo "-- Iteration $i --\n"; @@ -29,6 +34,7 @@ for($i=1; $i<=3; $i++) { unlink($created_file); } +fclose($h); unlink($dir_name."/tempnam_variation6.tmp"); rmdir($dir_name); @@ -37,10 +43,10 @@ echo "\n*** Done ***\n"; --EXPECTF-- *** Test tempnam() function: by passing an existing filename as prefix *** -- Iteration 1 -- -File name is => %s +File name is => %stempnam_variation6%etempnam_variation6.tmp%s -- Iteration 2 -- -File name is => %s +File name is => %stempnam_variation6%etempnam_variation6.tmp%s -- Iteration 3 -- -File name is => %s +File name is => %stempnam_variation6%etempnam_variation6.tmp%s *** Done *** diff --git a/ext/standard/tests/file/tempnam_variation6-win32.phpt b/ext/standard/tests/file/tempnam_variation6-win32.phpt new file mode 100644 index 0000000000..efe7e86e85 --- /dev/null +++ b/ext/standard/tests/file/tempnam_variation6-win32.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test tempnam() function: usage variations - Using previous unique filename +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Windows Only"); +?> +--FILE-- +<?php +/* Prototype: string tempnam ( string $dir, string $prefix ); + Description: Create file with unique file name. +*/ + +/* Trying to create unique files by passing previously created unique file name as prefix */ + +$file_path = dirname(__FILE__); + +echo "\n*** Test tempnam(): by passing previously created filenames ***\n"; +$file_name = "tempnam_variation6.tmp"; +for($i=1; $i<=3; $i++) { + echo "-- Iteration $i --\n"; + $file_name = tempnam("$file_path", $file_name); + + if( file_exists($file_name) ) { + echo "File name is => "; + print($file_name); + echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + + if ($file_dir == sys_get_temp_dir()) { + echo "temp dir\n"; + } + else if ($file_dir == $file_path) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + } + + unlink($file_name); +} + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Test tempnam(): by passing previously created filenames *** +-- Iteration 1 -- +File name is => %s%et%s +File created in => directory specified +-- Iteration 2 -- +File name is => %s%et%s +File created in => directory specified +-- Iteration 3 -- +File name is => %s%et%s +File created in => directory specified + +*** Done *** diff --git a/ext/standard/tests/file/tempnam_variation6.phpt b/ext/standard/tests/file/tempnam_variation6.phpt index 51ecde9a73..5eb6e6fc86 100644 --- a/ext/standard/tests/file/tempnam_variation6.phpt +++ b/ext/standard/tests/file/tempnam_variation6.phpt @@ -1,5 +1,10 @@ --TEST-- -Test tempnam() function: usage variations - Using previous unique filename +Test tempnam() function: usage variations - Using previous unique filename +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip Do not run on Windows"); +?> --FILE-- <?php /* Prototype: string tempnam ( string $dir, string $prefix ); @@ -20,7 +25,20 @@ for($i=1; $i<=3; $i++) { echo "File name is => "; print($file_name); echo "\n"; - } + + echo "File created in => "; + $file_dir = dirname($file_name); + + if ($file_dir == sys_get_temp_dir()) { + echo "temp dir\n"; + } + else if ($file_dir == $file_path) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + } unlink($file_name); } @@ -30,10 +48,13 @@ echo "\n*** Done ***\n"; --EXPECTF-- *** Test tempnam(): by passing previously created filenames *** -- Iteration 1 -- -File name is => %s +File name is => %s%etempnam_variation6.tmp%s +File created in => directory specified -- Iteration 2 -- -File name is => %s +File name is => %s%etempnam_variation6.tmp%s +File created in => directory specified -- Iteration 3 -- -File name is => %s +File name is => %s%etempnam_variation6.tmp%s +File created in => directory specified *** Done *** diff --git a/ext/standard/tests/file/tempnam_variation7-win32.phpt b/ext/standard/tests/file/tempnam_variation7-win32.phpt index 09f13053c5..087c4e8470 100644 --- a/ext/standard/tests/file/tempnam_variation7-win32.phpt +++ b/ext/standard/tests/file/tempnam_variation7-win32.phpt @@ -3,7 +3,7 @@ Test tempnam() function: usage variations - invalid/non-existing dir --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) != "WIN") - die("skip Run only on Windows"); + die("skip Only run on Windows"); ?> --FILE-- <?php @@ -15,8 +15,6 @@ if(substr(PHP_OS, 0, 3) != "WIN") hence the unique files will be created in temporary dir */ echo "*** Testing tempnam() with invalid/non-existing directory names ***\n"; -$file_path = dirname(__FILE__); - /* An array of names, which will be passed as a dir name */ $names_arr = array( /* Invalid args */ @@ -26,7 +24,7 @@ $names_arr = array( NULL, "", " ", - "/0", + "\0", array(), /* Non-existing dirs */ @@ -35,7 +33,7 @@ $names_arr = array( ); -for( $i=1; $i<count($names_arr); $i++ ) { +for( $i=0; $i<count($names_arr); $i++ ) { echo "-- Iteration $i --\n"; $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp"); @@ -48,9 +46,19 @@ for( $i=1; $i<count($names_arr); $i++ ) { echo "File permissions are => "; printf("%o", fileperms($file_name) ); echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else { + echo "unknown location\n"; + } } - else + else { echo "-- File is not created --\n"; + } unlink($file_name); } @@ -59,35 +67,48 @@ echo "\n*** Done ***\n"; ?> --EXPECTF-- *** Testing tempnam() with invalid/non-existing directory names *** +-- Iteration 0 -- +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 1 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 2 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 3 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 4 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 5 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 6 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 7 -- -Warning: tempnam() expects parameter 1 to be string, array given in %s on line %d --- File is not created -- - -Warning: unlink(): No such file or directory in %s on line %d +Notice: Array to string conversion in %s on line %d +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 8 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir -- Iteration 9 -- -File name is => %s -File permissions are => 100600 +File name is => %s%et%s +File permissions are => 100666 +File created in => temp dir *** Done *** + diff --git a/ext/standard/tests/file/tempnam_variation7.phpt b/ext/standard/tests/file/tempnam_variation7.phpt index 97c747d687..4aa6538019 100644 --- a/ext/standard/tests/file/tempnam_variation7.phpt +++ b/ext/standard/tests/file/tempnam_variation7.phpt @@ -3,7 +3,7 @@ Test tempnam() function: usage variations - invalid/non-existing dir --SKIPIF-- <?php if(substr(PHP_OS, 0, 3) == "WIN") - die("skip DO not run on Windows"); + die("skip Do not run on Windows"); ?> --FILE-- <?php @@ -15,8 +15,6 @@ if(substr(PHP_OS, 0, 3) == "WIN") hence the unique files will be created in temporary dir */ echo "*** Testing tempnam() with invalid/non-existing directory names ***\n"; -$file_path = dirname(__FILE__); - /* An array of names, which will be passed as a dir name */ $names_arr = array( /* Invalid args */ @@ -26,7 +24,7 @@ $names_arr = array( NULL, "", " ", - "/0", + "\0", array(), /* Non-existing dirs */ @@ -35,7 +33,7 @@ $names_arr = array( ); -for( $i=1; $i<count($names_arr); $i++ ) { +for( $i=0; $i<count($names_arr); $i++ ) { echo "-- Iteration $i --\n"; $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp"); @@ -48,9 +46,21 @@ for( $i=1; $i<count($names_arr); $i++ ) { echo "File permissions are => "; printf("%o", fileperms($file_name) ); echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + + if (realpath($file_dir) == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else { + echo "unknown location\n"; + } + } - else + else { echo "-- File is not created --\n"; + } unlink($file_name); } @@ -59,37 +69,48 @@ echo "\n*** Done ***\n"; ?> --EXPECTF-- *** Testing tempnam() with invalid/non-existing directory names *** +-- Iteration 0 -- +File name is => %s%etempnam_variation3.tmp%s +File permissions are => 100600 +File created in => temp dir -- Iteration 1 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 2 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 3 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 4 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 5 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 6 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 7 -- -Warning: tempnam() expects parameter 1 to be string, array given in %s on line %d --- File is not created -- - -Warning: unlink(): No such file or directory in %s on line %d -File name is => %s +Notice: Array to string conversion in %s on line %d +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 8 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir -- Iteration 9 -- -File name is => %s +File name is => %s%etempnam_variation3.tmp%s File permissions are => 100600 +File created in => temp dir *** Done *** + diff --git a/ext/standard/tests/file/tempnam_variation8-win32.phpt b/ext/standard/tests/file/tempnam_variation8-win32.phpt new file mode 100644 index 0000000000..8df67b609e --- /dev/null +++ b/ext/standard/tests/file/tempnam_variation8-win32.phpt @@ -0,0 +1,147 @@ +--TEST-- +Test tempnam() function: usage variations - various absolute and relative paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only valid for Windows"); +?> +--FILE-- +<?php +/* Prototype: string tempnam ( string $dir, string $prefix ); + Description: Create file with unique file name. +*/ + +/* Creating unique files in various dirs by passing relative paths to $dir arg */ + +echo "*** Testing tempnam() with absolute and relative paths ***\n"; +$dir_name = dirname(__FILE__)."\\tempnam_variation2"; +mkdir($dir_name); +$dir_path = $dir_name."/tempnam_variation2_sub"; +mkdir($dir_path); + +$old_dir_path = getcwd(); +chdir(dirname(__FILE__)); + +$dir_paths = array( + // absolute paths + "$dir_path\\", + "$dir_path\\..", + "$dir_path\\\\..\\", + "$dir_path\\..\\..\\.\\tempnam_variation2", + "$dir_path\\..\\\\\\tempnam_variation2_sub\\\\..\\\\..\\tempnam_variation2", + "$dir_path\\BADDIR", + + + // relative paths + "tempname_variation2\\", + "tempnam_variation2\\tempnam_variation2_sub", + "tempnam_variation2\\\\tempnam_variation2_sub", + ".\\tempnam_variation2\\..\\tempnam_variation2\\tempnam_variation2_sub", + "BADDIR", +); + +for($i = 0; $i<count($dir_paths); $i++) { + $j = $i+1; + echo "\n-- Iteration $j --\n"; + $file_name = tempnam($dir_paths[$i], "tempnam_variation2.tmp"); + + if( file_exists($file_name) ){ + + echo "File name is => "; + print(realpath($file_name)); + echo "\n"; + + echo "File permissions are => "; + printf("%o", fileperms($file_name) ); + echo "\n"; + + echo "File created in => "; + $file_dir = dirname($file_name); + $dir_req = $dir_paths[$i]; + + if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { + echo "temp dir\n"; + } + else if (realpath($file_dir) == realpath($dir_req) || realpath($file_dir."\\") == realpath($dir_req)) { + echo "directory specified\n"; + } + else { + echo "unknown location\n"; + } + + + } + else { + echo "-- File is not created --"; + } + + unlink($file_name); +} + +chdir($old_dir_path); +rmdir($dir_path); +rmdir($dir_name); + +echo "\n*** Done ***\n"; +?> +--EXPECTF-- +*** Testing tempnam() with absolute and relative paths *** + +-- Iteration 1 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 2 -- +File name is => %s\tempnam_variation2\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 3 -- +File name is => %s\tempnam_variation2\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 4 -- +File name is => %s\tempnam_variation2\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 5 -- +File name is => %s\tempnam_variation2\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 6 -- +File name is => %s\t%s +File permissions are => 100666 +File created in => temp dir + +-- Iteration 7 -- +File name is => %s\t%s +File permissions are => 100666 +File created in => temp dir + +-- Iteration 8 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 9 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 10 -- +File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s +File permissions are => 100666 +File created in => directory specified + +-- Iteration 11 -- +File name is => %s\t%s +File permissions are => 100666 +File created in => temp dir + +*** Done *** diff --git a/ext/standard/tests/file/touch.phpt b/ext/standard/tests/file/touch.phpt index ec2215cba9..c6c270d065 100644 --- a/ext/standard/tests/file/touch.phpt +++ b/ext/standard/tests/file/touch.phpt @@ -1,8 +1,16 @@ --TEST-- touch() tests +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. only for Non Windows.'); +} +?> --FILE-- <?php +// This doesn't work for windows, time, atime usage results in very different +// output to linux. This could be a php.net bug on windows or a windows querk. $filename = dirname(__FILE__)."/touch.dat"; var_dump(touch()); @@ -30,7 +38,7 @@ var_dump(touch("/no/such/file/or/directory")); echo "Done\n"; ?> ---EXPECTF-- +--EXPECTF-- Warning: touch() expects at least 1 parameter, 0 given in %s on line %d NULL bool(true) @@ -44,6 +52,7 @@ int(100) bool(true) int(100) -Warning: touch(): Unable to create file /no/such/file/or/directory because No such file or directory in %s on line %d +Warning: touch(): Unable to create file /no/such/file/or/directory because %s in %s on line %d bool(false) Done + diff --git a/ext/standard/tests/file/touch_basic-win32.phpt b/ext/standard/tests/file/touch_basic-win32.phpt new file mode 100644 index 0000000000..530e28c7ae --- /dev/null +++ b/ext/standard/tests/file/touch_basic-win32.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test touch() function : basic functionality +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : proto bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing touch() : basic functionality ***\n"; + +$filename = dirname(__FILE__)."/touch.dat"; + +echo "\n--- testing touch creates a file ---\n"; +@unlink($filename); +if (file_exists($filename)) { + die("touch_basic failed"); +} +var_dump( touch($filename) ); +if (file_exists($filename) == false) { + die("touch_basic failed"); +} + +echo "\n --- testing touch doesn't alter file contents ---\n"; +$testln = "Here is a test line"; +$h = fopen($filename, "wb"); +fwrite($h, $testln); +fclose($h); +touch($filename); +$h = fopen($filename, "rb"); +echo fgets($h); +fclose($h); + +echo "\n\n --- testing touch alters the correct file metadata ---\n"; +$init_meta = stat($filename); +clearstatcache(); +sleep(1); +touch($filename); +$next_meta = stat($filename); +$type = array("dev", "ino", "mode", "nlink", "uid", "gid", + "rdev", "size", "atime", "mtime", "ctime", + "blksize", "blocks"); + +for ($i = 0; $i < count($type); $i++) { + if ($init_meta[$i] != $next_meta[$i]) { + echo "stat data differs at $type[$i]\n"; + } +} + + +// Initialise all required variables +$time = 10000; +$atime = 20470; + +// Calling touch() with all possible arguments +echo "\n --- testing touch using all parameters ---\n"; +var_dump( touch($filename, $time, $atime) ); +clearstatcache(); +$init_meta = stat($filename); +echo "ctime=".$init_meta['ctime']."\n"; +echo "mtime=".$init_meta['mtime']."\n"; +echo "atime=".$init_meta['atime']."\n"; + +unlink($filename); + +echo "Done"; +?> +--EXPECTF-- +*** Testing touch() : basic functionality *** + +--- testing touch creates a file --- +bool(true) + + --- testing touch doesn't alter file contents --- +Here is a test line + + --- testing touch alters the correct file metadata --- +stat data differs at atime +stat data differs at mtime + + --- testing touch using all parameters --- +bool(true) +ctime=%d +mtime=10000 +atime=20470 +Done + diff --git a/ext/standard/tests/file/touch_basic.phpt b/ext/standard/tests/file/touch_basic.phpt new file mode 100644 index 0000000000..0128edf8d8 --- /dev/null +++ b/ext/standard/tests/file/touch_basic.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test touch() function : basic functionality +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. only for Non Windows'); +} +?> +--FILE-- +<?php +/* Prototype : proto bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing touch() : basic functionality ***\n"; + +$filename = dirname(__FILE__)."/touch.dat"; + +echo "\n--- testing touch creates a file ---\n"; +@unlink($filename); +if (file_exists($filename)) { + die("touch_basic failed"); +} +var_dump( touch($filename) ); +if (file_exists($filename) == false) { + die("touch_basic failed"); +} + +echo "\n --- testing touch doesn't alter file contents ---\n"; +$testln = "Here is a test line"; +$h = fopen($filename, "wb"); +fwrite($h, $testln); +fclose($h); +touch($filename); +$h = fopen($filename, "rb"); +echo fgets($h); +fclose($h); + +echo "\n\n --- testing touch alters the correct file metadata ---\n"; +$init_meta = stat($filename); +clearstatcache(); +sleep(1); +touch($filename); +$next_meta = stat($filename); +$type = array("dev", "ino", "mode", "nlink", "uid", "gid", + "rdev", "size", "atime", "mtime", "ctime", + "blksize", "blocks"); + +for ($i = 0; $i < count($type); $i++) { + if ($init_meta[$i] != $next_meta[$i]) { + echo "stat data differs at $type[$i]\n"; + } +} + + +// Initialise all required variables +$time = 10000; +$atime = 20470; + +// Calling touch() with all possible arguments +echo "\n --- testing touch using all parameters ---\n"; +var_dump( touch($filename, $time, $atime) ); +clearstatcache(); +$init_meta = stat($filename); +echo "ctime=".$init_meta['ctime']."\n"; +echo "mtime=".$init_meta['mtime']."\n"; +echo "atime=".$init_meta['atime']."\n"; + +unlink($filename); + +echo "Done"; +?> +--EXPECTF-- +*** Testing touch() : basic functionality *** + +--- testing touch creates a file --- +bool(true) + + --- testing touch doesn't alter file contents --- +Here is a test line + + --- testing touch alters the correct file metadata --- +stat data differs at atime +stat data differs at mtime +stat data differs at ctime + + --- testing touch using all parameters --- +bool(true) +ctime=%d +mtime=10000 +atime=20470 +Done diff --git a/ext/standard/tests/file/touch_error.phpt b/ext/standard/tests/file/touch_error.phpt new file mode 100644 index 0000000000..ec58fee511 --- /dev/null +++ b/ext/standard/tests/file/touch_error.phpt @@ -0,0 +1,22 @@ +--TEST-- +touch() error tests +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php + +var_dump(touch()); +var_dump(touch(1, 2, 3, 4)); +var_dump(touch("/no/such/file/or/directory")); + +?> +--EXPECTF-- +Warning: touch() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Warning: touch() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: touch(): Unable to create file /no/such/file/or/directory because No such file or directory in %s on line %d +bool(false) + diff --git a/ext/standard/tests/file/touch_variation1.phpt b/ext/standard/tests/file/touch_variation1.phpt new file mode 100644 index 0000000000..dba41a6077 --- /dev/null +++ b/ext/standard/tests/file/touch_variation1.phpt @@ -0,0 +1,39 @@ +--TEST-- +touch() with times +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php + +$filename = dirname(__FILE__)."/touch.dat"; + + +var_dump(touch($filename, 101)); +var_dump(filemtime($filename)); +var_dump(fileatime($filename)); + +@unlink($filename); + +@unlink($filename); +var_dump(touch($filename, 100, 102)); +var_dump(filemtime($filename)); +var_dump(fileatime($filename)); + +@unlink($filename); +echo "Done\n"; + +?> +--EXPECTF-- +bool(true) +int(101) +int(101) +bool(true) +int(100) +int(102) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/touch_variation2.phpt b/ext/standard/tests/file/touch_variation2.phpt new file mode 100644 index 0000000000..9306d4703d --- /dev/null +++ b/ext/standard/tests/file/touch_variation2.phpt @@ -0,0 +1,26 @@ +--TEST-- +touch() - ensure touch does not delete existing file. +--XFAIL-- +Pending completion of Unicode streams +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php + + +$filename = dirname(__FILE__)."/touch.dat"; +$fp=fopen($filename,"w"); +fwrite ($fp,"mydata"); +fclose($fp); + +var_dump(touch($filename, 101)); +var_dump(file_get_contents($filename)); + +@unlink($filename); +echo "Done\n"; + +?> +--EXPECT-- +bool(true) +string(6) "mydata" +Done diff --git a/ext/standard/tests/file/touch_variation3-win32.phpt b/ext/standard/tests/file/touch_variation3-win32.phpt new file mode 100644 index 0000000000..fa82b21446 --- /dev/null +++ b/ext/standard/tests/file/touch_variation3-win32.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test touch() function : usage variation - different types for time +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing touch() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'touchVar2.tmp'; +$atime = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for time + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( touch($filename, $value, $atime) ); +}; + +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : usage variation *** + +--float 10.5-- +bool(true) + +--float 12.3456789000e10-- +bool(true) + +--float .5-- +bool(true) + +--empty array-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(true) + +--lowercase null-- +bool(true) + +--lowercase true-- +bool(true) + +--lowercase false-- +bool(true) + +--uppercase TRUE-- +bool(true) + +--uppercase FALSE-- +bool(true) + +--empty string DQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - touch() expects parameter 2 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - touch() expects parameter 2 to be long, object given, %s(%d) +NULL + +--undefined var-- +bool(true) + +--unset var-- +bool(true) +===DONE=== + diff --git a/ext/standard/tests/file/touch_variation3.phpt b/ext/standard/tests/file/touch_variation3.phpt new file mode 100644 index 0000000000..44e173c8b1 --- /dev/null +++ b/ext/standard/tests/file/touch_variation3.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test touch() function : usage variation - different types for time +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing touch() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'touchVar2.tmp'; +$atime = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for time + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( touch($filename, $value, $atime) ); +}; + +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : usage variation *** + +--float 10.5-- +bool(true) + +--float 12.3456789000e10-- +bool(true) + +--float .5-- +bool(true) + +--empty array-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - touch() expects parameter 2 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(true) + +--lowercase null-- +bool(true) + +--lowercase true-- +bool(true) + +--lowercase false-- +bool(true) + +--uppercase TRUE-- +bool(true) + +--uppercase FALSE-- +bool(true) + +--empty string DQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - touch() expects parameter 2 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - touch() expects parameter 2 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - touch() expects parameter 2 to be long, object given, %s(%d) +NULL + +--undefined var-- +bool(true) + +--unset var-- +bool(true) +===DONE=== + diff --git a/ext/standard/tests/file/touch_variation4-win32.phpt b/ext/standard/tests/file/touch_variation4-win32.phpt new file mode 100644 index 0000000000..7680f18035 --- /dev/null +++ b/ext/standard/tests/file/touch_variation4-win32.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test touch() function : usage variation - different types for atime +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing touch() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'touchVar3.tmp'; +$time = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for atime + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( touch($filename, $time, $value) ); +}; + +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : usage variation *** + +--float 10.5-- +bool(true) + +--float 12.3456789000e10-- +bool(true) + +--float .5-- +bool(true) + +--empty array-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(true) + +--lowercase null-- +bool(true) + +--lowercase true-- +bool(true) + +--lowercase false-- +bool(true) + +--uppercase TRUE-- +bool(true) + +--uppercase FALSE-- +bool(true) + +--empty string DQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - touch() expects parameter 3 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - touch() expects parameter 3 to be long, object given, %s(%d) +NULL + +--undefined var-- +bool(true) + +--unset var-- +bool(true) +===DONE=== + diff --git a/ext/standard/tests/file/touch_variation4.phpt b/ext/standard/tests/file/touch_variation4.phpt new file mode 100644 index 0000000000..e1b9f80e0f --- /dev/null +++ b/ext/standard/tests/file/touch_variation4.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test touch() function : usage variation - different types for atime +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +echo "*** Testing touch() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = 'touchVar3.tmp'; +$time = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for atime + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( touch($filename, $time, $value) ); +}; + +unlink($filename); + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : usage variation *** + +--float 10.5-- +bool(true) + +--float 12.3456789000e10-- +bool(true) + +--float .5-- +bool(true) + +--empty array-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - touch() expects parameter 3 to be long, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(true) + +--lowercase null-- +bool(true) + +--lowercase true-- +bool(true) + +--lowercase false-- +bool(true) + +--uppercase TRUE-- +bool(true) + +--uppercase FALSE-- +bool(true) + +--empty string DQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--empty string SQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--string DQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--string SQ-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--mixed case string-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--heredoc-- +Error: 2 - touch() expects parameter 3 to be long, Unicode string given, %s(%d) +NULL + +--instance of classWithToString-- +Error: 2 - touch() expects parameter 3 to be long, object given, %s(%d) +NULL + +--instance of classWithoutToString-- +Error: 2 - touch() expects parameter 3 to be long, object given, %s(%d) +NULL + +--undefined var-- +bool(true) + +--unset var-- +bool(true) +===DONE=== + diff --git a/ext/standard/tests/file/touch_variation5-win32.phpt b/ext/standard/tests/file/touch_variation5-win32.phpt new file mode 100644 index 0000000000..062d5d7d79 --- /dev/null +++ b/ext/standard/tests/file/touch_variation5-win32.phpt @@ -0,0 +1,229 @@ +--TEST-- +Test touch() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +$workDir = "touchVar5.tmp"; +$subDirOrFile = "aSubDirOrFile"; +mkdir($workDir); +$cwd = getcwd(); + +$paths = array( + // relative + $workDir.'/'.$subDirOrFile, + './'.$workDir.'/'.$subDirOrFile, + $workDir.'/../'.$workDir.'/'.$subDirOrFile, + + // relative bad path (note p8 msgs differ) + $workDir.'/../BADDIR/'.$subDirOrFile, + 'BADDIR/'.$subDirOrFile, + + //absolute + $cwd.'/'.$workDir.'/'.$subDirOrFile, + $cwd.'/./'.$workDir.'/'.$subDirOrFile, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDirOrFile, + + //absolute bad path (note p8 msgs differ) + $cwd.'/BADDIR/'.$subDirOrFile, + + //trailing separators + $workDir.'/'.$subDirOrFile.'/', + $cwd.'/'.$workDir.'/'.$subDirOrFile.'/', + + // multiple separators + $workDir.'//'.$subDirOrFile, + $cwd.'//'.$workDir.'//'.$subDirOrFile, + + ); + +echo "*** Testing touch() : variation ***\n"; + +echo "\n*** testing nonexisting paths ***\n"; +test_nonexisting($paths); + +echo "\n*** testing existing files ***\n"; +test_existing($paths, false); + +echo "\n*** testing existing directories ***\n"; +test_existing($paths, true); + + +rmdir($workDir); + + + +function test_nonexisting($paths) { + foreach($paths as $path) { + echo "--- testing $path ---\n"; + + if (is_dir($path) || is_file($path)) { + echo "FAILED: $path - exists\n"; + } + else { + $res = touch($path); + if ($res === true) { + // something was created + if (file_exists($path)) { + // something found + if (is_dir($path)) { + echo "FAILED: $path - unexpected directory\n"; + } + else { + echo "PASSED: $path - created\n"; + unlink($path); + } + } + else { + // nothing found + echo "FAILED: $path - touch returned true, nothing there\n"; + } + } + else { + // nothing created + if (file_exists($path)) { + //something found + echo "FAILED: $path - touch returned false, something there\n"; + if (is_dir($path)) { + rmdir($path); + } + else { + unlink($path); + } + } + } + } + } +} + +function test_existing($paths, $are_dirs) { + foreach($paths as $path) { + if ($are_dirs) { + $res = @mkdir($path); + if ($res == true) { + test_path($path); + rmdir($path); + } + } + else { + $h = @fopen($path,"w"); + if ($h !== false) { + fclose($h); + test_path($path); + unlink($path); + } + } + } +} + + +function test_path($path) { + echo "--- testing $path ---\n"; + $org_atime = get_atime($path); + clearstatcache(); + $res = touch($path,0,0); + $next_atime = get_atime($path); + if ($next_atime == $org_atime) { + echo "FAILED: $path - access time not changed\n"; + } + else { + echo "PASSED: $path - touched\n"; + } +} + +function get_atime($path) { + $temp = stat($path); + return $temp['atime']; +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : variation *** + +*** testing nonexisting paths *** +--- testing touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/aSubDirOrFile - created +--- testing ./touchVar5.tmp/aSubDirOrFile --- +PASSED: ./touchVar5.tmp/aSubDirOrFile - created +--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created +--- testing touchVar5.tmp/../BADDIR/aSubDirOrFile --- + +Warning: touch(): Unable to create file touchVar5.tmp/../BADDIR/aSubDirOrFile because No such file or directory in %s on line %d +--- testing BADDIR/aSubDirOrFile --- + +Warning: touch(): Unable to create file BADDIR/aSubDirOrFile because No such file or directory in %s on line %d +--- testing %s/touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile - created +--- testing %s/./touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/./touchVar5.tmp/aSubDirOrFile - created +--- testing %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created +--- testing %s/BADDIR/aSubDirOrFile --- + +Warning: touch(): Unable to create file %s/BADDIR/aSubDirOrFile because No such file or directory in %s on line %d +--- testing touchVar5.tmp/aSubDirOrFile/ --- + +Warning: touch(): Unable to create file touchVar5.tmp/aSubDirOrFile/ because Invalid argument in %s on line %d +--- testing %s/touchVar5.tmp/aSubDirOrFile/ --- + +Warning: touch(): Unable to create file %s/touchVar5.tmp/aSubDirOrFile/ because Invalid argument in %s on line %d +--- testing touchVar5.tmp//aSubDirOrFile --- +PASSED: touchVar5.tmp//aSubDirOrFile - created +--- testing %s//touchVar5.tmp//aSubDirOrFile --- +PASSED: %s//touchVar5.tmp//aSubDirOrFile - created + +*** testing existing files *** +--- testing touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/aSubDirOrFile - touched +--- testing ./touchVar5.tmp/aSubDirOrFile --- +PASSED: ./touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing %s/touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile - touched +--- testing %s/./touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/./touchVar5.tmp/aSubDirOrFile - touched +--- testing %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp//aSubDirOrFile --- +PASSED: touchVar5.tmp//aSubDirOrFile - touched +--- testing %s//touchVar5.tmp//aSubDirOrFile --- +PASSED: %s//touchVar5.tmp//aSubDirOrFile - touched + +*** testing existing directories *** +--- testing touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/aSubDirOrFile - touched +--- testing ./touchVar5.tmp/aSubDirOrFile --- +PASSED: ./touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing %s/touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile - touched +--- testing %s/./touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/./touchVar5.tmp/aSubDirOrFile - touched +--- testing %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp/aSubDirOrFile/ --- +PASSED: touchVar5.tmp/aSubDirOrFile/ - touched +--- testing %s/touchVar5.tmp/aSubDirOrFile/ --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile/ - touched +--- testing touchVar5.tmp//aSubDirOrFile --- +PASSED: touchVar5.tmp//aSubDirOrFile - touched +--- testing %s//touchVar5.tmp//aSubDirOrFile --- +PASSED: %s//touchVar5.tmp//aSubDirOrFile - touched +===DONE=== + diff --git a/ext/standard/tests/file/touch_variation5.phpt b/ext/standard/tests/file/touch_variation5.phpt new file mode 100644 index 0000000000..f0e1f78691 --- /dev/null +++ b/ext/standard/tests/file/touch_variation5.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test touch() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +$workDir = "touchVar5.tmp"; +$subDirOrFile = "aSubDirOrFile"; +mkdir($workDir); +$cwd = getcwd(); + +$paths = array( + // relative + $workDir.'/'.$subDirOrFile, + './'.$workDir.'/'.$subDirOrFile, + $workDir.'/../'.$workDir.'/'.$subDirOrFile, + + // relative bad path + $workDir.'/../BADDIR/'.$subDirOrFile, + 'BADDIR/'.$subDirOrFile, + + //absolute + $cwd.'/'.$workDir.'/'.$subDirOrFile, + $cwd.'/./'.$workDir.'/'.$subDirOrFile, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDirOrFile, + + //absolute bad path + $cwd.'/BADDIR/'.$subDirOrFile, + + //trailing separators + $workDir.'/'.$subDirOrFile.'/', + $cwd.'/'.$workDir.'/'.$subDirOrFile.'/', + + // multiple separators + $workDir.'//'.$subDirOrFile, + $cwd.'//'.$workDir.'//'.$subDirOrFile, + + ); + +echo "*** Testing touch() : variation ***\n"; + +echo "\n*** testing nonexisting paths ***\n"; +test_nonexisting($paths); + +echo "\n*** testing existing files ***\n"; +test_existing($paths, false); + +echo "\n*** testing existing directories ***\n"; +test_existing($paths, true); + + +rmdir($workDir); + + + +function test_nonexisting($paths) { + foreach($paths as $path) { + echo "--- testing $path ---\n"; + + if (is_dir($path) || is_file($path)) { + echo "FAILED: $path - exists\n"; + } + else { + $res = touch($path); + if ($res === true) { + // something was created + if (file_exists($path)) { + // something found + if (is_dir($path)) { + echo "FAILED: $path - unexpected directory\n"; + } + else { + echo "PASSED: $path - created\n"; + unlink($path); + } + } + else { + // nothing found + echo "FAILED: $path - touch returned true, nothing there\n"; + } + } + else { + // nothing created + if (file_exists($path)) { + //something found + echo "FAILED: $path - touch returned false, something there\n"; + if (is_dir($path)) { + rmdir($path); + } + else { + unlink($path); + } + } + } + } + } +} + +function test_existing($paths, $are_dirs) { + foreach($paths as $path) { + if ($are_dirs) { + $res = @mkdir($path); + if ($res == true) { + test_path($path); + rmdir($path); + } + } + else { + $h = @fopen($path,"w"); + if ($h !== false) { + fclose($h); + test_path($path); + unlink($path); + } + } + } +} + + +function test_path($path) { + echo "--- testing $path ---\n"; + $org_atime = get_atime($path); + clearstatcache(); + $res = touch($path,0,0); + $next_atime = get_atime($path); + if ($next_atime == $org_atime) { + echo "FAILED: $path - access time not changed\n"; + } + else { + echo "PASSED: $path - touched\n"; + } +} + +function get_atime($path) { + $temp = stat($path); + return $temp['atime']; +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : variation *** + +*** testing nonexisting paths *** +--- testing touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/aSubDirOrFile - created +--- testing ./touchVar5.tmp/aSubDirOrFile --- +PASSED: ./touchVar5.tmp/aSubDirOrFile - created +--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created +--- testing touchVar5.tmp/../BADDIR/aSubDirOrFile --- + +Warning: touch(): Unable to create file touchVar5.tmp/../BADDIR/aSubDirOrFile because %s in %s on line %d +--- testing BADDIR/aSubDirOrFile --- + +Warning: touch(): Unable to create file BADDIR/aSubDirOrFile because %s in %s on line %d +--- testing /%s/touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/touchVar5.tmp/aSubDirOrFile - created +--- testing /%s/./touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/./touchVar5.tmp/aSubDirOrFile - created +--- testing /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - created +--- testing /%s/BADDIR/aSubDirOrFile --- + +Warning: touch(): Unable to create file /%s/BADDIR/aSubDirOrFile because %s in %s on line %d +--- testing touchVar5.tmp/aSubDirOrFile/ --- + +Warning: touch(): Unable to create file touchVar5.tmp/aSubDirOrFile/ because Is a directory in %s on line %d +--- testing /%s/touchVar5.tmp/aSubDirOrFile/ --- + +Warning: touch(): Unable to create file /%s/touchVar5.tmp/aSubDirOrFile/ because Is a directory in %s on line %d +--- testing touchVar5.tmp//aSubDirOrFile --- +PASSED: touchVar5.tmp//aSubDirOrFile - created +--- testing /%s//touchVar5.tmp//aSubDirOrFile --- +PASSED: /%s//touchVar5.tmp//aSubDirOrFile - created + +*** testing existing files *** +--- testing touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/aSubDirOrFile - touched +--- testing ./touchVar5.tmp/aSubDirOrFile --- +PASSED: ./touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing /%s/touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched +--- testing /%s/./touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/./touchVar5.tmp/aSubDirOrFile - touched +--- testing /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp//aSubDirOrFile --- +PASSED: touchVar5.tmp//aSubDirOrFile - touched +--- testing /%s//touchVar5.tmp//aSubDirOrFile --- +PASSED: /%s//touchVar5.tmp//aSubDirOrFile - touched + +*** testing existing directories *** +--- testing touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/aSubDirOrFile - touched +--- testing ./touchVar5.tmp/aSubDirOrFile --- +PASSED: ./touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing /%s/touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/touchVar5.tmp/aSubDirOrFile - touched +--- testing /%s/./touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/./touchVar5.tmp/aSubDirOrFile - touched +--- testing /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile --- +PASSED: /%s/touchVar5.tmp/../touchVar5.tmp/aSubDirOrFile - touched +--- testing touchVar5.tmp/aSubDirOrFile/ --- +PASSED: touchVar5.tmp/aSubDirOrFile/ - touched +--- testing /%s/touchVar5.tmp/aSubDirOrFile/ --- +PASSED: /%s/touchVar5.tmp/aSubDirOrFile/ - touched +--- testing touchVar5.tmp//aSubDirOrFile --- +PASSED: touchVar5.tmp//aSubDirOrFile - touched +--- testing /%s//touchVar5.tmp//aSubDirOrFile --- +PASSED: /%s//touchVar5.tmp//aSubDirOrFile - touched +===DONE=== + diff --git a/ext/standard/tests/file/touch_variation6-win32.phpt b/ext/standard/tests/file/touch_variation6-win32.phpt new file mode 100644 index 0000000000..3d0ee92326 --- /dev/null +++ b/ext/standard/tests/file/touch_variation6-win32.phpt @@ -0,0 +1,241 @@ +--TEST-- +Test touch() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool touch(string filename [, int time [, int atime]]) + * Description: Set modification time of file + * Source code: ext/standard/filestat.c + * Alias to functions: + */ + +$workDir = "touchVar5.tmp"; +$subDirOrFile = "aSubDirOrFile"; +mkdir($workDir); +$cwd = getcwd(); + +$unixifiedDirOrFile = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$subDirOrFile, 3); + +$paths = array( + // relative + $workDir.'\\'.$subDirOrFile, + '.\\'.$workDir.'\\'.$subDirOrFile, + $workDir.'\\..\\'.$workDir.'\\'.$subDirOrFile, + + // relative bad path (note p8 msgs differ) + $workDir.'\\..\\BADDIR\\'.$subDirOrFile, + 'BADDIR\\'.$subDirOrFile, + + //absolute + $cwd.'\\'.$workDir.'\\'.$subDirOrFile, + $cwd.'\\.\\'.$workDir.'\\'.$subDirOrFile, + $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$subDirOrFile, + + //absolute bad path (note p8 msgs differ) + $cwd.'\\BADDIR\\'.$subDirOrFile, + + //trailing separators + $workDir.'\\'.$subDirOrFile.'\\', + $cwd.'\\'.$workDir.'\\'.$subDirOrFile.'\\', + + // multiple separators + $workDir.'\\\\'.$subDirOrFile, + $cwd.'\\\\'.$workDir.'\\\\'.$subDirOrFile, + + // Unixified Dir Or File + $unixifiedDirOrFile, + + ); + +echo "*** Testing touch() : variation ***\n"; + +echo "\n*** testing nonexisting paths ***\n"; +test_nonexisting($paths); + +echo "\n*** testing existing files ***\n"; +test_existing($paths, false); + +echo "\n*** testing existing directories ***\n"; +test_existing($paths, true); + + +rmdir($workDir); + + + +function test_nonexisting($paths) { + foreach($paths as $path) { + echo "--- testing $path ---\n"; + + if (is_dir($path) || is_file($path)) { + echo "FAILED: $path - exists\n"; + } + else { + $res = touch($path); + if ($res === true) { + // something was created + if (file_exists($path)) { + // something found + if (is_dir($path)) { + echo "FAILED: $path - unexpected directory\n"; + } + else { + echo "PASSED: $path - created\n"; + unlink($path); + } + } + else { + // nothing found + echo "FAILED: $path - touch returned true, nothing there\n"; + } + } + else { + // nothing created + if (file_exists($path)) { + //something found + echo "FAILED: $path - touch returned false, something there\n"; + if (is_dir($path)) { + rmdir($path); + } + else { + unlink($path); + } + } + } + } + } +} + +function test_existing($paths, $are_dirs) { + foreach($paths as $path) { + if ($are_dirs) { + $res = @mkdir($path); + if ($res == true) { + test_path($path); + rmdir($path); + } + } + else { + $h = @fopen($path,"w"); + if ($h !== false) { + fclose($h); + test_path($path); + unlink($path); + } + } + } +} + + +function test_path($path) { + echo "--- testing $path ---\n"; + $org_atime = get_atime($path); + clearstatcache(); + $res = touch($path,0,0); + $next_atime = get_atime($path); + if ($next_atime == $org_atime) { + echo "FAILED: $path - access time not changed\n"; + } + else { + echo "PASSED: $path - touched\n"; + } +} + +function get_atime($path) { + $temp = stat($path); + return $temp['atime']; +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing touch() : variation *** + +*** testing nonexisting paths *** +--- testing touchVar5.tmp\aSubDirOrFile --- +PASSED: touchVar5.tmp\aSubDirOrFile - created +--- testing .\touchVar5.tmp\aSubDirOrFile --- +PASSED: .\touchVar5.tmp\aSubDirOrFile - created +--- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile --- +PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - created +--- testing touchVar5.tmp\..\BADDIR\aSubDirOrFile --- + +Warning: touch(): Unable to create file touchVar5.tmp\..\BADDIR\aSubDirOrFile because No such file or directory in %s on line %d +--- testing BADDIR\aSubDirOrFile --- + +Warning: touch(): Unable to create file BADDIR\aSubDirOrFile because No such file or directory in %s on line %d +--- testing %s\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\touchVar5.tmp\aSubDirOrFile - created +--- testing %s\.\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - created +--- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - created +--- testing %s\BADDIR\aSubDirOrFile --- + +Warning: touch(): Unable to create file %s\BADDIR\aSubDirOrFile because No such file or directory in %s on line %d +--- testing touchVar5.tmp\aSubDirOrFile\ --- + +Warning: touch(): Unable to create file touchVar5.tmp\aSubDirOrFile\ because Invalid argument in %s on line %d +--- testing %s\touchVar5.tmp\aSubDirOrFile\ --- + +Warning: touch(): Unable to create file %s\touchVar5.tmp\aSubDirOrFile\ because Invalid argument in %s on line %d +--- testing touchVar5.tmp\\aSubDirOrFile --- +PASSED: touchVar5.tmp\\aSubDirOrFile - created +--- testing %s\\touchVar5.tmp\\aSubDirOrFile --- +PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - created +--- testing %s/touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile - created + +*** testing existing files *** +--- testing touchVar5.tmp\aSubDirOrFile --- +PASSED: touchVar5.tmp\aSubDirOrFile - touched +--- testing .\touchVar5.tmp\aSubDirOrFile --- +PASSED: .\touchVar5.tmp\aSubDirOrFile - touched +--- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile --- +PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched +--- testing %s\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\touchVar5.tmp\aSubDirOrFile - touched +--- testing %s\.\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - touched +--- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched +--- testing touchVar5.tmp\\aSubDirOrFile --- +PASSED: touchVar5.tmp\\aSubDirOrFile - touched +--- testing %s\\touchVar5.tmp\\aSubDirOrFile --- +PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - touched +--- testing %s/touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile - touched + +*** testing existing directories *** +--- testing touchVar5.tmp\aSubDirOrFile --- +PASSED: touchVar5.tmp\aSubDirOrFile - touched +--- testing .\touchVar5.tmp\aSubDirOrFile --- +PASSED: .\touchVar5.tmp\aSubDirOrFile - touched +--- testing touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile --- +PASSED: touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched +--- testing %s\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\touchVar5.tmp\aSubDirOrFile - touched +--- testing %s\.\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\.\touchVar5.tmp\aSubDirOrFile - touched +--- testing %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile --- +PASSED: %s\touchVar5.tmp\..\touchVar5.tmp\aSubDirOrFile - touched +--- testing touchVar5.tmp\aSubDirOrFile\ --- +PASSED: touchVar5.tmp\aSubDirOrFile\ - touched +--- testing %s\touchVar5.tmp\aSubDirOrFile\ --- +PASSED: %s\touchVar5.tmp\aSubDirOrFile\ - touched +--- testing touchVar5.tmp\\aSubDirOrFile --- +PASSED: touchVar5.tmp\\aSubDirOrFile - touched +--- testing %s\\touchVar5.tmp\\aSubDirOrFile --- +PASSED: %s\\touchVar5.tmp\\aSubDirOrFile - touched +--- testing %s/touchVar5.tmp/aSubDirOrFile --- +PASSED: %s/touchVar5.tmp/aSubDirOrFile - touched +===DONE=== + diff --git a/ext/standard/tests/file/umask_variation3.phpt b/ext/standard/tests/file/umask_variation3.phpt new file mode 100644 index 0000000000..91d80c9262 --- /dev/null +++ b/ext/standard/tests/file/umask_variation3.phpt @@ -0,0 +1,239 @@ +--TEST-- +Test umask() function : usage variation +--XFAIL-- +Return values are inconsistent (and have changed from previous versions) +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. only for Non Windows'); +} +?> +--FILE-- +<?php +/* Prototype : int umask([int mask]) + * Description: Return or change the umask + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing umask() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + //out of boundary integers + 'int -100' => -100, + 'int 99999' => 99999, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + //'float -12.3456789000e10' => -12.3456789000e10, different in p8 + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for mask + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + umask(0); + var_dump(umask($value)); + var_dump( umask()); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing umask() : usage variation *** + +--int -100-- +int(0) +int(412) + +--int 99999-- +int(0) +int(159) + +--float 10.5-- +int(0) +int(10) + +--float -10.5-- +int(0) +int(502) + +--float 12.3456789000e10-- +int(0) +int(%d) + +--float .5-- +int(0) +int(0) + +--empty array-- +Error: 2 - umask() expects parameter 1 to be long, array given, %s(%d) +bool(false) +int(63) + +--int indexed array-- +Error: 2 - umask() expects parameter 1 to be long, array given, %s(%d) +bool(false) +int(63) + +--associative array-- +Error: 2 - umask() expects parameter 1 to be long, array given, %s(%d) +bool(false) +int(63) + +--nested arrays-- +Error: 2 - umask() expects parameter 1 to be long, array given, %s(%d) +bool(false) +int(63) + +--uppercase NULL-- +int(0) +int(0) + +--lowercase null-- +int(0) +int(0) + +--lowercase true-- +int(0) +int(1) + +--lowercase false-- +int(0) +int(0) + +--uppercase TRUE-- +int(0) +int(1) + +--uppercase FALSE-- +int(0) +int(0) + +--empty string DQ-- +Error: 2 - umask() expects parameter 1 to be long, Unicode string given, %s(%d) +bool(false) +int(63) + +--empty string SQ-- +Error: 2 - umask() expects parameter 1 to be long, Unicode string given, %s(%d) +bool(false) +int(63) + +--string DQ-- +Error: 2 - umask() expects parameter 1 to be long, Unicode string given, %s(%d) +bool(false) +int(63) + +--string SQ-- +Error: 2 - umask() expects parameter 1 to be long, Unicode string given, %s(%d) +bool(false) +int(63) + +--mixed case string-- +Error: 2 - umask() expects parameter 1 to be long, Unicode string given, %s(%d) +bool(false) +int(63) + +--heredoc-- +Error: 2 - umask() expects parameter 1 to be long, Unicode string given, %s(%d) +bool(false) +int(63) + +--instance of classWithToString-- +Error: 2 - umask() expects parameter 1 to be long, object given, %s(%d) +bool(false) +int(63) + +--instance of classWithoutToString-- +Error: 2 - umask() expects parameter 1 to be long, object given, %s(%d) +bool(false) +int(63) + +--undefined var-- +int(0) +int(0) + +--unset var-- +int(0) +int(0) +===DONE=== + diff --git a/ext/standard/tests/file/unlink_variation10.phpt b/ext/standard/tests/file/unlink_variation10.phpt new file mode 100644 index 0000000000..e0c92caeba --- /dev/null +++ b/ext/standard/tests/file/unlink_variation10.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test unlink() function : variation: unlinking directories +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool unlink(string filename[, context context]) + * Description: Delete a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing unlink() : variation ***\n"; + +$workDir = "unlinkVar8.tmp"; +$tmpDir = "subDir.tmp"; +$dirToLinkTo = $workDir.'/'."linkme.tmp"; + +mkdir($workDir); +$cwd = getcwd(); +mkdir($dirToLinkTo); + +$dirs = array( + // relative + $workDir.'/'.$tmpDir, + './'.$workDir.'/'.$tmpDir, + $workDir.'/../'.$workDir.'/'.$tmpDir, + + //absolute + $cwd.'/'.$workDir.'/'.$tmpDir, + $cwd.'/./'.$workDir.'/'.$tmpDir, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpDir, + + // multiple separators + $workDir.'//'.$tmpDir, + $cwd.'//'.$workDir.'//'.$tmpDir, + + ); + + +foreach($dirs as $dirToUnlink) { + test_link($workDir.'/'.$tmpDir, $dirToLinkTo, $dirToUnlink, true); //soft link + //cannot test hard links unless you are root. +} + +echo "\n--- try to unlink a directory ---\n"; +unlink($dirToLinkTo); +rmdir($dirToLinkTo); +rmdir($workDir); + +function test_link($linkedDir, $toLinkTo, $tounlink, $softlink) { + if ($softlink == true) { + symlink($toLinkTo, $linkedDir); + $msg = "soft link"; + } + else { + link($toLinkTo, $linkedDir); + $msg = "hard link"; + } + echo "-- unlinking $msg $tounlink --\n"; + $res = unlink($tounlink); + if ($res === true) { + if (is_link($tounlink) === false) { + echo "directory unlinked\n"; + } + else { + echo "FAILED: directory not unlinked\n"; + } + } + else { + unlink($linkedDir); + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing unlink() : variation *** +-- unlinking soft link unlinkVar8.tmp/subDir.tmp -- +directory unlinked +-- unlinking soft link ./unlinkVar8.tmp/subDir.tmp -- +directory unlinked +-- unlinking soft link unlinkVar8.tmp/../unlinkVar8.tmp/subDir.tmp -- +directory unlinked +-- unlinking soft link /%s/unlinkVar8.tmp/subDir.tmp -- +directory unlinked +-- unlinking soft link /%s/./unlinkVar8.tmp/subDir.tmp -- +directory unlinked +-- unlinking soft link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/subDir.tmp -- +directory unlinked +-- unlinking soft link unlinkVar8.tmp//subDir.tmp -- +directory unlinked +-- unlinking soft link /%s//unlinkVar8.tmp//subDir.tmp -- +directory unlinked + +--- try to unlink a directory --- + +Warning: unlink(unlinkVar8.tmp/linkme.tmp): %s in %s on line %d +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/unlink_variation6.phpt b/ext/standard/tests/file/unlink_variation6.phpt new file mode 100644 index 0000000000..ede9ada092 --- /dev/null +++ b/ext/standard/tests/file/unlink_variation6.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test unlink() function : variation +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool unlink(string filename[, context context]) + * Description: Delete a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing unlink() : variation: contexts and relative files ***\n"; + +// test relative directories and stream contexts. +$subdir = 'subdir'; +$testfile = $subdir.'/testfile.txt'; +mkdir($subdir); +touch($testfile); +f_exists($testfile); +$context = stream_context_create(); +var_dump(unlink($testfile, $context)); +f_exists($testfile); +rmdir($subdir); + +function f_exists($file) { + if (file_exists($file) == true) { + echo "$file exists\n"; + } + else { + echo "$file doesn't exist\n"; + } +} +?> +===DONE=== +--EXPECTF-- +*** Testing unlink() : variation: contexts and relative files *** +subdir/testfile.txt exists +bool(true) +subdir/testfile.txt doesn't exist +===DONE=== diff --git a/ext/standard/tests/file/unlink_variation7.phpt b/ext/standard/tests/file/unlink_variation7.phpt new file mode 100644 index 0000000000..aa7d291f26 --- /dev/null +++ b/ext/standard/tests/file/unlink_variation7.phpt @@ -0,0 +1,246 @@ +--TEST-- +Test unlink() function : usage variation different types for context +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--FILE-- +<?php +/* Prototype : bool unlink(string filename[, context context]) + * Description: Delete a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing unlink() : usage variation different types for context ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$filename = __FILE__.'tmp'; +$fileRes = fopen(__FILE__, 'r'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // file resource + 'file resource' => $fileRes +); + +// loop through each element of the array for context + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + touch($filename); // create if it doesn't exist + var_dump( unlink($filename, $value) ); +}; + +if (file_exists($filename)) { + unlink($filename); +} +fclose($fileRes); + +?> +===DONE=== +--EXPECTF-- +*** Testing unlink() : usage variation different types for context *** + +--int 0-- +Error: 2 - unlink() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--int 1-- +Error: 2 - unlink() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--int 12345-- +Error: 2 - unlink() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--int -12345-- +Error: 2 - unlink() expects parameter 2 to be resource, integer given, %s(%d) +bool(false) + +--float 10.5-- +Error: 2 - unlink() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float -10.5-- +Error: 2 - unlink() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - unlink() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - unlink() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--float .5-- +Error: 2 - unlink() expects parameter 2 to be resource, double given, %s(%d) +bool(false) + +--empty array-- +Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--int indexed array-- +Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--associative array-- +Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--nested arrays-- +Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--lowercase null-- +Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--lowercase true-- +Error: 2 - unlink() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--lowercase false-- +Error: 2 - unlink() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - unlink() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - unlink() expects parameter 2 to be resource, boolean given, %s(%d) +bool(false) + +--empty string DQ-- +Error: 2 - unlink() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--empty string SQ-- +Error: 2 - unlink() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--string DQ-- +Error: 2 - unlink() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--string SQ-- +Error: 2 - unlink() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--mixed case string-- +Error: 2 - unlink() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--heredoc-- +Error: 2 - unlink() expects parameter 2 to be resource, Unicode string given, %s(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - unlink() expects parameter 2 to be resource, object given, %s(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - unlink() expects parameter 2 to be resource, object given, %s(%d) +bool(false) + +--undefined var-- +Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--unset var-- +Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) +bool(false) + +--file resource-- +Error: 2 - unlink(): supplied resource is not a valid Stream-Context resource, %s(%d) +bool(true) +===DONE=== diff --git a/ext/standard/tests/file/unlink_variation8-win32.phpt b/ext/standard/tests/file/unlink_variation8-win32.phpt new file mode 100644 index 0000000000..5348676e40 --- /dev/null +++ b/ext/standard/tests/file/unlink_variation8-win32.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test unlink() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool unlink(string filename[, context context]) + * Description: Delete a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing unlink() : variation ***\n"; + +$workDir = "unlinkVar8.tmp"; +$tmpFile = "file.tmp"; +mkdir($workDir); +$cwd = getcwd(); + +$files = array( + // relative + $workDir.'/'.$tmpFile, + './'.$workDir.'/'.$tmpFile, + $workDir.'/../'.$workDir.'/'.$tmpFile, + + // relative bad path + $workDir.'/../BADDIR/'.$tmpFile, + 'BADDIR/'.$tmpFile, + + //absolute + $cwd.'/'.$workDir.'/'.$tmpFile, + $cwd.'/./'.$workDir.'/'.$tmpFile, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpFile, + + //absolute bad path + $cwd.'/BADDIR/'.$tmpFile, + + //trailing separators + $workDir.'/'.$tmpFile.'/', + $cwd.'/'.$workDir.'/'.$tmpFile.'/', + + // multiple separators + $workDir.'//'.$tmpFile, + $cwd.'//'.$workDir.'//'.$tmpFile, + + ); + + +foreach($files as $fileToUnlink) { + test_realfile($workDir.'/'.$tmpFile, $fileToUnlink); +} + +rmdir($workDir); + +function test_realfile($file, $tounlink) { + touch($file); + echo "-- removing $tounlink --\n"; + $res = unlink($tounlink); + if ($res === true) { + if (file_exists($tounlink) === false) { + echo "file removed\n"; + } + else { + echo "FAILED: file not removed\n"; + } + } + else { + unlink($file); + } +} +?> +===DONE=== +--EXPECTF-- +*** Testing unlink() : variation *** +-- removing unlinkVar8.tmp/file.tmp -- +file removed +-- removing ./unlinkVar8.tmp/file.tmp -- +file removed +-- removing unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file removed +-- removing unlinkVar8.tmp/../BADDIR/file.tmp -- + +Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d +-- removing BADDIR/file.tmp -- + +Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d +-- removing %s/unlinkVar8.tmp/file.tmp -- +file removed +-- removing %s/./unlinkVar8.tmp/file.tmp -- +file removed +-- removing %s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file removed +-- removing %s/BADDIR/file.tmp -- + +Warning: unlink(%s/BADDIR/file.tmp): No such file or directory in %s on line %d +-- removing unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(unlinkVar8.tmp/file.tmp/): Invalid argument in %s on line %d +-- removing %s/unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(%s/unlinkVar8.tmp/file.tmp/): Invalid argument in %s on line %d +-- removing unlinkVar8.tmp//file.tmp -- +file removed +-- removing %s//unlinkVar8.tmp//file.tmp -- +file removed +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/unlink_variation8.phpt b/ext/standard/tests/file/unlink_variation8.phpt new file mode 100644 index 0000000000..e87a584f5b --- /dev/null +++ b/ext/standard/tests/file/unlink_variation8.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test unlink() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool unlink(string filename[, context context]) + * Description: Delete a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing unlink() : variation ***\n"; + +$workDir = "unlinkVar8.tmp"; +$tmpFile = "file.tmp"; +$fileToLinkTo = $workDir.'/'."linkme.tmp"; + +mkdir($workDir); +$cwd = getcwd(); +touch($fileToLinkTo); + +$files = array( + // relative + $workDir.'/'.$tmpFile, + './'.$workDir.'/'.$tmpFile, + $workDir.'/../'.$workDir.'/'.$tmpFile, + + // relative bad path + $workDir.'/../BADDIR/'.$tmpFile, + 'BADDIR/'.$tmpFile, + + //absolute + $cwd.'/'.$workDir.'/'.$tmpFile, + $cwd.'/./'.$workDir.'/'.$tmpFile, + $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpFile, + + //absolute bad path + $cwd.'/BADDIR/'.$tmpFile, + + //trailing separators + $workDir.'/'.$tmpFile.'/', + $cwd.'/'.$workDir.'/'.$tmpFile.'/', + + // multiple separators + $workDir.'//'.$tmpFile, + $cwd.'//'.$workDir.'//'.$tmpFile, + + ); + + +foreach($files as $fileToUnlink) { + test_realfile($workDir.'/'.$tmpFile, $fileToUnlink); + test_link($workDir.'/'.$tmpFile, $fileToLinkTo, $fileToUnlink, true); //soft link + test_link($workDir.'/'.$tmpFile, $fileToLinkTo, $fileToUnlink, false); //hard link +} + +unlink($fileToLinkTo); +rmdir($workDir); + +function test_realfile($file, $tounlink) { + touch($file); + echo "-- removing $tounlink --\n"; + $res = unlink($tounlink); + if ($res === true) { + if (file_exists($tounlink) === false) { + echo "file removed\n"; + } + else { + echo "FAILED: file not removed\n"; + } + } + else { + unlink($file); + } +} + +function test_link($linkedfile, $toLinkTo, $tounlink, $softlink) { + if ($softlink == true) { + symlink($toLinkTo, $linkedfile); + $msg = "soft link"; + } + else { + link($toLinkTo, $linkedfile); + $msg = "hard link"; + } + echo "-- unlinking $msg $tounlink --\n"; + $res = unlink($tounlink); + if ($res === true) { + if (file_exists($tounlink) === false) { + echo "file unlinked\n"; + } + else { + echo "FAILED: file not unlinked\n"; + } + } + else { + unlink($linkedfile); + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing unlink() : variation *** +-- removing unlinkVar8.tmp/file.tmp -- +file removed +-- unlinking soft link unlinkVar8.tmp/file.tmp -- +file unlinked +-- unlinking hard link unlinkVar8.tmp/file.tmp -- +file unlinked +-- removing ./unlinkVar8.tmp/file.tmp -- +file removed +-- unlinking soft link ./unlinkVar8.tmp/file.tmp -- +file unlinked +-- unlinking hard link ./unlinkVar8.tmp/file.tmp -- +file unlinked +-- removing unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file removed +-- unlinking soft link unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file unlinked +-- unlinking hard link unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file unlinked +-- removing unlinkVar8.tmp/../BADDIR/file.tmp -- + +Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d +-- unlinking soft link unlinkVar8.tmp/../BADDIR/file.tmp -- + +Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d +-- unlinking hard link unlinkVar8.tmp/../BADDIR/file.tmp -- + +Warning: unlink(unlinkVar8.tmp/../BADDIR/file.tmp): No such file or directory in %s on line %d +-- removing BADDIR/file.tmp -- + +Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d +-- unlinking soft link BADDIR/file.tmp -- + +Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d +-- unlinking hard link BADDIR/file.tmp -- + +Warning: unlink(BADDIR/file.tmp): No such file or directory in %s on line %d +-- removing /%s/unlinkVar8.tmp/file.tmp -- +file removed +-- unlinking soft link /%s/unlinkVar8.tmp/file.tmp -- +file unlinked +-- unlinking hard link /%s/unlinkVar8.tmp/file.tmp -- +file unlinked +-- removing /%s/./unlinkVar8.tmp/file.tmp -- +file removed +-- unlinking soft link /%s/./unlinkVar8.tmp/file.tmp -- +file unlinked +-- unlinking hard link /%s/./unlinkVar8.tmp/file.tmp -- +file unlinked +-- removing /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file removed +-- unlinking soft link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file unlinked +-- unlinking hard link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/file.tmp -- +file unlinked +-- removing /%s/BADDIR/file.tmp -- + +Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d +-- unlinking soft link /%s/BADDIR/file.tmp -- + +Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d +-- unlinking hard link /%s/BADDIR/file.tmp -- + +Warning: unlink(/%s/BADDIR/file.tmp): No such file or directory in %s on line %d +-- removing unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d +-- unlinking soft link unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d +-- unlinking hard link unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d +-- removing /%s/unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d +-- unlinking soft link /%s/unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d +-- unlinking hard link /%s/unlinkVar8.tmp/file.tmp/ -- + +Warning: unlink(/%s/unlinkVar8.tmp/file.tmp/): Not a directory in %s on line %d +-- removing unlinkVar8.tmp//file.tmp -- +file removed +-- unlinking soft link unlinkVar8.tmp//file.tmp -- +file unlinked +-- unlinking hard link unlinkVar8.tmp//file.tmp -- +file unlinked +-- removing /%s//unlinkVar8.tmp//file.tmp -- +file removed +-- unlinking soft link /%s//unlinkVar8.tmp//file.tmp -- +file unlinked +-- unlinking hard link /%s//unlinkVar8.tmp//file.tmp -- +file unlinked +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/file/unlink_variation9-win32.phpt b/ext/standard/tests/file/unlink_variation9-win32.phpt new file mode 100644 index 0000000000..4f1a8bb8d3 --- /dev/null +++ b/ext/standard/tests/file/unlink_variation9-win32.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test unlink() function : variation: various valid and invalid paths +--CREDITS-- +Dave Kelsey <d_kelsey@uk.ibm.com> +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype : bool unlink(string filename[, context context]) + * Description: Delete a file + * Source code: ext/standard/file.c + * Alias to functions: + */ + +echo "*** Testing unlink() : variation ***\n"; + +$workDir = "unlinkVar9.tmp"; +$tmpFile = "file.tmp"; +mkdir($workDir); +$cwd = getcwd(); +$unixifiedFile = '/'.substr(str_replace('\\','/',$cwd).'/'.$workDir.'/'.$tmpFile, 3); + +$files = array( + // relative + $workDir.'\\'.$tmpFile, + '.\\'.$workDir.'\\'.$tmpFile, + $workDir.'\\..\\'.$workDir.'\\'.$tmpFile, + + // relative bad path + $workDir.'\\..\\BADDIR\\'.$tmpFile, + 'BADDIR\\'.$tmpFile, + + //absolute + $cwd.'\\'.$workDir.'\\'.$tmpFile, + $cwd.'\\.\\'.$workDir.'\\'.$tmpFile, + $cwd.'\\'.$workDir.'\\..\\'.$workDir.'\\'.$tmpFile, + + //absolute bad path + $cwd.'\\BADDIR\\'.$tmpFile, + + //trailing separators + $workDir.'\\'.$tmpFile.'\\', + $cwd.'\\'.$workDir.'\\'.$tmpFile.'\\', + + // multiple separators + $workDir.'\\\\'.$tmpFile, + $cwd.'\\\\'.$workDir.'\\\\'.$tmpFile, + + // Unixified File + $unixifiedFile, + + ); + + +foreach($files as $fileToUnlink) { + test_realfile($workDir.'/'.$tmpFile, $fileToUnlink); +} + +rmdir($workDir); + +function test_realfile($file, $tounlink) { + touch($file); + echo "-- removing $tounlink --\n"; + $res = unlink($tounlink); + if ($res === true) { + if (file_exists($tounlink) === false) { + echo "file removed\n"; + } + else { + echo "FAILED: file not removed\n"; + } + } + else { + unlink($file); + } +} + + +?> +===DONE=== +--EXPECTF-- +*** Testing unlink() : variation *** +-- removing unlinkVar9.tmp\file.tmp -- +file removed +-- removing .\unlinkVar9.tmp\file.tmp -- +file removed +-- removing unlinkVar9.tmp\..\unlinkVar9.tmp\file.tmp -- +file removed +-- removing unlinkVar9.tmp\..\BADDIR\file.tmp -- + +Warning: unlink(unlinkVar9.tmp\..\BADDIR\file.tmp): No such file or directory in %s on line %d +-- removing BADDIR\file.tmp -- + +Warning: unlink(BADDIR\file.tmp): No such file or directory in %s on line %d +-- removing %s\unlinkVar9.tmp\file.tmp -- +file removed +-- removing %s\.\unlinkVar9.tmp\file.tmp -- +file removed +-- removing %s\unlinkVar9.tmp\..\unlinkVar9.tmp\file.tmp -- +file removed +-- removing %s\BADDIR\file.tmp -- + +Warning: unlink(%s\BADDIR\file.tmp): No such file or directory in %s on line %d +-- removing unlinkVar9.tmp\file.tmp\ -- + +Warning: unlink(unlinkVar9.tmp\file.tmp\): Invalid argument in %s on line %d +-- removing %s\unlinkVar9.tmp\file.tmp\ -- + +Warning: unlink(%s\unlinkVar9.tmp\file.tmp\): Invalid argument in %s on line %d +-- removing unlinkVar9.tmp\\file.tmp -- +file removed +-- removing %s\\unlinkVar9.tmp\\file.tmp -- +file removed +-- removing /%s/unlinkVar9.tmp/file.tmp -- +file removed +===DONE===
\ No newline at end of file |
