kraghuba Sat Jul 21 17:25:59 2007 UTC Added files: /php-src/ext/standard/tests/file is_file_variation1.phpt is_file_variation2.phpt is_file_variation3.phpt is_file_variation4.phpt Log: New testcases for is_file() function
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/is_file_variation1.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/file/is_file_variation1.phpt +++ php-src/ext/standard/tests/file/is_file_variation1.phpt --TEST-- Test is_file() function: usage variations - diff. files --FILE-- <?php /* Prototype: bool is_file ( string $filename ); Description: Tells whether the filename is a regular file Returns TRUE if the filename exists and is a regular file */
/* Testing is_file() with file containing data, truncating its size and the file created by touch() */ $file_path = dirname(__FILE__); echo "-- Testing is_file() with file containing data --\n"; $filename = $file_path."/is_file_variation1.tmp"; $file_handle = fopen($filename, "w" ); fwrite( $file_handle, "Hello, world....." ); // exptected true fclose($file_handle); var_dump( is_file($filename) ); clearstatcache(); echo "\n-- Testing is_file() after truncating filesize to zero bytes --\n"; $file_handle = fopen( $file_path."/is_file_variation1.tmp", "r"); ftruncate($file_handle, 0); fclose($file_handle); var_dump( is_file($file_path."/is_file_variation1.tmp") ); // expected true clearstatcache(); unlink($file_path."/is_file_variation1.tmp"); echo "\n-- Testing is_file() with an empty file --\n"; /* created by fopen() */ fclose( fopen($file_path."/is_file_variation1.tmp", "w") ); var_dump( is_file($file_path."/is_file_variation1.tmp") ); //expected true clearstatcache(); unlink($file_path."/is_file_variation1.tmp"); /* created by touch() */ touch($file_path."/is_file_variation1.tmp"); var_dump( is_file($file_path."/is_file_variation1.tmp") ); // expected true clearstatcache(); unlink($file_path."/is_file_variation1.tmp"); echo "\n*** Done ***"; ?> --EXPECTF-- -- Testing is_file() with file containing data -- bool(true) -- Testing is_file() after truncating filesize to zero bytes -- bool(true) -- Testing is_file() with an empty file -- bool(true) bool(true) *** Done *** --UEXPECTF-- -- Testing is_file() with file containing data -- Notice: fwrite(): 17 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d bool(true) -- Testing is_file() after truncating filesize to zero bytes -- bool(true) -- Testing is_file() with an empty file -- bool(true) bool(true) *** Done *** http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/is_file_variation2.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/file/is_file_variation2.phpt +++ php-src/ext/standard/tests/file/is_file_variation2.phpt --TEST-- Test is_file() 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_file ( string $filename ); Description: Tells whether the filename is a regular file Returns TRUE if the filename exists and is a regular file */ /* Creating soft and hard links to a file and applying is_file() on links */ $file_path = dirname(__FILE__); fclose( fopen($file_path."/is_file_variation2.tmp", "w") ); echo "*** Testing is_file() with links ***\n"; /* With symlink */ symlink($file_path."/is_file_variation2.tmp", $file_path."/is_file_variation2_symlink.tmp"); var_dump( is_file($file_path."/is_file_variation2_symlink.tmp") ); //expected true clearstatcache(); /* With hardlink */ link($file_path."/is_file_variation2.tmp", $file_path."/is_file_variation2_link.tmp"); var_dump( is_file($file_path."/is_file_variation2_link.tmp") ); // expected: true clearstatcache(); echo "\n*** Done ***"; ?> --CLEAN-- <?php $file_path = dirname(__FILE__); unlink($file_path."/is_file_variation2_symlink.tmp"); unlink($file_path."/is_file_variation2_link.tmp"); unlink($file_path."/is_file_variation2.tmp"); ?> --EXPECTF-- *** Testing is_file() with links *** bool(true) bool(true) *** Done *** --UEXPECTF-- *** Testing is_file() with links *** bool(true) bool(true) *** Done *** http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/is_file_variation3.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/file/is_file_variation3.phpt +++ php-src/ext/standard/tests/file/is_file_variation3.phpt --TEST-- Test is_file() function: usage variations - invalid arguments --FILE-- <?php /* Prototype: bool is_file ( string $filename ); Description: Tells whether the filename is a regular file Returns TRUE if the filename exists and is a regular file */ /* Testing is_file() with invalid arguments -int, float, bool, NULL, resource */ $file_path = dirname(__FILE__); $file_handle = fopen($file_path."/is_file_variation3.tmp", "w"); echo "*** Testing Invalid file types ***\n"; $filenames = array( /* Invalid filenames */ -2.34555, "", TRUE, FALSE, NULL, $file_handle, /* scalars */ 1234, 0 ); /* loop through to test each element the above array */ foreach( $filenames as $filename ) { var_dump( is_file($filename) ); clearstatcache(); } fclose($file_handle); echo "\n*** Done ***"; ?> --CLEAN-- <?php $file_path = dirname(__FILE__); unlink($file_path."/is_file_variation3.tmp"); ?> --EXPECTF-- *** Testing Invalid file types *** bool(false) bool(false) bool(false) bool(false) bool(false) Warning: is_file() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d NULL bool(false) bool(false) *** Done *** --UEXPECTF-- *** Testing Invalid file types *** bool(false) bool(false) bool(false) bool(false) bool(false) Warning: is_file() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d NULL bool(false) bool(false) *** Done *** http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/is_file_variation4.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/file/is_file_variation4.phpt +++ php-src/ext/standard/tests/file/is_file_variation4.phpt --TEST-- Test is_file() function: usage variations - diff. path notations(fails on linux, see bug#42027) --FILE-- <?php /* Prototype: bool is_file ( string $filename ); Description: Tells whether the filename is a regular file Returns TRUE if the filename exists and is a regular file */ /* Passing file names with different notations, using slashes, wild-card chars */ $file_path = dirname(__FILE__); echo "*** Testing is_file() with different notations of file names ***\n"; $dir_name = $file_path."/is_file_variation4"; mkdir($dir_name); $file_handle = fopen($dir_name."/is_file_variation4.tmp", "w"); fclose($file_handle); $files_arr = array( "/is_file_variation4/is_file_variation4.tmp", /* Testing a file trailing slash */ "/is_file_variation4/is_file_variation4.tmp/", /* Testing file with double slashes */ "/is_file_variation4//is_file_variation4.tmp", "//is_file_variation4//is_file_variation4.tmp", "/is_file_variation4/*.tmp", "is_file_variation4/is_file*.tmp", /* Testing Binary safe */ "/is_file_variation4/is_file_variation4.tmp".chr(0), "/is_file_variation4/is_file_variation4.tmp\0" ); $count = 1; /* loop through to test each element in the above array */ foreach($files_arr as $file) { echo "- Iteration $count -\n"; var_dump( is_file( $file_path."/".$file ) ); clearstatcache(); $count++; } echo "\n*** Done ***"; ?> --CLEAN-- <?php $file_path = dirname(__FILE__); $dir_name = $file_path."/is_file_variation4"; unlink($dir_name."/is_file_variation4.tmp"); rmdir($dir_name); ?> --EXPECTF-- *** Testing is_file() with different notations of file 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(true) *** Done *** --UEXPECTF-- *** Testing is_file() with different notations of file 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(true) *** Done ***
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php