summaryrefslogtreecommitdiff
path: root/ext/standard/tests
diff options
context:
space:
mode:
authorSteve Seear <stevseea@php.net>2008-03-19 17:25:47 +0000
committerSteve Seear <stevseea@php.net>2008-03-19 17:25:47 +0000
commit9071a478b5738b3ccb8cf40359f3172af870c952 (patch)
tree501171403d30fa1ed7914931b145595f0ee3a0b5 /ext/standard/tests
parent6ef4d75c81206c83b9a9cfa066762286e80bfcb8 (diff)
downloadphp-git-9071a478b5738b3ccb8cf40359f3172af870c952.tar.gz
Adding filesystem tests
Diffstat (limited to 'ext/standard/tests')
-rw-r--r--ext/standard/tests/file/fopen_variation1.phpt14
-rw-r--r--ext/standard/tests/file/fread_socket_variation1.phpt16
-rw-r--r--ext/standard/tests/file/fseek_dir_basic.phpt66
-rw-r--r--ext/standard/tests/file/glob_variation2.phpt57
-rw-r--r--ext/standard/tests/file/parse_ini_file_error.phpt53
-rw-r--r--ext/standard/tests/file/realpath_basic2.phpt13
-rw-r--r--ext/standard/tests/file/realpath_basic3.phpt86
7 files changed, 305 insertions, 0 deletions
diff --git a/ext/standard/tests/file/fopen_variation1.phpt b/ext/standard/tests/file/fopen_variation1.phpt
new file mode 100644
index 0000000000..53f635b6ed
--- /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 0000000000..bd3d23ac57
--- /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 0000000000..5204432b38
--- /dev/null
+++ b/ext/standard/tests/file/fseek_dir_basic.phpt
@@ -0,0 +1,66 @@
+--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));
+while( FALSE !== ($file = readdir($dh)) ) {
+ var_dump($file);
+}
+
+echo "\ncall fseek() on directory resource:\n";
+var_dump(fseek($dh, 20));
+
+echo "call readdir():\n";
+while( FALSE !== ($file = readdir($dh)) ) {
+ var_dump($file);
+}
+
+echo "\ncall fseek() with different arguments on directory resource:\n";
+var_dump(fseek($dh, 20, SEEK_END));
+
+echo "call readdir():\n";
+while( FALSE !== ($file = readdir($dh)) ) {
+ var_dump($file);
+}
+
+delete_files($path, 3);
+closedir($dh);
+var_dump(rmdir($path));
+
+?>
+--EXPECTF--
+call readdir():
+resource(%d) of type (stream)
+string(1) "."
+string(2) ".."
+string(9) "file1.tmp"
+string(9) "file2.tmp"
+string(9) "file3.tmp"
+
+call fseek() on directory resource:
+int(0)
+call readdir():
+string(1) "."
+string(2) ".."
+string(9) "file1.tmp"
+string(9) "file2.tmp"
+string(9) "file3.tmp"
+
+call fseek() with different arguments on directory resource:
+int(0)
+call readdir():
+string(1) "."
+string(2) ".."
+string(9) "file1.tmp"
+string(9) "file2.tmp"
+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 0000000000..f95fd17e7a
--- /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/parse_ini_file_error.phpt b/ext/standard/tests/file/parse_ini_file_error.phpt
new file mode 100644
index 0000000000..db63f2cdb6
--- /dev/null
+++ b/ext/standard/tests/file/parse_ini_file_error.phpt
@@ -0,0 +1,53 @@
+--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: parse_ini_file() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+-- Testing parse_ini_file() function with more than expected no. of arguments --
+
+Warning: parse_ini_file(%s): failed to open stream: No such file or directory in %s on line %d
+array(0) {
+}
+
+-- 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 0000000000..b71feb98b9
--- /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 0000000000..ce9385591d
--- /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