From 7c75fe7b8ce1531924bc71713ee34dceaeb9956c Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Mon, 24 Dec 2007 05:19:42 +0000 Subject: [PATCH] new testcases for dir() function --- ext/standard/tests/dir/dir_basic.phpt | 86 ++++++++ ext/standard/tests/dir/dir_error.phpt | 34 ++++ ext/standard/tests/dir/dir_variation1.phpt | 160 +++++++++++++++ ext/standard/tests/dir/dir_variation2.phpt | 223 +++++++++++++++++++++ ext/standard/tests/dir/dir_variation3.phpt | 195 ++++++++++++++++++ ext/standard/tests/dir/dir_variation4.phpt | 72 +++++++ ext/standard/tests/dir/dir_variation5.phpt | 29 +++ ext/standard/tests/dir/dir_variation6.phpt | 51 +++++ ext/standard/tests/dir/dir_variation7.phpt | 85 ++++++++ ext/standard/tests/dir/dir_variation8.phpt | 63 ++++++ ext/standard/tests/dir/dir_variation9.phpt | 111 ++++++++++ 11 files changed, 1109 insertions(+) create mode 100644 ext/standard/tests/dir/dir_basic.phpt create mode 100644 ext/standard/tests/dir/dir_error.phpt create mode 100644 ext/standard/tests/dir/dir_variation1.phpt create mode 100644 ext/standard/tests/dir/dir_variation2.phpt create mode 100644 ext/standard/tests/dir/dir_variation3.phpt create mode 100644 ext/standard/tests/dir/dir_variation4.phpt create mode 100644 ext/standard/tests/dir/dir_variation5.phpt create mode 100644 ext/standard/tests/dir/dir_variation6.phpt create mode 100644 ext/standard/tests/dir/dir_variation7.phpt create mode 100644 ext/standard/tests/dir/dir_variation8.phpt create mode 100644 ext/standard/tests/dir/dir_variation9.phpt diff --git a/ext/standard/tests/dir/dir_basic.phpt b/ext/standard/tests/dir/dir_basic.phpt new file mode 100644 index 0000000000..dba49dba08 --- /dev/null +++ b/ext/standard/tests/dir/dir_basic.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test dir() function : basic functionality +--FILE-- +read() ); +var_dump( $d->read() ); +var_dump( $d->rewind() ); + +echo "\nTest using handle directly:\n"; +var_dump( readdir($d->handle) ); +var_dump( readdir($d->handle) ); + +echo "\nClose directory:\n"; +var_dump( $d->close() ); +var_dump( $d ); + +echo "\nTest read after closing the dir:"; +var_dump( $d->read() ); + +// delete temp files +delete_files($dir_path, 3, "dir_basic", 1, ".tmp"); +echo "Done"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : basic functionality *** +Get Directory instance: +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_basic" + ["handle"]=> + resource(%d) of type (stream) +} + +Read and rewind: +string(%d) "%s" +string(%d) "%s" +NULL + +Test using handle directly: +string(%d) "%s" +string(%d) "%s" + +Close directory: +NULL +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_basic" + ["handle"]=> + resource(%d) of type (Unknown) +} + +Test read after closing the dir: +Warning: Directory::read(): %d is not a valid Directory resource in %s on line %d +bool(false) +Done \ No newline at end of file diff --git a/ext/standard/tests/dir/dir_error.phpt b/ext/standard/tests/dir/dir_error.phpt new file mode 100644 index 0000000000..f2ef25cc87 --- /dev/null +++ b/ext/standard/tests/dir/dir_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test dir() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing dir() : error conditions *** + +-- Testing dir() function with zero arguments -- +Warning: dir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing dir() function with one more than expected number of arguments -- +Warning: dir() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/dir/dir_variation1.phpt b/ext/standard/tests/dir/dir_variation1.phpt new file mode 100644 index 0000000000..ad912c008f --- /dev/null +++ b/ext/standard/tests/dir/dir_variation1.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test dir() function : usage variations - unexpected value for 'dir' argument +--FILE-- +var = 10; + } +} + +// get a resource variable +$fp = fopen(__FILE__, "r"); // get a file handle +$dfp = opendir( dirname(__FILE__) ); // get a dir handle + +// unexpected values to be passed to $directory argument +$unexpected_values = array ( + + // array data +/*1*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*6*/ NULL, + null, + + // boolean data +/*8*/ true, + false, + TRUE, + FALSE, + + // empty data +/*12*/ "", + '', + + // undefined data +/*14*/ @$undefined_var, + + // unset data +/*15*/ @$unset_var, + + // resource variable(dir and file handle) +/*16*/ $fp, + $dfp, + + // object data +/*18*/ new A() +); + +// loop through various elements of $unexpected_values to check the behavior of dir() +$iterator = 1; +foreach( $unexpected_values as $unexpected_value ) { + echo "\n-- Iteration $iterator --\n"; + var_dump( dir($unexpected_value) ); + $iterator++; +} + +fclose($fp); +closedir($dfp); +echo "Done"; +?> +--EXPECTF-- +*** Testing dir() : unexpected values for $directory argument *** + +-- Iteration 1 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- + +Warning: dir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- + +Warning: dir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- + +Warning: dir() expects parameter 1 to be string, resource given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: dir() expects parameter 1 to be string, resource given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: dir() expects parameter 1 to be string, object given in %s on line %d +NULL +Done \ No newline at end of file diff --git a/ext/standard/tests/dir/dir_variation2.phpt b/ext/standard/tests/dir/dir_variation2.phpt new file mode 100644 index 0000000000..ee42900eec --- /dev/null +++ b/ext/standard/tests/dir/dir_variation2.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test dir() function : usage variations - unexpected value for 'context' argument +--FILE-- +var = 10; + } +} + +// heredoc string +$heredoc = << 'red', 'item' => 'pen'), + + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // object data +/*26*/ new classA(), + + // undefined data +/*27*/ @$undefined_var, + + // unset data +/*28*/ @$unset_var +); + +// loop through various elements of $unexpected_values to check the behavior of dir() +$iterator = 1; +foreach( $unexpected_values as $unexpected_value ) { + echo "\n-- Iteration $iterator --"; + var_dump( dir($directory, $unexpected_value) ); + $iterator++; +} + +echo "Done"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : unexpected values for $context argument *** + +-- Iteration 1 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 15 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 16 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 17 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 18 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 19 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 21 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 23 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 24 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 25 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 26 -- +Warning: dir() expects parameter 2 to be resource, object given in %s on line %d +NULL + +-- Iteration 27 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 28 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL +Done \ No newline at end of file diff --git a/ext/standard/tests/dir/dir_variation3.phpt b/ext/standard/tests/dir/dir_variation3.phpt new file mode 100644 index 0000000000..a3badc79aa --- /dev/null +++ b/ext/standard/tests/dir/dir_variation3.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test dir() function : usage variations - different directory permissions +--SKIPIF-- + +--FILE-- +read()); + + // close directory + $d->close(); +} + +echo "Done"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : different directory permissions *** +-- Iteration 1 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 2 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 3 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 4 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 5 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 6 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 7 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 8 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 9 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 10 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" +Done diff --git a/ext/standard/tests/dir/dir_variation4.phpt b/ext/standard/tests/dir/dir_variation4.phpt new file mode 100644 index 0000000000..62b10b2a86 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation4.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test dir() function : usage variations - operate on previously opened directory +--FILE-- +read() ); // with previous handle + +echo "-- reading directory contents with current handle --\n"; +var_dump( $e->read() ); // with current handle + +// delete temporary files +delete_files($dir_path, 3, "dir_variation4"); +echo "Done"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : operate on previously opened directory *** +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation4" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation4" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading directory contents with previous handle -- +string(%d) "%s" +-- reading directory contents with current handle -- +string(%d) "%s" +Done diff --git a/ext/standard/tests/dir/dir_variation5.phpt b/ext/standard/tests/dir/dir_variation5.phpt new file mode 100644 index 0000000000..2399c634c5 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation5.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test dir() function : usage variations - open a file instead of directory +--FILE-- + +--EXPECTF-- +*** Testing dir() : open a file instead of a directory *** + +Warning: dir(%s): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation6.phpt b/ext/standard/tests/dir/dir_variation6.phpt new file mode 100644 index 0000000000..e42057ed15 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation6.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test dir() function : usage variations - non-existent directory +--FILE-- +close(); //close the dir + +// remove directory and try to open the same(non-existent) directory again +rmdir($dir_path); +clearstatcache(); + +echo "-- opening previously removed directory --\n"; +var_dump( dir($dir_path) ); + +// point to a non-existent directory +$non_existent_dir = $file_path."/non_existent_dir"; +echo "-- opening non-existent directory --\n"; +$d = dir($non_existent_dir); +var_dump( $d ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing dir() : open a non-existent directory *** +-- opening previously removed directory -- + +Warning: dir(%s): failed to open dir: %s in %s on line %d +bool(false) +-- opening non-existent directory -- + +Warning: dir(%s): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation7.phpt b/ext/standard/tests/dir/dir_variation7.phpt new file mode 100644 index 0000000000..baf9a79b54 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation7.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test dir() function : usage variations - directories with restricted permissions +--SKIPIF-- + +--FILE-- + sub_dir ( sub parent ) + |-> child_dir ( child dir) +*/ +$file_path = dirname(__FILE__); +$parent_dir_path = $file_path."/dir_variation7"; +@mkdir($parent_dir_path); +chmod($parent_dir_path, 0777); + +// create sub_dir +$sub_dir_path = $parent_dir_path."/sub_dir"; +@mkdir($sub_dir_path); +chmod($sub_dir_path, 0777); + +//create sub_sub_dir +$child_dir_path = $sub_dir_path."/child_dir"; +@mkdir($child_dir_path); + +// remove the write and execute permisson from sub parent +chmod($sub_dir_path, 0444); +echo "-- After restricting 1st level parent directory --\n"; +$d = dir($child_dir_path); // try to open, expected failure +var_dump( $d ); // dump it + +// remove the execute permisson from parent dir, allowing all permission for sub dir +chmod($sub_dir_path, 0777); // all permisson to sub dir +chmod($parent_dir_path, 0666); // restricting parent directory +echo "-- After restricting parent directory --\n"; +$d = dir($child_dir_path); // try to open, expected failure +var_dump( $d ); // dump it + +echo "Done"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : remove execute permission from the parent dir *** +-- After restricting 1st level parent directory -- + +Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: Permission denied in %s on line %d +bool(false) +-- After restricting parent directory -- + +Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: Permission denied in %s on line %d +bool(false) +Done \ No newline at end of file diff --git a/ext/standard/tests/dir/dir_variation8.phpt b/ext/standard/tests/dir/dir_variation8.phpt new file mode 100644 index 0000000000..41217500d4 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation8.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test dir() function : usage variations - checking with wildcard characters +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : checking with wildcard characters *** +-- wildcard = '*' -- + +Warning: dir(%s/dir_var*): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/*): failed to open dir: %s in %s on line %d +bool(false) +-- wildcard = '?' -- + +Warning: dir(%s/dir_variation81/sub_dir?): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation81/sub?dir1): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation9.phpt b/ext/standard/tests/dir/dir_variation9.phpt new file mode 100644 index 0000000000..22f3d5baab --- /dev/null +++ b/ext/standard/tests/dir/dir_variation9.phpt @@ -0,0 +1,111 @@ +--TEST-- +Test dir() function : usage variations - relative valid and invalid paths +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing dir() : checking with valid and invalid paths *** + +-- With valid paths -- +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/.." + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir11/.." + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/.." + ["handle"]=> + resource(%d) of type (stream) +} + +-- With invalid paths -- + +Warning: dir(%s/dir_variation91/sub_dir12/sub_dir111/..): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation92/sub_dir21/../dir_variation91): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir12/..): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation91/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..): failed to open dir: %s in %s on line %d +bool(false) +Done -- 2.50.1