summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghubansh Kumar <kraghuba@php.net>2007-07-21 17:24:29 +0000
committerRaghubansh Kumar <kraghuba@php.net>2007-07-21 17:24:29 +0000
commite889f297f3b31057c1328f6f9f08014424d43a31 (patch)
treec41a61903f5a83402d41bcdcc74553125c13ea6a
parente41c15f71e24cf456f6817a897038ce472ea1a84 (diff)
downloadphp-git-e889f297f3b31057c1328f6f9f08014424d43a31.tar.gz
New testcases for is_dir() function
-rw-r--r--ext/standard/tests/file/is_dir_variation1.phpt51
-rw-r--r--ext/standard/tests/file/is_dir_variation2.phpt103
-rw-r--r--ext/standard/tests/file/is_dir_variation3.phpt61
-rw-r--r--ext/standard/tests/file/is_dir_variation4.phpt118
4 files changed, 333 insertions, 0 deletions
diff --git a/ext/standard/tests/file/is_dir_variation1.phpt b/ext/standard/tests/file/is_dir_variation1.phpt
new file mode 100644
index 0000000000..ef14d562ab
--- /dev/null
+++ b/ext/standard/tests/file/is_dir_variation1.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test is_dir() function: usage variations - dir/subdir
+--FILE--
+<?php
+/* Prototype: bool is_dir ( string $dirname );
+ Description: Tells whether the dirname is a directory
+ Returns TRUE if the dirname exists and is a directory, FALSE otherwise.
+*/
+
+/* Testing is_dir() with base and sub dirs */
+
+$file_path = dirname(__FILE__);
+
+echo "-- Testing is_dir() with an empty dir --\n";
+$dirname = $file_path."/is_dir_variation1";
+mkdir($dirname);
+var_dump( is_dir($dirname) );
+clearstatcache();
+
+echo "-- Testing is_dir() with a subdir in base dir --\n";
+$subdirname = $dirname."/is_dir_variation1_sub";
+mkdir($subdirname);
+var_dump( is_dir($subdirname) );
+var_dump( is_dir($dirname) );
+
+echo "\n*** Done ***";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$dir_name = $file_path."/is_dir_variation1";
+unlink($file_path."/is_dir_variation1.tmp");
+rmdir($dir_name."/is_dir_variation1_sub");
+rmdir($dir_name);
+?>
+--EXPECTF--
+-- Testing is_dir() with an empty dir --
+bool(true)
+-- Testing is_dir() with a subdir in base dir --
+bool(true)
+bool(true)
+
+*** Done ***
+--UEXPECTF--
+-- Testing is_dir() with an empty dir --
+bool(true)
+-- Testing is_dir() with a subdir in base dir --
+bool(true)
+bool(true)
+
+*** Done ***
diff --git a/ext/standard/tests/file/is_dir_variation2.phpt b/ext/standard/tests/file/is_dir_variation2.phpt
new file mode 100644
index 0000000000..3c994a748a
--- /dev/null
+++ b/ext/standard/tests/file/is_dir_variation2.phpt
@@ -0,0 +1,103 @@
+--TEST--
+Test is_dir() function: usage variations - links
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip Do not run on Windows');
+}
+--FILE--
+<?php
+/* Prototype: bool is_dir ( string $dirname );
+ Description: Tells whether the dirname is a directory
+ Returns TRUE if the dirname exists and is a directory, FALSE otherwise.
+*/
+
+/* Testing is_dir() with dir, soft & hard link to dir,
+ and with file, soft & hard link to file */
+
+$file_path = dirname(__FILE__);
+
+echo "*** Testing is_dir() with dir and links to dir ***\n";
+echo "-- With dir --\n";
+$dirname = $file_path."/is_dir_variation2";
+mkdir($dirname);
+var_dump( is_dir($dirname) );
+clearstatcache();
+
+echo "-- With symlink --\n";
+symlink($file_path."/is_dir_variation2", $file_path."/is_dir_variation2_symlink");
+var_dump( is_dir($file_path."/is_dir_variation2_symlink") ); //is_dir() resolves symlinks
+clearstatcache();
+
+echo "-- With hardlink --";
+link($file_path."/is_dir_variation2", $file_path."/is_dir_variation2_link"); //Not permitted to create hard-link to a dir
+var_dump( is_dir($file_path."/is_dir_variation2_link") );
+clearstatcache();
+
+echo "\n*** Testing is_dir() with file and links to a file ***\n";
+echo "-- With file --\n";
+$filename = $file_path."/is_dir_variation2.tmp";
+fclose( fopen($filename, "w") );
+var_dump( is_dir($filename) );
+clearstatcache();
+
+echo "-- With symlink --\n";
+symlink($file_path."/is_dir_variation2.tmp", $file_path."/is_dir_variation2_symlink.tmp");
+var_dump( is_dir($file_path."/is_dir_variation2_symlink.tmp") );
+clearstatcache();
+
+echo "-- With hardlink --\n";
+link($file_path."/is_dir_variation2.tmp", $file_path."/is_dir_variation2_link.tmp");
+var_dump( is_dir($file_path."/is_dir_variation2_link.tmp") );
+clearstatcache();
+
+echo "\n*** Done ***";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink($file_path."/is_dir_variation2_symlink");
+unlink($file_path."/is_dir_variation2_link");
+unlink($file_path."/is_dir_variation2_symlink.tmp");
+unlink($file_path."/is_dir_variation2_link.tmp");
+unlink($file_path."/is_dir_variation2.tmp");
+rmdir($file_path."/is_dir_variation2");
+?>
+--EXPECTF--
+*** Testing is_dir() with dir and links to dir ***
+-- With dir --
+bool(true)
+-- With symlink --
+bool(true)
+-- With hardlink --
+Warning: link(): Operation not permitted in %s on line %d
+bool(false)
+
+*** Testing is_dir() with file and links to a file ***
+-- With file --
+bool(false)
+-- With symlink --
+bool(false)
+-- With hardlink --
+bool(false)
+
+*** Done ***
+--UEXPECTF--
+*** Testing is_dir() with dir and links to dir ***
+-- With dir --
+bool(true)
+-- With symlink --
+bool(true)
+-- With hardlink --
+Warning: link(): Operation not permitted in %s on line %d
+bool(false)
+
+*** Testing is_dir() with file and links to a file ***
+-- With file --
+bool(false)
+-- With symlink --
+bool(false)
+-- With hardlink --
+bool(false)
+
+*** Done ***
diff --git a/ext/standard/tests/file/is_dir_variation3.phpt b/ext/standard/tests/file/is_dir_variation3.phpt
new file mode 100644
index 0000000000..65ac1b9e2f
--- /dev/null
+++ b/ext/standard/tests/file/is_dir_variation3.phpt
@@ -0,0 +1,61 @@
+--TEST--
+Test is_dir() function: usage variations - invalid arguments
+--FILE--
+<?php
+/* Prototype: bool is_dir ( string $dirname );
+ Description: Tells whether the dirname is a directory
+ Returns TRUE if the dirname exists and is a directory, FALSE otherwise.
+*/
+
+/* Passing invalid arguments to is_dir() */
+
+$dir_handle = opendir( dirname(__FILE__) );
+
+echo "*** Testing is_dir() with Invalid arguments: expected bool(false) ***\n";
+$dirnames = array(
+ /* Invalid dirnames */
+ -2.34555,
+ TRUE,
+ FALSE,
+ NULL,
+ $dir_handle,
+
+ /* Non-existing dirnames */
+ 0,
+ 1234
+);
+
+/* loop through to test each element the above array */
+foreach($dirnames as $dirname) {
+ var_dump( is_dir($dirname) );
+}
+closedir($dir_handle);
+
+echo "\n*** Done ***";
+?>
+--EXPECTF--
+*** Testing is_dir() with Invalid arguments: expected bool(false) ***
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: is_dir() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
+NULL
+bool(false)
+bool(false)
+
+*** Done ***
+--UEXPECTF--
+*** Testing is_dir() with Invalid arguments: expected bool(false) ***
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: is_dir() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
+NULL
+bool(false)
+bool(false)
+
+*** Done ***
diff --git a/ext/standard/tests/file/is_dir_variation4.phpt b/ext/standard/tests/file/is_dir_variation4.phpt
new file mode 100644
index 0000000000..373e23ddbc
--- /dev/null
+++ b/ext/standard/tests/file/is_dir_variation4.phpt
@@ -0,0 +1,118 @@
+--TEST--
+Test is_dir() function: usage variations - diff. path notations
+--FILE--
+<?php
+/* Prototype: bool is_dir ( string $dirname );
+ Description: Tells whether the dirname is a directory
+ Returns TRUE if the dirname exists and is a directory, FALSE otherwise.
+*/
+
+/* Passing dir names with different notations, using slashes, wild-card chars */
+
+$file_path = dirname(__FILE__);
+
+echo "*** Testing is_dir() with different notations of dir names ***";
+$dir_name = "/is_dir_variation4";
+mkdir($file_path.$dir_name);
+
+$dirs_arr = array(
+ "is_dir_variation4",
+ "./is_dir_variation4",
+
+ /* Testing a file trailing slash */
+ "is_dir_variation4/",
+ "./is_dir_variation4/",
+
+ /* Testing file with double trailing slashes */
+ "is_dir_variation4//",
+ "./is_dir_variation4//",
+ ".//is_dir_variation4//",
+ "is_dir_vari*",
+
+ /* Testing Binary safe */
+ "./is_dir_variation4/".chr(0),
+ "is_dir_variation4\0"
+);
+
+$count = 1;
+/* loop through to test each element the above array */
+foreach($dirs_arr as $dir) {
+ echo "\n-- Iteration $count --\n";
+ var_dump( is_dir($file_path."/".$dir ) );
+ $count++;
+}
+
+echo "\n*** Done ***";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$dir_name = $file_path."/is_dir_variation4";
+rmdir($dir_name);
+?>
+--EXPECTF--
+*** Testing is_dir() with different notations of dir names ***
+-- Iteration 1 --
+bool(true)
+
+-- Iteration 2 --
+bool(true)
+
+-- Iteration 3 --
+bool(true)
+
+-- Iteration 4 --
+bool(true)
+
+-- Iteration 5 --
+bool(true)
+
+-- Iteration 6 --
+bool(true)
+
+-- Iteration 7 --
+bool(true)
+
+-- Iteration 8 --
+bool(false)
+
+-- Iteration 9 --
+bool(true)
+
+-- Iteration 10 --
+bool(true)
+
+*** Done ***
+--UEXPECTF--
+*** Testing is_dir() with different notations of dir names ***
+-- Iteration 1 --
+bool(true)
+
+-- Iteration 2 --
+bool(true)
+
+-- Iteration 3 --
+bool(true)
+
+-- Iteration 4 --
+bool(true)
+
+-- Iteration 5 --
+bool(true)
+
+-- Iteration 6 --
+bool(true)
+
+-- Iteration 7 --
+bool(true)
+
+-- Iteration 8 --
+bool(false)
+
+-- Iteration 9 --
+bool(true)
+
+-- Iteration 10 --
+bool(true)
+
+*** Done ***