diff options
Diffstat (limited to 'ext/standard/tests/file')
64 files changed, 3430 insertions, 334 deletions
diff --git a/ext/standard/tests/file/bug22414.phpt b/ext/standard/tests/file/bug22414.phpt index b60b865e7..f5036daa8 100644 --- a/ext/standard/tests/file/bug22414.phpt +++ b/ext/standard/tests/file/bug22414.phpt @@ -8,20 +8,21 @@ output_handler= $php = getenv('TEST_PHP_EXECUTABLE'); $tmpfile = tempnam('/tmp', 'phpt'); + $args = ' -n -dsafe_mode=off '; /* Regular Data Test */ - passthru($php . ' -n -r " echo \"HELLO\"; "'); + passthru($php . $args . ' -r " echo \"HELLO\"; "'); echo "\n"; /* Binary Data Test */ if (substr(PHP_OS, 0, 3) != 'WIN') { - $cmd = $php . ' -n -r \"readfile(@getenv(\'TEST_PHP_EXECUTABLE\')); \"'; - $cmd = $php . ' -n -r \' passthru("'.$cmd.'"); \' > '.$tmpfile ; + $cmd = $php . $args . ' -r \"readfile(@getenv(\'TEST_PHP_EXECUTABLE\')); \"'; + $cmd = $php . $args . ' -r \' passthru("'.$cmd.'"); \' > '.$tmpfile ; } else { - $cmd = $php . ' -n -r \"readfile(@getenv(\\\\\\"TEST_PHP_EXECUTABLE\\\\\\")); \"'; - $cmd = $php . ' -n -r " passthru(\''.$cmd.'\');" > '.$tmpfile ; + $cmd = $php . $args . ' -r \"readfile(@getenv(\\\\\\"TEST_PHP_EXECUTABLE\\\\\\")); \"'; + $cmd = $php . $args . ' -r " passthru(\''.$cmd.'\');" > '.$tmpfile ; } exec($cmd); diff --git a/ext/standard/tests/file/bug41655_2.phpt b/ext/standard/tests/file/bug41655_2.phpt index 23086661f..d406f1ba0 100644 --- a/ext/standard/tests/file/bug41655_2.phpt +++ b/ext/standard/tests/file/bug41655_2.phpt @@ -5,13 +5,11 @@ open_basedir=/ --FILE-- <?php $dir = dirname(__FILE__); - $a=glob($dir . "/bug41655*.*"); + $a=glob($dir . "/test.*"); print_r($a); ?> --EXPECTF-- Array ( - [0] => %sbug41655_1.phpt - [1] => %sbug41655_2.php - [2] => %sbug41655_2.phpt + [0] => %stest.csv ) diff --git a/ext/standard/tests/file/bug43216.phpt b/ext/standard/tests/file/bug43216.phpt new file mode 100755 index 000000000..b7e42534c --- /dev/null +++ b/ext/standard/tests/file/bug43216.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #43216 (stream_is_local() returns false on file://) +--FILE-- +<?php +var_dump(stream_is_local("file://")); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/file/bug43248.phpt b/ext/standard/tests/file/bug43248.phpt new file mode 100755 index 000000000..a20e0e06c --- /dev/null +++ b/ext/standard/tests/file/bug43248.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #43248 backward compatibility break in realpath() +--FILE-- +<?php +echo realpath(dirname(__FILE__) . '/../file/'); +?> +--EXPECTF-- +%sfile diff --git a/ext/standard/tests/file/bug43522.phpt b/ext/standard/tests/file/bug43522.phpt new file mode 100644 index 000000000..10e44fc35 --- /dev/null +++ b/ext/standard/tests/file/bug43522.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #43522 (stream_get_line() eats additional characters) +--FILE-- +<?php // 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ + +$fp = fopen(__FILE__, 'r'); // Open self + +DoTest($fp, 'ZZZ'); // test multi-char delimiter +DoTest($fp, "Z"); // test single-char delimiter + +function DoTest($fp, $delim) { + echo "Delimiter: " . $delim . "\n"; + rewind($fp); + echo "\t" . stream_get_line($fp, 10, $delim) . "\n"; + echo "\t" . stream_get_line($fp, 10, $delim) . "\n"; +} + +?> +--EXPECT-- +Delimiter: ZZZ + <?php // 1 + 234567890A +Delimiter: Z + <?php // 1 + 234567890A diff --git a/ext/standard/tests/file/fgetc_basic.phpt b/ext/standard/tests/file/fgetc_basic.phpt index d82110f78..7851e432f 100644 --- a/ext/standard/tests/file/fgetc_basic.phpt +++ b/ext/standard/tests/file/fgetc_basic.phpt @@ -69,475 +69,475 @@ echo "Done\n"; string(1) "2" int(1) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 2 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using rb mode -- string(1) "2" int(1) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 3 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using rt mode -- string(1) "2" int(1) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 4 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using r+ mode -- string(1) "2" int(1) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 5 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using r+b mode -- string(1) "2" int(1) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 6 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using r+t mode -- string(1) "2" int(1) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) --- Outerloop iteration 2 --- -- Innerloop iteration 1 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r mode -- string(1) "t" int(1) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 2 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using rb mode -- string(1) "t" int(1) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 3 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using rt mode -- string(1) "t" int(1) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 4 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r+ mode -- string(1) "t" int(1) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 5 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r+b mode -- string(1) "t" int(1) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 6 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r+t mode -- string(1) "t" int(1) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) --- Outerloop iteration 3 --- -- Innerloop iteration 1 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r mode -- string(1) "l" int(1) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 2 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using rb mode -- string(1) "l" int(1) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 3 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using rt mode -- string(1) "l" int(1) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 4 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r+ mode -- string(1) "l" int(1) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 5 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r+b mode -- string(1) "l" int(1) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 6 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r+t mode -- string(1) "l" int(1) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) Done
\ No newline at end of file diff --git a/ext/standard/tests/file/fgetc_variation2.phpt b/ext/standard/tests/file/fgetc_variation2.phpt index d733c2909..e7f22b304 100644 --- a/ext/standard/tests/file/fgetc_variation2.phpt +++ b/ext/standard/tests/file/fgetc_variation2.phpt @@ -41,20 +41,7 @@ echo "Done"; *** Testing fgetc() : usage variations *** -- Testing fgetc() with closed handle -- -Warning: fgetc(): 6 is not a valid stream resource in %s on line %d -bool(false) --- Testing fgetc() with unset handle -- - -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 -bool(false) -Done ---UEXPECTF-- -*** Testing fgetc() : usage variations *** --- Testing fgetc() with closed handle -- - -Warning: fgetc(): 6 is not a valid stream resource in %s on line %d +Warning: fgetc(): %d is not a valid stream resource in %s on line %d bool(false) -- Testing fgetc() with unset handle -- diff --git a/ext/standard/tests/file/fopen_variation1.phpt b/ext/standard/tests/file/fopen_variation1.phpt new file mode 100644 index 000000000..53f635b6e --- /dev/null +++ b/ext/standard/tests/file/fopen_variation1.phpt @@ -0,0 +1,14 @@ +--TEST-- +fopen() with relative path on a file in the script directory +--FILE-- +<?php + +$file = basename(__FILE__); + +$fd = fopen($file, "r", true); +var_dump($fd); +fclose($fd); + +?> +--EXPECTF-- +resource(%d) of type (stream) diff --git a/ext/standard/tests/file/fread_socket_variation1.phpt b/ext/standard/tests/file/fread_socket_variation1.phpt new file mode 100644 index 000000000..bd3d23ac5 --- /dev/null +++ b/ext/standard/tests/file/fread_socket_variation1.phpt @@ -0,0 +1,16 @@ +--TEST-- +Testing fread() on a TCP server socket +--FILE-- +<?php + +$tcp_socket = stream_socket_server('tcp://127.0.0.1:31337'); + +socket_set_timeout($tcp_socket, 1); + +var_dump(fread($tcp_socket, 1)); + +fclose($tcp_socket); + +?> +--EXPECT-- +string(0) "" diff --git a/ext/standard/tests/file/fseek_dir_basic.phpt b/ext/standard/tests/file/fseek_dir_basic.phpt new file mode 100644 index 000000000..c6d0816e9 --- /dev/null +++ b/ext/standard/tests/file/fseek_dir_basic.phpt @@ -0,0 +1,96 @@ +--TEST-- +Testing fseek() on a directory stream +--FILE-- +<?php + +// include the file.inc for Function: function create_files() +require(dirname(__FILE__) . '/file.inc'); + +$path = dirname(__FILE__) . '/fseek_dir_basic'; +mkdir($path); +create_files($path, 3); + +echo "call readdir():\n"; +var_dump($dh = opendir($path)); +$files = array(); +while( FALSE !== ($files[] = readdir($dh)) ) {} +sort($files); +var_dump($files); +$files = array(); + +echo "\ncall fseek() on directory resource:\n"; +var_dump(fseek($dh, 20)); + +echo "call readdir():\n"; +while( FALSE !== ($files[] = readdir($dh)) ) {} +sort($files); +var_dump($files); +$files = array(); + +echo "\ncall fseek() with different arguments on directory resource:\n"; +var_dump(fseek($dh, 20, SEEK_END)); + +echo "call readdir():\n"; +while( FALSE !== ($files[] = readdir($dh)) ) {} +sort($files); +var_dump($files); + +delete_files($path, 3); +closedir($dh); +var_dump(rmdir($path)); + +?> +--EXPECTF-- +call readdir(): +resource(12) of type (stream) +array(6) { + [0]=> + bool(false) + [1]=> + string(1) "." + [2]=> + string(2) ".." + [3]=> + string(9) "file1.tmp" + [4]=> + string(9) "file2.tmp" + [5]=> + string(9) "file3.tmp" +} + +call fseek() on directory resource: +int(0) +call readdir(): +array(6) { + [0]=> + bool(false) + [1]=> + string(1) "." + [2]=> + string(2) ".." + [3]=> + string(9) "file1.tmp" + [4]=> + string(9) "file2.tmp" + [5]=> + string(9) "file3.tmp" +} + +call fseek() with different arguments on directory resource: +int(0) +call readdir(): +array(6) { + [0]=> + bool(false) + [1]=> + string(1) "." + [2]=> + string(2) ".." + [3]=> + string(9) "file1.tmp" + [4]=> + string(9) "file2.tmp" + [5]=> + string(9) "file3.tmp" +} +bool(true) diff --git a/ext/standard/tests/file/glob_variation2.phpt b/ext/standard/tests/file/glob_variation2.phpt new file mode 100644 index 000000000..f95fd17e7 --- /dev/null +++ b/ext/standard/tests/file/glob_variation2.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test glob() function with relative path +--FILE-- +<?php +/* Prototype: array glob ( string $pattern [, int $flags] ); + Description: Find pathnames matching a pattern +*/ + +$file_path = dirname(__FILE__); + +// temp dirname used here +$dir_name = 'glob_test'; + +// create temp directory +mkdir("$file_path/$dir_name"); + +// create temp file +$fp = fopen("$file_path/$dir_name/file.text", "w"); +fclose($fp); + +echo "Testing glob() with relative paths:\n"; + +chdir("$file_path/$dir_name"); +var_dump( glob("./*") ); +var_dump( glob("../$dir_name/*")); + +chdir("$file_path"); +var_dump( glob("$dir_name/*")); +var_dump( glob("$dir_name")); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink("$file_path/glob_test/file.text"); +rmdir("$file_path/glob_test/"); +?> +--EXPECT-- +Testing glob() with relative paths: +array(1) { + [0]=> + string(11) "./file.text" +} +array(1) { + [0]=> + string(22) "../glob_test/file.text" +} +array(1) { + [0]=> + string(19) "glob_test/file.text" +} +array(1) { + [0]=> + string(9) "glob_test" +} +Done diff --git a/ext/standard/tests/file/is_dir_variation2.phpt b/ext/standard/tests/file/is_dir_variation2.phpt index df2464d3c..70fe94e44 100644 --- a/ext/standard/tests/file/is_dir_variation2.phpt +++ b/ext/standard/tests/file/is_dir_variation2.phpt @@ -70,7 +70,7 @@ bool(true) -- With symlink -- bool(true) -- With hardlink -- -Warning: link(): Operation not permitted in %s on line %d +Warning: link(): %s in %s on line %d bool(false) *** Testing is_dir() with file and links to a file *** diff --git a/ext/standard/tests/file/open_basedir.inc b/ext/standard/tests/file/open_basedir.inc new file mode 100644 index 000000000..7fd0afc8b --- /dev/null +++ b/ext/standard/tests/file/open_basedir.inc @@ -0,0 +1,133 @@ +<?php + +// This file contains helper functions for testing open_basedir configuration +// Care must be taken with where the directories are created because different +// SAPIs set the working directory differently. So simply creating a directory +// relative to the current working directory like this: mkdir("blah") might +// actually create it in several different places depending on the SAPI..! +// +// Note also depending on the version of php being tested, so the open_basedir +// configuration may or may not be changeable from a script (PHP_INI_SYSTEM). +// +// For this reason we set the open_basedir to . (current directory) and then +// move around to various directories for testing using chdir(). This is NOT +// recommended for production use as . bypasses all semblence of security..! +// +// Although safe mode has been removed in php 6.0, open_basedir is still valid. +// See http://www.php.net/features.safe-mode for more information + +function recursive_delete_directory($directory) { + + // Remove any trailing slash first + if (substr($directory, -1) == '/') { + $directory = substr($directory, 0, -1); + } + + // Make sure the directory is valid + if (is_dir($directory) == FALSE) { + return FALSE; + } + + // Check we can access the directory + if (is_readable($directory) == FALSE) { + return FALSE; + } + + $handle = opendir($directory); + + // Scan through the directory contents + while (FALSE !== ($item = readdir($handle))) { + if ($item != '.') { + if ($item != '..') { + $path = ($directory.'/'.$item); + if (is_dir($path) == TRUE) { + recursive_delete_directory($path); + } else { + @chmod($path, 0777); + unlink($path); + } + } + } + } + + closedir($handle); + @chmod($directory, 0777); + rmdir($directory); + + return TRUE; +} + +function create_directories() { + delete_directories(); + $directory = dirname(__FILE__); + + var_dump(mkdir($directory."/test")); + var_dump(mkdir($directory."/test/ok")); + var_dump(mkdir($directory."/test/bad")); + file_put_contents($directory."/test/ok/ok.txt", "Hello World!"); + file_put_contents($directory."/test/bad/bad.txt", "Hello World!"); +} + +function delete_directories() { + $directory = (dirname(__FILE__)."/test"); + recursive_delete_directory($directory); +} + +function test_open_basedir_error($function) { + var_dump($function("../bad")); + var_dump($function("../bad/bad.txt")); + var_dump($function("..")); + var_dump($function("../")); + var_dump($function("/")); + var_dump($function("../bad/.")); + $directory = dirname(__FILE__); + var_dump($function($directory."/test/bad/bad.txt")); + var_dump($function($directory."/test/bad/../bad/bad.txt")); +} + +function test_open_basedir_before($function, $change = TRUE) { + echo "*** Testing open_basedir configuration [$function] ***\n"; + $directory = dirname(__FILE__); + var_dump(chdir($directory)); + create_directories(); + + // Optionally change directory + if ($change == TRUE) { + var_dump(chdir($directory."/test/ok")); + } +} + +// Delete directories using a --CLEAN-- section! +function test_open_basedir_after($function) { + echo "*** Finished testing open_basedir configuration [$function] ***\n"; +} + +// This is used by functions that return an array on success +function test_open_basedir_array($function) { + test_open_basedir_before($function); + test_open_basedir_error($function); + var_dump(is_array($function("./../."))); + var_dump(is_array($function("../ok"))); + var_dump(is_array($function("ok.txt"))); + var_dump(is_array($function("../ok/ok.txt"))); + $directory = dirname(__FILE__); + var_dump(is_array($function($directory."/test/ok/ok.txt"))); + var_dump(is_array($function($directory."/test/ok/../ok/ok.txt"))); + test_open_basedir_after($function); +} + +function test_open_basedir($function) { + test_open_basedir_before($function); + test_open_basedir_error($function); + var_dump($function("./../.")); + var_dump($function("../ok")); + var_dump($function("ok.txt")); + var_dump($function("../ok/ok.txt")); + $directory = dirname(__FILE__); + var_dump($function($directory."/test/ok/ok.txt")); + var_dump($function($directory."/test/ok/../ok/ok.txt")); + test_open_basedir_after($function); +} + +?> + diff --git a/ext/standard/tests/file/open_basedir_chdir.phpt b/ext/standard/tests/file/open_basedir_chdir.phpt new file mode 100644 index 000000000..32ed4eb1e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_chdir.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("chdir"); +$directory = dirname(__FILE__); + +var_dump(chdir("../bad")); +var_dump(chdir("..")); +var_dump(chdir("../")); +var_dump(chdir("/")); +var_dump(chdir("../bad/.")); +var_dump(chdir("./../.")); + +test_open_basedir_after("chdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [chdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: chdir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [chdir] *** + diff --git a/ext/standard/tests/file/open_basedir_chmod.phpt b/ext/standard/tests/file/open_basedir_chmod.phpt new file mode 100644 index 000000000..02fdce5a1 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_chmod.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("chmod"); +$directory = dirname(__FILE__); + +var_dump(chmod("../bad", 0600)); +var_dump(chmod("../bad/bad.txt", 0600)); +var_dump(chmod("..", 0600)); +var_dump(chmod("../", 0600)); +var_dump(chmod("/", 0600)); +var_dump(chmod("../bad/.", 0600)); +var_dump(chmod("../bad/./bad.txt", 0600)); +var_dump(chmod("./../.", 0600)); + +var_dump(chmod($directory."/test/ok/ok.txt", 0600)); +var_dump(chmod("./ok.txt", 0600)); +var_dump(chmod("ok.txt", 0600)); +var_dump(chmod("../ok/ok.txt", 0600)); +var_dump(chmod("../ok/./ok.txt", 0600)); +chmod($directory."/test/ok/ok.txt", 0777); + +test_open_basedir_after("chmod"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [chmod] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: chmod(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [chmod] *** + diff --git a/ext/standard/tests/file/open_basedir_copy.phpt b/ext/standard/tests/file/open_basedir_copy.phpt new file mode 100644 index 000000000..8f0f7a91f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_copy.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("copy"); +$directory = dirname(__FILE__); + +var_dump(copy("ok.txt", "../bad")); +var_dump(copy("ok.txt", "../bad/bad.txt")); +var_dump(copy("ok.txt", "..")); +var_dump(copy("ok.txt", "../")); +var_dump(copy("ok.txt", "/")); +var_dump(copy("ok.txt", "../bad/.")); +var_dump(copy("ok.txt", "../bad/./bad.txt")); +var_dump(copy("ok.txt", "./../.")); + +var_dump(copy("ok.txt", "copy.txt")); +var_dump(unlink("copy.txt")); +test_open_basedir_after("copy"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [copy] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: copy(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(./../.): failed to open stream: Operation not permitted in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [copy] *** + diff --git a/ext/standard/tests/file/open_basedir_copy_variation1.phpt b/ext/standard/tests/file/open_basedir_copy_variation1.phpt new file mode 100644 index 000000000..de532e12c --- /dev/null +++ b/ext/standard/tests/file/open_basedir_copy_variation1.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("copy"); +$directory = dirname(__FILE__); + +var_dump(copy("../bad/bad.txt", "copy.txt")); +var_dump(unlink("copy.txt")); + +test_open_basedir_after("copy"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [copy] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: copy(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(copy.txt): No such file or directory in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [copy] *** + diff --git a/ext/standard/tests/file/open_basedir_disk_free_space.phpt b/ext/standard/tests/file/open_basedir_disk_free_space.phpt new file mode 100644 index 000000000..e3e36e670 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_disk_free_space.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; + +test_open_basedir_before("disk_free_space"); +test_open_basedir_error("disk_free_space"); +$directory = dirname(__FILE__); +var_dump(disk_free_space($directory."/test/ok")); +test_open_basedir_after("disk_free_space"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [disk_free_space] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +float(%s) +*** Finished testing open_basedir configuration [disk_free_space] *** diff --git a/ext/standard/tests/file/open_basedir_file.phpt b/ext/standard/tests/file/open_basedir_file.phpt new file mode 100644 index 000000000..fbc841e3f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$directory = dirname(__FILE__); +test_open_basedir_before("file"); +test_open_basedir_error("file"); + +var_dump(file("ok.txt")); +var_dump(file("../ok/ok.txt")); +var_dump(file($directory."/test/ok/ok.txt")); +var_dump(file($directory."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(%s/test/bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(%s/test/bad/../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +*** Finished testing open_basedir configuration [file] *** + diff --git a/ext/standard/tests/file/open_basedir_file_exists.phpt b/ext/standard/tests/file/open_basedir_file_exists.phpt new file mode 100644 index 000000000..c249fc116 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file_exists.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("file_exists"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_exists] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [file_exists] *** + diff --git a/ext/standard/tests/file/open_basedir_file_get_contents.phpt b/ext/standard/tests/file/open_basedir_file_get_contents.phpt new file mode 100644 index 000000000..637c499ea --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file_get_contents.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$directory = dirname(__FILE__); +test_open_basedir_before("file_get_contents"); +test_open_basedir_error("file_get_contents"); + +var_dump(file_get_contents("ok.txt")); +var_dump(file_get_contents("../ok/ok.txt")); +var_dump(file_get_contents($directory."/test/ok/ok.txt")); +var_dump(file_get_contents($directory."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("file_get_contents"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_get_contents] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(%s/test/bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(%s/test/bad/../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) +string(12) "Hello World!" +string(12) "Hello World!" +string(12) "Hello World!" +string(12) "Hello World!" +*** Finished testing open_basedir configuration [file_get_contents] *** diff --git a/ext/standard/tests/file/open_basedir_file_put_contents.phpt b/ext/standard/tests/file/open_basedir_file_put_contents.phpt new file mode 100644 index 000000000..d4bd417b5 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file_put_contents.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("file_put_contents"); +$directory = dirname(__FILE__); + +var_dump(file_put_contents("../bad/bad.txt", "Hello World!")); +var_dump(file_put_contents(".././bad/bad.txt", "Hello World!")); +var_dump(file_put_contents("../bad/../bad/bad.txt", "Hello World!")); +var_dump(file_put_contents("./.././bad/bad.txt", "Hello World!")); +var_dump(file_put_contents($directory."/test/bad/bad.txt", "Hello World!")); + +test_open_basedir_after("file_put_contents"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_put_contents] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_put_contents(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(.././bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(../bad/../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(./.././bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents%s/test/bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [file_put_contents] *** + diff --git a/ext/standard/tests/file/open_basedir_fileatime.phpt b/ext/standard/tests/file/open_basedir_fileatime.phpt new file mode 100644 index 000000000..02cc94f83 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileatime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileatime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileatime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileatime] *** + diff --git a/ext/standard/tests/file/open_basedir_filectime.phpt b/ext/standard/tests/file/open_basedir_filectime.phpt new file mode 100644 index 000000000..542c8423e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filectime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filectime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filectime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filectime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filectime] *** + diff --git a/ext/standard/tests/file/open_basedir_filegroup.phpt b/ext/standard/tests/file/open_basedir_filegroup.phpt new file mode 100644 index 000000000..5f6279aa8 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filegroup.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filegroup"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filegroup] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filegroup] *** + diff --git a/ext/standard/tests/file/open_basedir_fileinode.phpt b/ext/standard/tests/file/open_basedir_fileinode.phpt new file mode 100644 index 000000000..070c2c806 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileinode.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileinode"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileinode] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileinode] *** + diff --git a/ext/standard/tests/file/open_basedir_filemtime.phpt b/ext/standard/tests/file/open_basedir_filemtime.phpt new file mode 100644 index 000000000..7213ddb5b --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filemtime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filemtime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filemtime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filemtime] *** + diff --git a/ext/standard/tests/file/open_basedir_fileowner.phpt b/ext/standard/tests/file/open_basedir_fileowner.phpt new file mode 100644 index 000000000..b363b7e0e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileowner.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileowner"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileowner] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileowner] *** + diff --git a/ext/standard/tests/file/open_basedir_fileperms.phpt b/ext/standard/tests/file/open_basedir_fileperms.phpt new file mode 100644 index 000000000..a1e6511b0 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileperms.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileperms"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileperms] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileperms] *** + diff --git a/ext/standard/tests/file/open_basedir_filesize.phpt b/ext/standard/tests/file/open_basedir_filesize.phpt new file mode 100644 index 000000000..a335dfd17 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filesize.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filesize"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filesize] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filesize(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filesize] *** + diff --git a/ext/standard/tests/file/open_basedir_filetype.phpt b/ext/standard/tests/file/open_basedir_filetype.phpt new file mode 100644 index 000000000..5091db56f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filetype.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filetype"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filetype] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filetype(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(3) "dir" +string(4) "file" +string(4) "file" +string(4) "file" +string(4) "file" +*** Finished testing open_basedir configuration [filetype] *** + diff --git a/ext/standard/tests/file/open_basedir_fopen.phpt b/ext/standard/tests/file/open_basedir_fopen.phpt new file mode 100644 index 000000000..c6c9a253f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fopen.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("fopen"); +$directory = dirname(__FILE__); + +var_dump(fopen("../bad", "r")); +var_dump(fopen("../bad/bad.txt", "r")); +var_dump(fopen("..", "r")); +var_dump(fopen("../", "r")); +var_dump(fopen("/", "r")); +var_dump(fopen("../bad/.", "r")); +var_dump(fopen("../bad/./bad.txt", "r")); +var_dump(fopen("./../.", "r")); + +var_dump(fopen($directory."/test/ok/ok.txt", "r")); +var_dump(fopen("./ok.txt", "r")); +var_dump(fopen("ok.txt", "r")); +var_dump(fopen("../ok/ok.txt", "r")); +var_dump(fopen("../ok/./ok.txt", "r")); + +test_open_basedir_after("fopen"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fopen] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fopen(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line 12 +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(./../.): failed to open stream: Operation not permitted in %s on line %d +bool(false) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +*** Finished testing open_basedir configuration [fopen] *** + diff --git a/ext/standard/tests/file/open_basedir_glob-win32.phpt b/ext/standard/tests/file/open_basedir_glob-win32.phpt new file mode 100644 index 000000000..3fa19afa3 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_glob-win32.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("glob"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [glob] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +array(0) { +} +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +array(1) { + [0]=> + string(5) "../ok" +} +array(1) { + [0]=> + string(6) "ok.txt" +} +array(1) { + [0]=> + string(12) "../ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/../ok/ok.txt" +} +*** Finished testing open_basedir configuration [glob] *** + diff --git a/ext/standard/tests/file/open_basedir_glob.phpt b/ext/standard/tests/file/open_basedir_glob.phpt new file mode 100644 index 000000000..591cd8f4f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_glob.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("glob"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [glob] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +array(1) { + [0]=> + string(5) "../ok" +} +array(1) { + [0]=> + string(6) "ok.txt" +} +array(1) { + [0]=> + string(12) "../ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/../ok/ok.txt" +} +*** Finished testing open_basedir configuration [glob] *** + diff --git a/ext/standard/tests/file/open_basedir_is_dir.phpt b/ext/standard/tests/file/open_basedir_is_dir.phpt new file mode 100644 index 000000000..e4ad620d7 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_dir.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_dir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_dir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_dir] *** + diff --git a/ext/standard/tests/file/open_basedir_is_executable.phpt b/ext/standard/tests/file/open_basedir_is_executable.phpt new file mode 100644 index 000000000..1bab86055 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_executable.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("is_executable"); +test_open_basedir_error("is_executable"); + +var_dump(is_executable("ok.txt")); +var_dump(is_executable("../ok/ok.txt")); +$directory = dirname(__FILE__); +var_dump(is_executable($directory."/test/ok/ok.txt")); +var_dump(is_executable($directory."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("is_executable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_executable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_executable] *** diff --git a/ext/standard/tests/file/open_basedir_is_file.phpt b/ext/standard/tests/file/open_basedir_is_file.phpt new file mode 100644 index 000000000..51ef0a2d1 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_file.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_file] *** + diff --git a/ext/standard/tests/file/open_basedir_is_link.phpt b/ext/standard/tests/file/open_basedir_is_link.phpt new file mode 100644 index 000000000..5d12148d8 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_link.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_link"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_link] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_link(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_link] *** + diff --git a/ext/standard/tests/file/open_basedir_is_readable.phpt b/ext/standard/tests/file/open_basedir_is_readable.phpt new file mode 100644 index 000000000..951a19ac7 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_readable.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_readable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_readable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_readable] *** + diff --git a/ext/standard/tests/file/open_basedir_is_writable.phpt b/ext/standard/tests/file/open_basedir_is_writable.phpt new file mode 100644 index 000000000..25ce1c63a --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_writable.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_writable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_writable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_writable] *** + diff --git a/ext/standard/tests/file/open_basedir_link.phpt b/ext/standard/tests/file/open_basedir_link.phpt new file mode 100644 index 000000000..a54c22f4b --- /dev/null +++ b/ext/standard/tests/file/open_basedir_link.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no links on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("link"); +$directory = dirname(__FILE__); + +$target = ($directory."/test/ok/ok.txt"); +var_dump(link($target, "../bad/link.txt")); +var_dump(link($target, "../link.txt")); +var_dump(link($target, "../bad/./link.txt")); +var_dump(link($target, "./.././link.txt")); + +$link = ($directory."/test/ok/link.txt"); +var_dump(link("../bad/bad.txt", $link)); +var_dump(link("../bad", $link)); +var_dump(link("../bad/./bad.txt", $link)); +var_dump(link("../bad/bad.txt", $link)); +var_dump(link("./.././bad", $link)); + +$target = ($directory."/test/ok/ok.txt"); + +var_dump(link($target, $link)); +var_dump(unlink($link)); +test_open_basedir_after("link"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [link] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [link] *** + diff --git a/ext/standard/tests/file/open_basedir_linkinfo.phpt b/ext/standard/tests/file/open_basedir_linkinfo.phpt new file mode 100644 index 000000000..ab12a5149 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_linkinfo.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("linkinfo", FALSE); +$directory = dirname(__FILE__); + +chdir($directory); + +$target = ($directory."/test/bad/bad.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); + +chdir($directory."/test/ok"); + +var_dump(linkinfo("symlink.txt")); +var_dump(linkinfo("../ok/symlink.txt")); +var_dump(linkinfo("../ok/./symlink.txt")); +var_dump(linkinfo("./symlink.txt")); +var_dump(linkinfo($directory."/test/ok/symlink.txt")); + +$target = ($directory."/test/ok/ok.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); +var_dump(linkinfo($symlink)); +var_dump(unlink($symlink)); + +test_open_basedir_after("linkinfo"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [linkinfo] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [linkinfo] *** + diff --git a/ext/standard/tests/file/open_basedir_lstat.phpt b/ext/standard/tests/file/open_basedir_lstat.phpt new file mode 100644 index 000000000..35e5a2201 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_lstat.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_array("lstat"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [lstat] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: lstat(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [lstat] *** + diff --git a/ext/standard/tests/file/open_basedir_mkdir.phpt b/ext/standard/tests/file/open_basedir_mkdir.phpt new file mode 100644 index 000000000..253818ccf --- /dev/null +++ b/ext/standard/tests/file/open_basedir_mkdir.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("mkdir"); +$directory = dirname(__FILE__); + +var_dump(mkdir("../bad/blah")); +var_dump(mkdir("../blah")); +var_dump(mkdir("../bad/./blah")); +var_dump(mkdir("./.././blah")); + +var_dump(mkdir($directory."/test/ok/blah")); +var_dump(rmdir($directory."/test/ok/blah")); +test_open_basedir_after("mkdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [mkdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: mkdir(): open_basedir restriction in effect. File(../bad/blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(../blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(../bad/./blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(./.././blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [mkdir] *** diff --git a/ext/standard/tests/file/open_basedir_parse_ini_file.phpt b/ext/standard/tests/file/open_basedir_parse_ini_file.phpt new file mode 100644 index 000000000..dadddac98 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_parse_ini_file.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("parse_ini_file"); +$directory = dirname(__FILE__); + +var_dump(parse_ini_file("../bad")); +var_dump(parse_ini_file("../bad/bad.txt")); +var_dump(parse_ini_file("..")); +var_dump(parse_ini_file("../")); +var_dump(parse_ini_file("../bad/.")); +var_dump(parse_ini_file("../bad/./bad.txt")); +var_dump(parse_ini_file("./../.")); + +test_open_basedir_after("parse_ini_file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [parse_ini_file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(..): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/.): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(./../.): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} +*** Finished testing open_basedir configuration [parse_ini_file] *** + diff --git a/ext/standard/tests/file/open_basedir_readlink.phpt b/ext/standard/tests/file/open_basedir_readlink.phpt new file mode 100644 index 000000000..cbba4307e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_readlink.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("readlink", FALSE); +$directory = dirname(__FILE__); + +chdir($directory); + +$target = ($directory."/test/bad/bad.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); + +chdir($directory."/test/ok"); + +var_dump(readlink("symlink.txt")); +var_dump(readlink("../ok/symlink.txt")); +var_dump(readlink("../ok/./symlink.txt")); +var_dump(readlink("./symlink.txt")); +var_dump(readlink($directory."/test/ok/symlink.txt")); + +$target = ($directory."/test/ok/ok.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); +var_dump(readlink($symlink)); +var_dump(unlink($symlink)); + +test_open_basedir_after("readlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [readlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: readlink(): open_basedir restriction in effect. File(symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(../ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(../ok/./symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(./symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [readlink] *** + diff --git a/ext/standard/tests/file/open_basedir_realpath.phpt b/ext/standard/tests/file/open_basedir_realpath.phpt new file mode 100644 index 000000000..8cae890e9 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_realpath.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip only run on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("realpath"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [realpath] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(%d) "%s\test\ok" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +*** Finished testing open_basedir configuration [realpath] *** + diff --git a/ext/standard/tests/file/open_basedir_rename.phpt b/ext/standard/tests/file/open_basedir_rename.phpt new file mode 100644 index 000000000..428e7a070 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_rename.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("rename"); +$directory = dirname(__FILE__); + +var_dump(rename("../bad/bad.txt", "rename.txt")); +var_dump(rename(".././bad/bad.txt", "rename.txt")); +var_dump(rename("../bad/../bad/bad.txt", "rename.txt")); +var_dump(rename("./.././bad/bad.txt", "rename.txt")); +var_dump(rename($directory."/test/bad/bad.txt", "rename.txt")); + +test_open_basedir_after("rename"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [rename] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: rename(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [rename] *** + diff --git a/ext/standard/tests/file/open_basedir_rmdir.phpt b/ext/standard/tests/file/open_basedir_rmdir.phpt new file mode 100644 index 000000000..b4d61f8b7 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_rmdir.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("rmdir"); +$directory = dirname(__FILE__); + +var_dump(rmdir("../bad")); +var_dump(rmdir(".././bad")); +var_dump(rmdir("../bad/../bad")); +var_dump(rmdir("./.././bad")); +var_dump(rmdir($directory."/test/bad")); + +test_open_basedir_after("rmdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [rmdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: rmdir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(.././bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(../bad/../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(./.././bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [rmdir] *** + diff --git a/ext/standard/tests/file/open_basedir_stat.phpt b/ext/standard/tests/file/open_basedir_stat.phpt new file mode 100644 index 000000000..b80b854d6 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_stat.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_array("stat"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [stat] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: stat(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [stat] *** + diff --git a/ext/standard/tests/file/open_basedir_symlink.phpt b/ext/standard/tests/file/open_basedir_symlink.phpt new file mode 100644 index 000000000..3b3f1d571 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_symlink.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("symlink"); +$directory = dirname(__FILE__); + +$target = ($directory."/test/ok/ok.txt"); +var_dump(symlink($target, "../bad/symlink.txt")); +var_dump(symlink($target, "../symlink.txt")); +var_dump(symlink($target, "../bad/./symlink.txt")); +var_dump(symlink($target, "./.././symlink.txt")); + +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink("../bad/bad.txt", $symlink)); +var_dump(symlink("../bad", $symlink)); +var_dump(symlink("../bad/./bad.txt", $symlink)); +var_dump(symlink("../bad/bad.txt", $symlink)); +var_dump(symlink("./.././bad", $symlink)); + +$target = ($directory."/test/ok/ok.txt"); + +var_dump(symlink($target, $symlink)); +var_dump(unlink($symlink)); +test_open_basedir_after("symlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [symlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [symlink] *** + diff --git a/ext/standard/tests/file/open_basedir_tempnam.phpt b/ext/standard/tests/file/open_basedir_tempnam.phpt new file mode 100644 index 000000000..247ac88d5 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_tempnam.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("tempnam"); +$directory = dirname(__FILE__); + +var_dump(tempnam("../bad", "test")); +var_dump(tempnam("..", "test")); +var_dump(tempnam("../", "test")); +var_dump(tempnam("/", "test")); +var_dump(tempnam("../bad/.", "test")); +var_dump(tempnam("./../.", "test")); + +$file = tempnam($directory."/test/ok", "test"); +var_dump($file); +var_dump(unlink($file)); + +test_open_basedir_after("tempnam"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [tempnam] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: tempnam(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(%d) "%s" +bool(true) +*** Finished testing open_basedir configuration [tempnam] *** + diff --git a/ext/standard/tests/file/open_basedir_touch.phpt b/ext/standard/tests/file/open_basedir_touch.phpt new file mode 100644 index 000000000..b0a5aee61 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_touch.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("touch"); +$directory = dirname(__FILE__); + +var_dump(touch("../bad")); +var_dump(touch("../bad/bad.txt")); +var_dump(touch("..")); +var_dump(touch("../")); +var_dump(touch("/")); +var_dump(touch("../bad/.")); +var_dump(touch("../bad/./bad.txt")); +var_dump(touch("./../.")); + +var_dump(touch($directory."/test/ok/ok.txt")); +var_dump(touch("./ok.txt")); +var_dump(touch("ok.txt")); +var_dump(touch("../ok/ok.txt")); +var_dump(touch("../ok/./ok.txt")); + +test_open_basedir_after("touch"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [touch] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: touch(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [touch] *** + diff --git a/ext/standard/tests/file/open_basedir_unlink.phpt b/ext/standard/tests/file/open_basedir_unlink.phpt new file mode 100644 index 000000000..75b0f3f4a --- /dev/null +++ b/ext/standard/tests/file/open_basedir_unlink.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("unlink"); +$directory = dirname(__FILE__); + +var_dump(unlink("../bad/bad.txt")); +var_dump(unlink(".././bad/bad.txt")); +var_dump(unlink("../bad/../bad/bad.txt")); +var_dump(unlink("./.././bad/bad.txt")); +var_dump(unlink($directory."/test/bad/bad.txt")); + +test_open_basedir_after("unlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [unlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: unlink(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [unlink] *** + diff --git a/ext/standard/tests/file/parse_ini_file_error.phpt b/ext/standard/tests/file/parse_ini_file_error.phpt new file mode 100644 index 000000000..65a6ac1d8 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_error.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test parse_ini_file() function : error conditions +--FILE-- +<?php +/* Prototype : proto array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing parse_ini_file() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing parse_ini_file() function with Zero arguments --\n"; +var_dump( parse_ini_file() ); + +//Test parse_ini_file with one more than the expected number of arguments +echo "\n-- Testing parse_ini_file() function with more than expected no. of arguments --\n"; +$filename = 'string_val'; +$process_sections = true; +$extra_arg = 10; +var_dump( parse_ini_file($filename, $process_sections, $extra_arg) ); + +echo "\n-- Testing parse_ini_file() function with a non-existent file --\n"; +$filename = __FILE__ . 'invalidfilename'; +var_dump( parse_ini_file($filename, $process_sections) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing parse_ini_file() : error conditions *** + +-- Testing parse_ini_file() function with Zero arguments -- + +Warning: Wrong parameter count for parse_ini_file() in %s on line %d +NULL + +-- Testing parse_ini_file() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for parse_ini_file() in %s on line %d +NULL + +-- Testing parse_ini_file() function with a non-existent file -- + +Warning: parse_ini_file(%s): failed to open stream: No such file or directory in %s on line %d +array(0) { +} +Done diff --git a/ext/standard/tests/file/realpath_basic2.phpt b/ext/standard/tests/file/realpath_basic2.phpt new file mode 100644 index 000000000..b71feb98b --- /dev/null +++ b/ext/standard/tests/file/realpath_basic2.phpt @@ -0,0 +1,13 @@ +--TEST-- +realpath() with relative directory +--FILE-- +<?php + +var_dump(realpath('.') == getcwd()); +chdir('..'); +var_dump(realpath('.') == getcwd()); + +?> +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/standard/tests/file/realpath_basic3.phpt b/ext/standard/tests/file/realpath_basic3.phpt new file mode 100644 index 000000000..ce9385591 --- /dev/null +++ b/ext/standard/tests/file/realpath_basic3.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test realpath() with relative paths +--FILE-- +<?php +/* Prototype: string realpath ( string $path ); + Description: Returns canonicalized absolute pathname +*/ + +echo "\n*** Testing basic functions of realpath() with files ***\n"; + +/* creating directories and files */ +$file_path = dirname(__FILE__); +mkdir("$file_path/realpath_basic/home/test/", 0777, true); + +$file_handle1 = fopen("$file_path/realpath_basic/home/test/realpath_basic.tmp", "w"); +$file_handle2 = fopen("$file_path/realpath_basic/home/realpath_basic.tmp", "w"); +$file_handle3 = fopen("$file_path/realpath_basic/realpath_basic.tmp", "w"); +fclose($file_handle1); +fclose($file_handle2); +fclose($file_handle3); + +echo "\n*** Testing realpath() on filenames ***\n"; +$filenames = array ( + /* filenames resulting in valid paths */ + "./realpath_basic/home/realpath_basic.tmp", + "./realpath_basic/realpath_basic.tmp", + "./realpath_basic//home/test//../test/./realpath_basic.tmp", + "./realpath_basic/home//../././realpath_basic.tmp", + + /* filenames with invalid path */ + // checking for binary safe + "./realpath_basicx000/home/realpath_basic.tmp", + + ".///realpath_basic/home//..//././test//realpath_basic.tmp", + "./realpath_basic/home/../home/../test/..realpath_basic.tmp" +); + +chdir("$file_path/.."); +chdir($file_path); + +$counter = 1; +/* loop through $files to read the filepath of $file in the above array */ +foreach($filenames as $file) { + echo "\n-- Iteration $counter --\n"; + var_dump( realpath($file) ); + $counter++; +} + +echo "Done\n"; +?> +--CLEAN-- +<?php +$name_prefix = dirname(__FILE__)."/realpath_basic"; +unlink("$name_prefix/home/test/realpath_basic.tmp"); +unlink("$name_prefix/home/realpath_basic.tmp"); +unlink("$name_prefix/realpath_basic.tmp"); +rmdir("$name_prefix/home/test/"); +rmdir("$name_prefix/home/"); +rmdir("$name_prefix/"); +?> +--EXPECTF-- +*** Testing basic functions of realpath() with files *** + +*** Testing realpath() on filenames *** + +-- Iteration 1 -- +string(%d) "%srealpath_basic%shome%srealpath_basic.tmp" + +-- Iteration 2 -- +string(%d) "%srealpath_basic%srealpath_basic.tmp" + +-- Iteration 3 -- +string(%d) "%srealpath_basic%shome%stest%srealpath_basic.tmp" + +-- Iteration 4 -- +string(%d) "%srealpath_basic%srealpath_basic.tmp" + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) +Done diff --git a/ext/standard/tests/file/rename_basic.phpt b/ext/standard/tests/file/rename_basic.phpt index 8a255ca6e..28d3b1988 100755 --- a/ext/standard/tests/file/rename_basic.phpt +++ b/ext/standard/tests/file/rename_basic.phpt @@ -6,7 +6,7 @@ Test rename() function: basic functionality Description: Renames a file or directory */ -echo "*** Testing rename() for basic functions on existing file ***\n"; +echo "*** Testing rename() on non-existing file ***\n"; $file_path = dirname(__FILE__); $src_name = "$file_path/rename_basic.tmp"; $dest_name = "$file_path/rename_basic_new.tmp"; @@ -16,103 +16,30 @@ $fp = fopen($src_name, "w"); $s1 = stat($src_name); fclose($fp); -var_dump( rename($src_name, $dest_name) ); -// ensure that $dest_name didn't get created -var_dump( file_exists($src_name) ); // expecting false +var_dump( rename($src_name, $dest_name) ); // expecting true +var_dump( file_exists($src_name) ); // expecting false var_dump( file_exists($dest_name) ); // expecting true $s2 = stat("$file_path/rename_basic_new.tmp"); -// checking statistics of old and renamed file -// both should be same + +// checking statistics of old and renamed file - both should be same for ($i = 0; $i <= 12; $i++) { if ($s1[$i] != $s2[$i]) { echo "rename_basic.tmp and rename_basic_new.tmp stat differ at element $i\n"; } } -echo "\n*** Testing rename() on non-existing file ***\n"; -// try renaming a non existing file -$src_name = $file_path."/non_existent_file.tmp"; -$dest_name = $file_path."/rename_basic_new1.tmp"; -var_dump( rename($src_name, $dest_name) ); -// ensure that $dest_name didn't get created -var_dump( file_exists($src_name) ); // expecting false -var_dump( file_exists($dest_name) ); // expecting false - -// rename a existing dir to new name -echo "\n*** Testing rename() on existing directory ***\n"; -$dir_name = $file_path."/rename_basic_dir"; -mkdir($dir_name); -$new_dir_name = $file_path."/rename_basic_dir1"; -var_dump( rename($dir_name, $new_dir_name) ); -//ensure that $new_dir_name got created -var_dump( file_exists($dir_name) ); // expecting false -var_dump( file_exists($new_dir_name) ); // expecting true - -// try to rename an non_existing dir -echo "\n*** Testing rename() on non-existing directory ***\n"; -$non_existent_dir_name = $file_path."/non_existent_dir"; -$new_dir_name = "$file_path/rename_basic_dir2"; -var_dump( rename($non_existent_dir_name, $new_dir_name) ); -// ensure that $new_dir_name didn't get created -var_dump( file_exists($non_existent_dir_name) ); // expecting flase -var_dump( file_exists($new_dir_name) ); // expecting false - -echo "\n*** Testing rename() by giving stream context as third argument ***\n"; -$context = stream_context_create(); -// on directory -$dir_name = "$file_path/rename_basic_dir1"; -$new_dir_name = "$file_path/rename_basic_dir3"; -var_dump( rename($dir_name, $new_dir_name, $context) ); -// ensure that $new_dir_name got created -var_dump( file_exists($dir_name) ); // expecting flase -var_dump( file_exists($new_dir_name) ); // expecting true - -//on file -$src_name = "$file_path/rename_basic_new.tmp"; -$dest_name = "$file_path/rename_basic_new2.tmp"; -var_dump( rename($src_name, $dest_name, $context) ); -// ensure that $dest_name got created -var_dump( file_exists($src_name) ); // expecting false -var_dump( file_exists($dest_name) ); // expecting true - echo "Done\n"; ?> --CLEAN-- <?php -unlink(dirname(__FILE__)."/rename_basic_new2.tmp"); -rmdir(dirname(__FILE__)."/rename_basic_dir3"); +unlink(dirname(__FILE__)."/rename_basic.tmp"); +unlink(dirname(__FILE__)."/rename_basic_new.tmp"); ?> --EXPECTF-- -*** Testing rename() for basic functions on existing file *** -bool(true) -bool(false) -bool(true) - *** Testing rename() on non-existing file *** - -Warning: rename(%s/non_existent_file.tmp,%s/rename_basic_new1.tmp): No such file or directory in %s on line %d -bool(false) -bool(false) -bool(false) - -*** Testing rename() on existing directory *** -bool(true) -bool(false) -bool(true) - -*** Testing rename() on non-existing directory *** - -Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d -bool(false) -bool(false) -bool(false) - -*** Testing rename() by giving stream context as third argument *** -bool(true) -bool(false) -bool(true) 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 3cac5ccad..ae9555760 100644 --- a/ext/standard/tests/file/rename_variation-win32.phpt +++ b/ext/standard/tests/file/rename_variation-win32.phpt @@ -14,7 +14,7 @@ if (substr(PHP_OS, 0, 3) != 'WIN') { require dirname(__FILE__).'/file.inc'; -/* creating directory */ +/* create directory */ $file_path = dirname(__FILE__); mkdir("$file_path/rename_variation"); @@ -30,7 +30,9 @@ $src_filenames = array( "$file_path/rename_variation//rename_variation.tmp", "$file_path//rename_variation//rename_variation.tmp", ); + $counter = 1; + /* loop through each $file and rename it to rename_variation2.tmp */ foreach($src_filenames as $src_filename) { echo "-- Iteration $counter --\n"; @@ -38,6 +40,7 @@ foreach($src_filenames as $src_filename) { fclose($fp); $dest_filename = "$file_path/rename_variation2.tmp"; var_dump( rename($src_filename, $dest_filename) ); + // ensure that file got renamed to new name var_dump( file_exists($src_filename) ); // expecting false var_dump( file_exists($dest_filename) ); // expecting true @@ -47,90 +50,8 @@ foreach($src_filenames as $src_filename) { unlink($dest_filename); } -// clean the temp dir and file rmdir("$file_path/rename_variation"); -// rename dirs across directories -echo "\n*** Testing rename() : renaming directory across directories ***\n"; -$src_dirs = array ( - /* Testing simple directory tree */ - "$file_path/rename_variation/", - - /* Testing a dir with trailing slash */ - "$file_path/rename_variation/", - - /* Testing dir with double trailing slashes */ - "$file_path//rename_variation//", -); - -$dest_dir = "$file_path/rename_variation_dir"; -// create the $dest_dir -mkdir($dest_dir); - -$counter = 1; -/* loop through each $src_dirs and rename it to $dest_dir */ -foreach($src_dirs as $src_dir) { - echo "-- Iteration $counter --\n"; - - // create the src dir - mkdir("$file_path/rename_variation/"); - // rename the src dir to a new dir in dest dir - var_dump( rename($src_dir, $dest_dir."/new_dir") ); - // ensure that dir was renamed - var_dump( file_exists($src_dir) ); // expecting false - var_dump( file_exists($dest_dir."/new_dir") ); // expecting true - - // remove the new dir - rmdir($dest_dir."/new_dir"); - $counter++; -} - -/* Renaming a file and directory to numeric name */ -echo "\n*** Testing rename() by renaming a file and directory to numeric name ***\n"; -$fp = fopen($file_path."/rename_variation.tmp", "w"); -fclose($fp); -// renaming existing file to numeric name -var_dump( rename($file_path."/rename_variation.tmp", $file_path."/12345") ); -// ensure that rename worked fine -var_dump( file_exists($file_path."/rename_variation.tmp" ) ); // expecting false -var_dump( file_exists($file_path."/12345" ) ); // expecting true -// remove the file -unlink($file_path."/12345"); - -// renaming a directory to numeric name -var_dump( rename($file_path."/rename_variation_dir/", $file_path."/12345") ); -// ensure that rename worked fine -var_dump( file_exists($file_path."/rename_variation_dir" ) ); // expecting false -var_dump( file_exists($file_path."/12345" ) ); // expecting true - -// delete the file and dir -rmdir($file_path."/12345"); - -/* test rename() by trying to rename an existing file/dir to the same name - and one another */ -// create a dir -$file_path = dirname(__FILE__); -$dirname = "$file_path/rename_variation_dir"; -mkdir($dirname); -//create a file -$filename = "$file_path/rename_variation.tmp"; -$fp = fopen($filename, "w"); -fclose($fp); - -echo "\n-- Renaming file to same file name --\n"; -var_dump( rename($filename, $filename) ); - -echo "\n-- Renaming directory to same directory name --\n"; -var_dump( rename($dirname, $dirname) ); - -echo "\n-- Renaming existing file to existing directory name --\n"; -var_dump( rename($filename, $dirname) ); - -echo "\n-- Renaming existing directory to existing file name --\n"; -$fp = fopen($filename, "w"); -fclose($fp); -var_dump( rename($dirname, $filename) ); - echo "Done\n"; ?> --CLEAN-- @@ -147,53 +68,20 @@ bool(true) bool(false) bool(true) -- Iteration 2 -- -bool(true) -bool(false) -bool(true) --- Iteration 3 -- -bool(true) -bool(false) -bool(true) --- Iteration 4 -- -bool(true) -bool(false) -bool(true) -*** Testing rename() : renaming directory across directories *** --- Iteration 1 -- -bool(true) +Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): Invalid argument in %s on line %d bool(false) bool(true) --- Iteration 2 -- -bool(true) bool(false) -bool(true) --- Iteration 3 -- -bool(true) -bool(false) -bool(true) -*** Testing rename() by renaming a file and directory to numeric name *** +Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d +-- Iteration 3 -- bool(true) bool(false) bool(true) +-- Iteration 4 -- bool(true) bool(false) bool(true) +Done --- Renaming file to same file name -- -bool(true) - --- Renaming directory to same directory name -- -bool(true) - --- Renaming existing file to existing directory name -- - -Warning: rename(%s,%s): File exists in %s on line %d -bool(false) - --- Renaming existing directory to existing file name -- - -Warning: rename(%s,%s): File exists in %s on line %d -bool(false) -Done
\ No newline at end of file diff --git a/ext/standard/tests/file/rename_variation1-win32.phpt b/ext/standard/tests/file/rename_variation1-win32.phpt new file mode 100644 index 000000000..0955096d7 --- /dev/null +++ b/ext/standard/tests/file/rename_variation1-win32.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +/* creating directory */ +$file_path = dirname(__FILE__); + +// rename dirs across directories +echo "\n*** Testing rename() : renaming directory across directories ***\n"; +$src_dirs = array ( + /* Testing simple directory tree */ + "$file_path/rename_variation/", + + /* Testing a dir with trailing slash */ + "$file_path/rename_variation/", + + /* Testing dir with double trailing slashes */ + "$file_path//rename_variation//", +); + +$dest_dir = "$file_path/rename_variation_dir"; + +// create the $dest_dir +mkdir($dest_dir); + +$counter = 1; + +/* loop through each $src_dirs and rename it to $dest_dir */ +foreach($src_dirs as $src_dir) { + echo "-- Iteration $counter --\n"; + + // create the src dir + mkdir("$file_path/rename_variation/"); + // rename the src dir to a new dir in dest dir + var_dump( rename($src_dir, $dest_dir."/new_dir") ); + // ensure that dir was renamed + var_dump( file_exists($src_dir) ); // expecting false + var_dump( file_exists($dest_dir."/new_dir") ); // expecting true + + // remove the new dir + rmdir($dest_dir."/new_dir"); + $counter++; +} + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +*** Testing rename() : renaming directory across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +Done + diff --git a/ext/standard/tests/file/rename_variation2-win32.phpt b/ext/standard/tests/file/rename_variation2-win32.phpt new file mode 100644 index 000000000..87f4e7ddb --- /dev/null +++ b/ext/standard/tests/file/rename_variation2-win32.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +$file_path = dirname(__FILE__); +mkdir("$file_path/rename_variation_dir"); + +/* Renaming a file and directory to numeric name */ +echo "\n*** Testing rename() by renaming a file and directory to numeric name ***\n"; +$fp = fopen($file_path."/rename_variation.tmp", "w"); +fclose($fp); + +// renaming existing file to numeric name +var_dump( rename($file_path."/rename_variation.tmp", $file_path."/12345") ); + +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation.tmp" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true + +unlink($file_path."/12345"); + +// renaming a directory to numeric name +var_dump( rename($file_path."/rename_variation_dir/", $file_path."/12345") ); + +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation_dir" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true + +rmdir($file_path."/12345"); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +*** Testing rename() by renaming a file and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) +Done + diff --git a/ext/standard/tests/file/rename_variation3-win32.phpt b/ext/standard/tests/file/rename_variation3-win32.phpt new file mode 100644 index 000000000..7ad17093d --- /dev/null +++ b/ext/standard/tests/file/rename_variation3-win32.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +/* creating directory */ +$file_path = dirname(__FILE__); +$dirname = "$file_path/rename_variation_dir"; +mkdir($dirname); + +/* test rename() by trying to rename an existing file/dir to the same name + and one another */ + +$filename = "$file_path/rename_variation.tmp"; +$fp = fopen($filename, "w"); +fclose($fp); + +echo "\n-- Renaming file to same file name --\n"; +var_dump( rename($filename, $filename) ); + +echo "\n-- Renaming directory to same directory name --\n"; +var_dump( rename($dirname, $dirname) ); + +echo "\n-- Renaming existing file to existing directory name --\n"; +var_dump( rename($filename, $dirname) ); + +echo "\n-- Renaming existing directory to existing file name --\n"; +$fp = fopen($filename, "w"); +fclose($fp); +var_dump( rename($dirname, $filename) ); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +-- Renaming file to same file name -- +bool(true) + +-- Renaming directory to same directory name -- +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s/rename_variation.tmp,%s/rename_variation_dir): File exists in %s on line %d +bool(false) + +-- Renaming existing directory to existing file name -- + +Warning: rename(%s/rename_variation_dir,%s/rename_variation.tmp): File exists in %s on line %d +bool(false) +Done + diff --git a/ext/standard/tests/file/rename_variation8.phpt b/ext/standard/tests/file/rename_variation8.phpt new file mode 100644 index 000000000..650b6c990 --- /dev/null +++ b/ext/standard/tests/file/rename_variation8.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test rename() function: variation +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +echo "\n*** Testing rename() on non-existing file ***\n"; +$file_path = dirname(__FILE__); + +// try renaming a non existing file +$src_name = $file_path."/non_existent_file.tmp"; +$dest_name = $file_path."/rename_variation8_new.tmp"; +var_dump( rename($src_name, $dest_name) ); + +// ensure that $dest_name didn't get created +var_dump( file_exists($src_name) ); // expecting false +var_dump( file_exists($dest_name) ); // expecting false + +// rename a existing dir to new name +echo "\n*** Testing rename() on existing directory ***\n"; +$dir_name = $file_path."/rename_basic_dir"; +mkdir($dir_name); +$new_dir_name = $file_path."/rename_basic_dir1"; +var_dump( rename($dir_name, $new_dir_name) ); +//ensure that $new_dir_name got created +var_dump( file_exists($dir_name) ); // expecting false +var_dump( file_exists($new_dir_name) ); // expecting true + +// try to rename an non_existing dir +echo "\n*** Testing rename() on non-existing directory ***\n"; +$non_existent_dir_name = $file_path."/non_existent_dir"; +$new_dir_name = "$file_path/rename_basic_dir2"; +var_dump( rename($non_existent_dir_name, $new_dir_name) ); +// ensure that $new_dir_name didn't get created +var_dump( file_exists($non_existent_dir_name) ); // expecting flase +var_dump( file_exists($new_dir_name) ); // expecting false + +echo "Done\n"; +?> +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/rename_basic_new2.tmp"); +rmdir(dirname(__FILE__)."/rename_basic_dir1"); +?> +--EXPECTF-- +*** Testing rename() on non-existing file *** + +Warning: rename(%s/non_existent_file.tmp,%s/rename_variation8_new.tmp): No such file or directory in %s on line %d +bool(false) +bool(false) +bool(false) + +*** Testing rename() on existing directory *** +bool(true) +bool(false) +bool(true) + +*** Testing rename() on non-existing directory *** + +Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d +bool(false) +bool(false) +bool(false) +Done + diff --git a/ext/standard/tests/file/rename_variation9.phpt b/ext/standard/tests/file/rename_variation9.phpt new file mode 100644 index 000000000..d923e4a3d --- /dev/null +++ b/ext/standard/tests/file/rename_variation9.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test rename() function: basic functionality +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +echo "\n*** Testing rename() by giving stream context as third argument ***\n"; +$file_path = dirname(__FILE__); + +$context = stream_context_create(); + +// on directory +$dir_name = "$file_path/rename_variation_dir9"; +$new_dir_name = "$file_path/rename_variation_dir9_new"; + +mkdir($dir_name); + +var_dump( rename($dir_name, $new_dir_name, $context) ); +var_dump( file_exists($dir_name) ); // expecting flase +var_dump( file_exists($new_dir_name) ); // expecting true + +//on file +$src_name = "$file_path/rename_variation9.tmp"; +$dest_name = "$file_path/rename_variation9_new.tmp"; + +// create the file +$fp = fopen($src_name, "w"); +$s1 = stat($src_name); +fclose($fp); + +var_dump( rename($src_name, $dest_name, $context) ); +var_dump( file_exists($src_name) ); // expecting false +var_dump( file_exists($dest_name) ); // expecting true + +echo "Done\n"; +?> +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/rename_variation9_new.tmp"); +rmdir(dirname(__FILE__)."/rename_variation_dir9_new"); +?> +--EXPECTF-- +*** Testing rename() by giving stream context as third argument *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) +Done + |
