From 94565fb45068db3debe86c33cf1ac2436f652483 Mon Sep 17 00:00:00 2001 From: Josie Messa Date: Tue, 4 Mar 2008 10:39:32 +0000 Subject: [PATCH] - new tests for opendir() function --- ext/standard/tests/dir/opendir_basic.phpt | 62 +++++ ext/standard/tests/dir/opendir_error1.phpt | 47 ++++ ext/standard/tests/dir/opendir_error2.phpt | 37 +++ .../tests/dir/opendir_variation1.phpt | 218 ++++++++++++++++ .../tests/dir/opendir_variation2.phpt | 239 ++++++++++++++++++ .../tests/dir/opendir_variation3.phpt | 50 ++++ .../tests/dir/opendir_variation4.phpt | 107 ++++++++ .../tests/dir/opendir_variation5.phpt | 103 ++++++++ .../tests/dir/opendir_variation6.phpt | 61 +++++ .../tests/dir/opendir_variation7.phpt | 127 ++++++++++ 10 files changed, 1051 insertions(+) create mode 100644 ext/standard/tests/dir/opendir_basic.phpt create mode 100644 ext/standard/tests/dir/opendir_error1.phpt create mode 100644 ext/standard/tests/dir/opendir_error2.phpt create mode 100644 ext/standard/tests/dir/opendir_variation1.phpt create mode 100644 ext/standard/tests/dir/opendir_variation2.phpt create mode 100644 ext/standard/tests/dir/opendir_variation3.phpt create mode 100644 ext/standard/tests/dir/opendir_variation4.phpt create mode 100644 ext/standard/tests/dir/opendir_variation5.phpt create mode 100644 ext/standard/tests/dir/opendir_variation6.phpt create mode 100644 ext/standard/tests/dir/opendir_variation7.phpt diff --git a/ext/standard/tests/dir/opendir_basic.phpt b/ext/standard/tests/dir/opendir_basic.phpt new file mode 100644 index 0000000000..17ada17ea6 --- /dev/null +++ b/ext/standard/tests/dir/opendir_basic.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test opendir() function : basic functionality +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : basic functionality *** + +-- Testing opendir() with absolute path: -- +resource(%d) of type (stream) + +-- Testing opendir() with relative paths: -- +bool(true) +resource(%d) of type (stream) + +-- Close directory handles: -- +resource(%d) of type (Unknown) +resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_error1.phpt b/ext/standard/tests/dir/opendir_error1.phpt new file mode 100644 index 0000000000..92b8eee1bd --- /dev/null +++ b/ext/standard/tests/dir/opendir_error1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test opendir() function : error conditions - Incorrect number of args +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : error conditions *** + +-- Testing opendir() function with Zero arguments -- + +Warning: opendir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing opendir() function with more than expected no. of arguments -- + +Warning: opendir() expects at most 2 parameters, 3 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/opendir_error2.phpt b/ext/standard/tests/dir/opendir_error2.phpt new file mode 100644 index 0000000000..9b3a110bcd --- /dev/null +++ b/ext/standard/tests/dir/opendir_error2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test opendir() function : error conditions - Non-existent directory +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing opendir() : error conditions *** + +-- Pass a non-existent absolute path: -- + +Warning: opendir(%s/idonotexist): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Pass a non-existent relative path: -- + +Warning: opendir(idonotexist): failed to open dir: No such file or directory in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation1.phpt b/ext/standard/tests/dir/opendir_variation1.phpt new file mode 100644 index 0000000000..bcf64dd26e --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test opendir() function : usage variations - different data types as $path arg +--FILE-- +path = $path; + } + public function __toString() { + return $this->path; + } +} + +// heredoc string +$heredoc = << +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Iteration 1 -- + +Warning: opendir(0): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: opendir(1): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: opendir(12345): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: opendir(-2345): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: opendir(10.5): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: opendir(-10.5): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: opendir(123456789000): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: opendir(1.23456789E-9): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: opendir(0.5): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- + +Warning: opendir(1): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- + +Warning: opendir(1): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- + +Warning: opendir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 19 -- +resource(%d) of type (stream) + +-- Iteration 20 -- + +Warning: opendir(string): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Iteration 21 -- +resource(%d) of type (stream) + +-- Iteration 22 -- +resource(%d) of type (stream) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- +bool(false) + +-- Iteration 25 -- + +Warning: opendir() expects parameter 1 to be string, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation2.phpt b/ext/standard/tests/dir/opendir_variation2.phpt new file mode 100644 index 0000000000..4236bec84b --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation2.phpt @@ -0,0 +1,239 @@ +--TEST-- +Test opendir() function : usage variations - different data types as $context arg +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- Iteration 1 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: opendir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: opendir() expects parameter 2 to be resource, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: opendir(): supplied resource is not a valid Stream-Context resource in %s on line %d +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation3.phpt b/ext/standard/tests/dir/opendir_variation3.phpt new file mode 100644 index 0000000000..3de0dd3701 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation3.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test opendir() function : usage variations - open a directory twice +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- Open directory first time: -- +resource(%d) of type (stream) + +-- Open directory second time: -- +resource(%d) of type (stream) + +New resource created +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation4.phpt b/ext/standard/tests/dir/opendir_variation4.phpt new file mode 100644 index 0000000000..b20641740b --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation4.phpt @@ -0,0 +1,107 @@ +--TEST-- +Test opendir() function : usage variations - different relative paths +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- $path = './level_one': -- +bool(true) +resource(%d) of type (stream) + +-- $path = 'level_one/level_two': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '..': -- +resource(%d) of type (stream) + +-- $path = 'level_two', '.': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '../': -- +resource(%d) of type (stream) + +-- $path = './': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '../../'level_one': -- +bool(true) +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation5.phpt b/ext/standard/tests/dir/opendir_variation5.phpt new file mode 100644 index 0000000000..39caf3d713 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation5.phpt @@ -0,0 +1,103 @@ +--TEST-- +Test opendir() function : usage variations - directories with restricted permissions +--SKIPIF-- + +--FILE-- + sub_dir ( sub parent ) + * |-> child_dir ( child dir) + */ + +$parent_dir_path = dirname(__FILE__) . "/opendir_variation5"; +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 "\n-- After restricting 1st level parent directory --\n"; +$dir_handle1 = opendir($child_dir_path); +var_dump( $dir_handle1 ); + +// 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 "\n-- After restricting parent directory --\n"; +$dir_handle2 = opendir($child_dir_path); // try to open, expected failure +var_dump( $dir_handle2 ); // dump it + +if (is_resource($dir_handle1)) { + closedir($dir_handle1); +} +if (is_resource($dir_handle2)) { + closedir($dir_handle2); +} +?> +===DONE=== +--CLEAN-- + + +--EXPECTF-- +"*** Testing opendir() : usage variations *** + +-- After restricting 1st level parent directory -- + +Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: Permission denied in %s on line %d +bool(false) + +-- After restricting parent directory -- + +Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: Permission denied in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation6.phpt b/ext/standard/tests/dir/opendir_variation6.phpt new file mode 100644 index 0000000000..29dfd948e9 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation6.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test opendir() function : usage variations - Different wildcards +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Wildcard = '*' -- + +Warning: opendir(%s/opendir_var*): failed to open dir: No such file or directory in %s on line %d +bool(false) + +Warning: opendir(%s/*): failed to open dir: No such file or directory in %s on line %d +bool(false) + +-- Wildcard = '?' -- + +Warning: opendir(%s/opendir_variation6/sub_dir?): failed to open dir: No such file or directory in %s on line %d +bool(false) + +Warning: opendir(%s/opendir_variation6/sub?dir1): failed to open dir: No such file or directory in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation7.phpt b/ext/standard/tests/dir/opendir_variation7.phpt new file mode 100644 index 0000000000..2ad41b1d31 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation7.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test opendir() function : usage variations - different directory permissions +--SKIPIF-- + +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Iteration 1 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 2 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 3 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 4 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 5 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 6 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 7 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 8 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 9 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 10 -- +bool(true) +resource(%d) of type (stream) +===DONE=== -- 2.40.0