diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-07-21 17:31:42 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-07-21 17:31:42 +0000 |
commit | 7cefd7792c4356f08273429f73a8da6a5f93cb01 (patch) | |
tree | 74fd0cd08fe4cefa76d1100908fb6e4fcf4cb29a /ext | |
parent | 0e6b39f51565f5c9cf7c784b97c7d82606f47fb5 (diff) | |
download | php-git-7cefd7792c4356f08273429f73a8da6a5f93cb01.tar.gz |
New testcases for is_dir() function
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/tests/file/is_dir_variation1.phpt | 43 | ||||
-rw-r--r-- | ext/standard/tests/file/is_dir_variation2.phpt | 84 | ||||
-rw-r--r-- | ext/standard/tests/file/is_dir_variation3.phpt | 46 | ||||
-rw-r--r-- | ext/standard/tests/file/is_dir_variation4.phpt | 85 |
4 files changed, 258 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..4f85ba93bb --- /dev/null +++ b/ext/standard/tests/file/is_dir_variation1.phpt @@ -0,0 +1,43 @@ +--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 *** 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..df2464d3c2 --- /dev/null +++ b/ext/standard/tests/file/is_dir_variation2.phpt @@ -0,0 +1,84 @@ +--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 *** 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..c9b20420c7 --- /dev/null +++ b/ext/standard/tests/file/is_dir_variation3.phpt @@ -0,0 +1,46 @@ +--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, + + /* scalars */ + 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) +bool(false) +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..a68fe0b005 --- /dev/null +++ b/ext/standard/tests/file/is_dir_variation4.phpt @@ -0,0 +1,85 @@ +--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 *** |