--- /dev/null
+--TEST--
+Test disk_free_space and its alias diskfreespace() functions : basic functionality
+--FILE--
+<?php
+/*
+ * Prototype: float disk_free_space( string directory )
+ * Description: Given a string containing a directory, this function
+ * will return the number of bytes available on the corresponding
+ * filesystem or disk partition
+ */
+
+$file_path = dirname(__FILE__);
+include($file_path."/file.inc");
+
+echo "*** Testing with existing directory ***\n";
+var_dump( disk_free_space($file_path) );
+var_dump( diskfreespace($file_path) );
+$dir = "/disk_free_space";
+
+echo "*** Testing with newly created directory ***\n";
+mkdir($file_path.$dir);
+echo" \n Free Space before writing to a file\n";
+$space1 = disk_free_space($file_path.$dir);
+var_dump($space1);
+
+fill_buffer($buffer, "text", 3000000);
+file_put_contents($file_path.$dir."/disk_free_space.tmp", $buffer);
+
+echo "\n Free Space after writing to a file\n";
+$space2 = disk_free_space($file_path.$dir);
+var_dump( $space2 );
+
+if( $space1 > $space2 )
+ echo "\n Free Space Value Is Correct\n";
+else
+ echo "\n Free Space Value Is Incorrect\n";
+
+echo"\n-- Done --";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$dir = "/disk_free_space";
+unlink($file_path.$dir."/disk_free_space.tmp");
+rmdir($file_path.$dir);
+?>
+
+--EXPECTF--
+*** Testing with existing directory ***
+float(%d)
+float(%d)
+*** Testing with newly created directory ***
+
+ Free Space before writing to a file
+float(%d)
+
+ Free Space after writing to a file
+float(%d)
+
+ Free Space Value Is Correct
+
+-- Done --
--- /dev/null
+--TEST--
+Test disk_free_space and its alias diskfreespace() functions : usage variations
+--FILE--
+<?php
+/*
+ * Prototype: float disk_free_space( string directory )
+ * Description: Given a string containing a directory, this function
+ * will return the number of bytes available on the corresponding
+ * filesystem or disk partition
+ */
+
+$file_path = dirname(__FILE__);
+
+echo "*** Testing disk_free_space() function with a directory ***\n";
+var_dump( disk_free_space($file_path."/..") );
+var_dump( diskfreespace($file_path."/..") );
+
+echo "\n*** Testing for the return type ***\n";
+$return_value = disk_free_space($file_path);
+var_dump( is_float($return_value) );
+
+echo "\n*** Testing disk_free_space() function with different styles of file and directory ***";
+
+$dir = "/disk_free_space";
+mkdir($file_path.$dir);
+
+$dirs_arr = array(
+ ".",
+ $file_path.$dir,
+ $file_path."/.".$dir,
+
+ /* Testing a file trailing slash */
+ $file_path."".$dir."/",
+ $file_path."/.".$dir."/",
+
+ /* Testing file with double trailing slashes */
+ $file_path.$dir."//",
+ $file_path."/.".$dir."//",
+ $file_path."/./".$dir."//",
+
+ /* Testing Binary safe */
+ $file_path.$dir.chr(0),
+ $file_path."/.".$dir.chr(0),
+ ".".chr(0).$file_path.$dir,
+ ".".chr(0).$file_path.$dir.chr(0)
+);
+
+$count = 1;
+/* loop through to test each element the above array */
+foreach($dirs_arr as $dir) {
+ echo "\n-- Iteration $count --\n";
+ var_dump( disk_free_space( $dir ) );
+ var_dump( diskfreespace( $dir ) );
+ $count++;
+}
+
+echo"\n--- Done ---";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__)."/disk_free_space";
+rmdir($file_path);
+?>
+
+--EXPECTF--
+*** Testing disk_free_space() function with a directory ***
+float(%d)
+float(%d)
+
+*** Testing for the return type ***
+bool(true)
+
+*** Testing disk_free_space() function with different styles of file and directory ***
+-- Iteration 1 --
+float(%d)
+float(%d)
+
+-- Iteration 2 --
+float(%d)
+float(%d)
+
+-- Iteration 3 --
+float(%d)
+float(%d)
+
+-- Iteration 4 --
+float(%d)
+float(%d)
+
+-- Iteration 5 --
+float(%d)
+float(%d)
+
+-- Iteration 6 --
+float(%d)
+float(%d)
+
+-- Iteration 7 --
+float(%d)
+float(%d)
+
+-- Iteration 8 --
+float(%d)
+float(%d)
+
+-- Iteration 9 --
+float(%d)
+float(%d)
+
+-- Iteration 10 --
+float(%d)
+float(%d)
+
+-- Iteration 11 --
+float(%d)
+float(%d)
+
+-- Iteration 12 --
+float(%d)
+float(%d)
+
+--- Done ---
--- /dev/null
+--TEST--
+Test disk_total_space() function : basic functionality
+--FILE--
+<?php
+/*
+ * Prototype: float disk_total_space( string $directory );
+ * Description: given a string containing a directory, this
+ * function will return the total number of bytes
+ * on the corresponding filesyatem or disk partition.
+ */
+
+$file_path = dirname(__FILE__);
+
+echo "*** Testing with existing directory ***\n";
+var_dump( disk_total_space($file_path) );
+
+echo "*** Testing with newly created directory ***\n";
+mkdir($file_path."/disk_total_space");
+var_dump( disk_total_space($file_path."/disk_total_space") );
+
+$fh = fopen($file_path."/disk_total_space/disk_total_space.tmp", "w");
+fwrite($fh, "Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data");
+
+fclose($fh);
+
+echo" \n Total Space after writing to a file\n";
+var_dump( disk_total_space($file_path."/disk_total_space") );
+
+echo"\n--- Done ---";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink($file_path."/disk_total_space/disk_total_space.tmp");
+rmdir($file_path."/disk_total_space");
+?>
+
+--EXPECTF--
+*** Testing with existing directory ***
+float(%d)
+*** Testing with newly created directory ***
+float(%d)
+
+ Total Space after writing to a file
+float(%d)
+
+--- Done ---
--- /dev/null
+--TEST--
+Test disk_total_space() functions : usage variations
+--FILE--
+<?php
+/*
+ * Prototype: float disk_total_space( string directory )
+ * Description: given a string containing a directory, this function
+ * will return the total number of bytes on the corresponding
+ * filesystem or disk partition.
+ */
+
+$file_path = dirname(__FILE__);
+
+echo "*** Testing with a directory ***\n";
+var_dump( disk_total_space($file_path."/..") );
+
+echo "\nTesting for the return type ***\n";
+$return_value = disk_total_space($file_path);
+var_dump( is_float($return_value) );
+
+echo "\n*** Testing disk_total_space() function with different directory combinations ***";
+
+$dir = "/disk_total_space";
+mkdir($file_path.$dir);
+
+$dirs_arr = array(
+ ".",
+ $file_path.$dir,
+ $file_path."/.".$dir,
+
+ /* Testing a file trailing slash */
+ $file_path.$dir."/",
+ $file_path."/.".$dir."/",
+
+ /* Testing file with double trailing slashes */
+ $file_path.$dir."//",
+ $file_path."/.".$dir."//",
+ $file_path."/./".$dir."//",
+
+ /* Testing Binary safe */
+ $file_path.$dir.chr(0),
+ $file_path."/.".$dir.chr(0),
+ ".".chr(0).$file_path.$dir,
+ ".".chr(0).$file_path.$dir.chr(0)
+);
+
+$count = 1;
+/* loop through to test each element the above array */
+foreach($dirs_arr as $dir1) {
+ echo "\n-- Iteration $count --\n";
+ var_dump( disk_total_space( $dir1 ) );
+ $count++;
+}
+
+echo"\n--- Done ---";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$dir = "/disk_total_space";
+rmdir($file_path.$dir);
+?>
+--EXPECTF--
+*** Testing with a directory ***
+float(%d)
+
+Testing for the return type ***
+bool(true)
+
+*** Testing disk_total_space() function with different directory combinations ***
+-- Iteration 1 --
+float(%d)
+
+-- Iteration 2 --
+float(%d)
+
+-- Iteration 3 --
+float(%d)
+
+-- Iteration 4 --
+float(%d)
+
+-- Iteration 5 --
+float(%d)
+
+-- Iteration 6 --
+float(%d)
+
+-- Iteration 7 --
+float(%d)
+
+-- Iteration 8 --
+float(%d)
+
+-- Iteration 9 --
+float(%d)
+
+-- Iteration 10 --
+float(%d)
+
+-- Iteration 11 --
+float(%d)
+
+-- Iteration 12 --
+float(%d)
+
+--- Done ---
--- /dev/null
+--TEST--
+Test file() function : basic functionality
+--FILE--
+<?php
+/*
+ * Prototype: array file ( string filename [,int use-include_path [,resource context]] );
+ * Description: Reads entire file into an array
+ * Returns the file in an array
+ */
+require(dirname(__FILE__) . '/file.inc');
+$file_path = dirname(__FILE__);
+echo "*** Testing file() with basic files ***\n";
+$filetypes = array("numeric", "text", "empty", "text_with_new_line");
+
+foreach( $filetypes as $type ) {
+ create_files($file_path, 1, $type, 0755, 100, "w", "file", 1, "byte");
+ print_r( file($file_path."/file1.tmp") );
+ delete_files($file_path, 1);
+}
+
+echo "*** Testing for return type of file function ***\n";
+foreach( $filetypes as $type ) {
+ create_files($file_path, 1, $type);
+ $ret_arr = file($file_path."/file1.tmp");
+ var_dump( is_array($ret_arr) );
+ delete_files($file_path, 1);
+}
+
+echo "\n--- Done ---";
+?>
+--EXPECTF--
+*** Testing file() with basic files ***
+Array
+(
+ [0] => 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+)
+Array
+(
+ [0] => text text text text text text text text text text text text text text text text text text text text
+)
+Array
+(
+)
+Array
+(
+ [0] => line
+
+ [1] => line of text
+
+ [2] => line
+
+ [3] => line of text
+
+ [4] => line
+
+ [5] => line of text
+
+ [6] => line
+
+ [7] => line of text
+
+ [8] => line
+
+ [9] => line of text
+
+ [10] => line
+
+ [11] => line
+)
+*** Testing for return type of file function ***
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+
+--- Done ---
--- /dev/null
+--TEST--
+Testing file() function : error conditions
+--FILE--
+<?php
+/*
+ * Prototype: array file ( string filename [,int use-include_path [,resource context]] );
+ * Description: Reads entire file into an array
+ * Returns the file in an array
+ */
+
+$file_path = dirname(__FILE__);
+
+echo "\n*** Testing error conditions ***";
+$file_handle = fopen($file_path."/file.tmp", "w");
+var_dump( file() ); // Zero No. of args
+
+$filename = $file_path."/file.tmp";
+var_dump( file($filename, $filename, $filename, $filename) ); // more than expected number of arguments
+
+var_dump( file($filename, "INCORRECT_FLAG", NULL) ); // Incorrect flag
+var_dump( file($filename, 10, NULL) ); // Incorrect flag
+var_dump( file( "nofile.tmp" ) ); // non existing filename
+fclose($file_handle);
+
+echo "\n--- Done ---";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink($file_path."/file.tmp");
+
+?>
+--EXPECTF--
+*** Testing error conditions ***
+Warning: file() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: file() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+Warning: file() expects parameter 2 to be long, string given in %s on line %d
+NULL
+array(0) {
+}
+
+Warning: file(nofile.tmp): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+--- Done ---
--- /dev/null
+--TEST--
+Test file_put_contents() and file_get_contents() functions : basic functionality
+--FILE--
+<?php
+
+/* Prototype: string file_get_contents( string $filename[, bool $use_include_path[,
+ * resource $context[, int $offset[, int $maxlen]]]] )
+ * Description: Reads entire file into a string
+ */
+
+/* Prototype: int file_put_contents( string $filename, mixed $data[, int $flags[, resource $context]] )
+ * Description: Write a string to a file
+ */
+
+$file_path = dirname(__FILE__);
+include($file_path."/file.inc");
+
+echo "*** Testing the basic functionality of file_put_contents() and file_get_contents() functions ***\n";
+
+echo "-- Testing with simple valid data file --\n";
+
+$file_name = "/file_put_contents.tmp";
+fill_buffer($text_buffer, "text", 100);
+file_put_contents( $file_path.$file_name, $text_buffer );
+
+var_dump( file_get_contents($file_path.$file_name) );
+
+echo "\n-- Testing with empty file --\n";
+
+$file_name = "/file_put_contents1.tmp";
+file_put_contents( $file_path.$file_name, "");
+var_dump( file_get_contents( $file_path.$file_name ) );
+
+echo "\n*** Done ***";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink($file_path."/file_put_contents.tmp");
+unlink($file_path."/file_put_contents1.tmp");
+?>
+--EXPECTF--
+*** Testing the basic functionality of file_put_contents() and file_get_contents() functions ***
+-- Testing with simple valid data file --
+string(100) "text text text text text text text text text text text text text text text text text text text text "
+
+-- Testing with empty file --
+string(0) ""
+
+*** Done ***
--- /dev/null
+--TEST--
+Test file-get_contents() and file_put_contents() functions : error conditions
+--FILE--
+<?php
+/* Prototype: string file_get_contents( string $filename{, bool $use_include_path[,
+ * resource $context[, int $offset[, int $maxlen]]]] )
+ * Description: Reads entire file into a string
+ */
+
+/* Prototype: int file_put_contents( string $filename, mixed $data[, int $flags[, resource $context]] )
+ * Description: Write a string to a file
+ */
+
+echo "*** Testing error conditions ***\n";
+
+$file_path = dirname(__FILE__);
+
+echo "\n-- Testing with Non-existing file --\n";
+print( file_get_contents("/no/such/file/or/dir") );
+
+echo "\n-- Testing No.of arguments less than expected --\n";
+print( file_get_contents() );
+print( file_put_contents() );
+print( file_put_contents($file_path."/".__FILE__) );
+
+$file_handle = fopen($file_path."/file_put_contents.tmp", "w");
+echo "\n-- Testing No.of arguments greater than expected --\n";
+print( file_put_contents("abc.tmp", 12345, 1, $file_handle, "extra_argument") );
+print( file_get_contents("abc.tmp", false, $file_handle, 1, 2, "extra_argument") );
+
+echo "\n-- Testing for invalid negative maxlen values --";
+file_put_contents($file_path."/file_put_contents1.tmp", "Garbage data in the file");
+var_dump( file_get_contents($file_path."/file_put_contents1.tmp", FALSE, NULL, 0, -5) );
+
+fclose($file_handle);
+
+echo "\n*** Done ***\n";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink($file_path."/file_put_contents.tmp");
+unlink($file_path."/file_put_contents1.tmp");
+
+?>
+--EXPECTF--
+*** Testing error conditions ***
+
+-- Testing with Non-existing file --
+
+Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d
+
+-- Testing No.of arguments less than expected --
+
+Warning: file_get_contents() expects at least 1 parameter, 0 given in %s on line %d
+
+Warning: file_put_contents() expects at least 2 parameters, 0 given in %s on line %d
+
+Warning: file_put_contents() expects at least 2 parameters, 1 given in %s on line %d
+
+-- Testing No.of arguments greater than expected --
+
+Warning: file_put_contents() expects at most 4 parameters, 5 given in %s on line %d
+
+Warning: file_get_contents() expects at most 5 parameters, 6 given in %s on line %d
+
+-- Testing for invalid negative maxlen values --
+Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d
+bool(false)
+
+*** Done ***
--- /dev/null
+--TEST--
+Test file() function : usage variations
+--FILE--
+<?php
+/*
+ * Prototype: array file ( string $filename [,int $flags [,resource $context]] );
+ * Description: Reads entire file into an array
+ * Returns the file in an array
+ */
+
+$file_path = dirname(__FILE__);
+require($file_path."/file.inc");
+$filename = $file_path."/file.tmp";
+
+$data_array = array( "Garbage data", "Gar\nba\nge d\nata", "Gar\n\nbage \n\n data" );
+
+echo "*** Using various flags values with different data in a file\n";
+$count=1;
+foreach( $data_array as $data ) {
+ echo "--Iteration $count --\n";
+ $fh = fopen($filename, "w");
+ fwrite($fh, $data);
+ var_dump( file($filename, FILE_IGNORE_NEW_LINES) );
+ var_dump( file($filename, FILE_SKIP_EMPTY_LINES) );
+ $count++;
+ fclose($fh);
+}
+
+echo "*** Testing with variation in use_include_path argument ***\n";
+$dir = "/file";
+$file_path = dirname(__FILE__).$dir;
+
+mkdir($file_path);
+ini_set( 'include_path', $file_path );
+$filename = $file_path."/file1.tmp";
+
+$buffer_types = array("text", "numeric", "alphanumeric", "text_with_new_line");
+foreach( $buffer_types as $type) {
+ fill_buffer($buffer, $type, 100);
+ file_put_contents($filename, $buffer );
+ var_dump( file("file1.tmp", FILE_USE_INCLUDE_PATH) );
+ var_dump( file($filename, FILE_IGNORE_NEW_LINES) );
+ var_dump( file($filename, FILE_SKIP_EMPTY_LINES) );
+
+}
+
+echo "\n--- Done ---";
+?>
+
+--CLEAN--
+<?php
+// Removing the temporary files and directory
+
+$file_path = dirname(__FILE__);
+unlink($file_path."/file.tmp");
+
+$dir = "/file";
+$file_path = dirname(__FILE__).$dir;
+unlink($file_path."/file1.tmp");
+rmdir($file_path);
+
+?>
+--EXPECTF--
+*** Using various flags values with different data in a file
+--Iteration 1 --
+array(1) {
+ [0]=>
+ string(12) "Garbage data"
+}
+array(1) {
+ [0]=>
+ string(12) "Garbage data"
+}
+--Iteration 2 --
+array(4) {
+ [0]=>
+ string(3) "Gar"
+ [1]=>
+ string(2) "ba"
+ [2]=>
+ string(4) "ge d"
+ [3]=>
+ string(3) "ata"
+}
+array(4) {
+ [0]=>
+ string(4) "Gar
+"
+ [1]=>
+ string(3) "ba
+"
+ [2]=>
+ string(5) "ge d
+"
+ [3]=>
+ string(3) "ata"
+}
+--Iteration 3 --
+array(5) {
+ [0]=>
+ string(3) "Gar"
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(5) "bage "
+ [3]=>
+ string(0) ""
+ [4]=>
+ string(5) " data"
+}
+array(5) {
+ [0]=>
+ string(4) "Gar
+"
+ [1]=>
+ string(1) "
+"
+ [2]=>
+ string(6) "bage
+"
+ [3]=>
+ string(1) "
+"
+ [4]=>
+ string(5) " data"
+}
+*** Testing with variation in use_include_path argument ***
+array(1) {
+ [0]=>
+ string(100) "text text text text text text text text text text text text text text text text text text text text "
+}
+array(1) {
+ [0]=>
+ string(100) "text text text text text text text text text text text text text text text text text text text text "
+}
+array(1) {
+ [0]=>
+ string(100) "text text text text text text text text text text text text text text text text text text text text "
+}
+array(1) {
+ [0]=>
+ string(100) "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+}
+array(1) {
+ [0]=>
+ string(100) "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+}
+array(1) {
+ [0]=>
+ string(100) "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+}
+array(1) {
+ [0]=>
+ string(100) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+}
+array(1) {
+ [0]=>
+ string(100) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+}
+array(1) {
+ [0]=>
+ string(100) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+}
+array(12) {
+ [0]=>
+ string(5) "line
+"
+ [1]=>
+ string(13) "line of text
+"
+ [2]=>
+ string(5) "line
+"
+ [3]=>
+ string(13) "line of text
+"
+ [4]=>
+ string(5) "line
+"
+ [5]=>
+ string(13) "line of text
+"
+ [6]=>
+ string(5) "line
+"
+ [7]=>
+ string(13) "line of text
+"
+ [8]=>
+ string(5) "line
+"
+ [9]=>
+ string(13) "line of text
+"
+ [10]=>
+ string(5) "line
+"
+ [11]=>
+ string(5) "line "
+}
+array(12) {
+ [0]=>
+ string(4) "line"
+ [1]=>
+ string(12) "line of text"
+ [2]=>
+ string(4) "line"
+ [3]=>
+ string(12) "line of text"
+ [4]=>
+ string(4) "line"
+ [5]=>
+ string(12) "line of text"
+ [6]=>
+ string(4) "line"
+ [7]=>
+ string(12) "line of text"
+ [8]=>
+ string(4) "line"
+ [9]=>
+ string(12) "line of text"
+ [10]=>
+ string(4) "line"
+ [11]=>
+ string(5) "line "
+}
+array(12) {
+ [0]=>
+ string(5) "line
+"
+ [1]=>
+ string(13) "line of text
+"
+ [2]=>
+ string(5) "line
+"
+ [3]=>
+ string(13) "line of text
+"
+ [4]=>
+ string(5) "line
+"
+ [5]=>
+ string(13) "line of text
+"
+ [6]=>
+ string(5) "line
+"
+ [7]=>
+ string(13) "line of text
+"
+ [8]=>
+ string(5) "line
+"
+ [9]=>
+ string(13) "line of text
+"
+ [10]=>
+ string(5) "line
+"
+ [11]=>
+ string(5) "line "
+}
+
+--- Done ---
--- /dev/null
+--TEST--
+Test is_executable() function: usage variations
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip.. only for LINUX');
+}
+?>
+--FILE--
+<?php
+/* Prototype: bool is_executable ( string $filename );
+ Description: Tells whether the filename is executable
+*/
+
+require dirname(__FILE__).'/file.inc';
+echo "*** Testing is_executable(): usage variations ***\n";
+
+$file_path = dirname(__FILE__);
+mkdir("$file_path/is_executable");
+
+// create a new temporary file
+$fp = fopen("$file_path/is_executable/bar.tmp", "w");
+fclose($fp);
+
+/* array of files checked to see if they are executable files
+ using is_executable() function */
+$files_arr = array(
+ "$file_path/is_executable/bar.tmp",
+
+ /* Testing a file with trailing slash */
+ "$file_path/is_executable/bar.tmp/",
+
+ /* Testing file with double slashes */
+ "$file_path/is_executable//bar.tmp",
+ "$file_path/is_executable/*.tmp",
+ "$file_path/is_executable/b*.tmp",
+
+ /* Testing Binary safe */
+ "$file_path/is_executable".chr(0)."bar.temp",
+ "$file_path".chr(0)."is_executable/bar.temp",
+ "$file_path/is_executablex000/",
+
+ /* Testing directories */
+ ".", // current directory, exp: bool(true)
+ "$file_path/is_executable" // temp directory, exp: bool(true)
+);
+$counter = 1;
+/* loop through to test each element in the above array
+ is an executable file */
+foreach($files_arr as $file) {
+ echo "-- Iteration $counter --\n";
+ var_dump( is_executable($file) );
+ $counter++;
+ clearstatcache();
+}
+
+echo "\n*** Testing is_executable() on directory without execute permission ***\n";
+chmod("$file_path/is_executable", 0444);
+var_dump( is_executable("$file_path/is_executable") ); // exp: bool(false)
+chmod("$file_path/is_executable", 0777); // chmod to enable deletion of directory
+
+echo "\n*** Testing miscelleneous input for is_executable() function ***\n";
+$name_prefix = "is_executable";
+create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
+create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
+create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
+create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 4);
+create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
+create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
+create_files(dirname(__FILE__), 1, "text", 0714, 1, "w", $name_prefix, 7);
+create_files(dirname(__FILE__), 1, "numeric", 0744, 1, "w", $name_prefix, 8);
+create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
+create_files(dirname(__FILE__), 1, "text", 0712, 1, "w", $name_prefix, 10);
+
+$files = array (
+ "$file_path/is_executable1.tmp",
+ "$file_path/is_executable2.tmp",
+ "$file_path/is_executable3.tmp",
+ "$file_path/is_executable4.tmp",
+ "$file_path/is_executable5.tmp",
+ "$file_path/is_executable6.tmp",
+ "$file_path/is_executable7.tmp",
+ "$file_path/is_executable8.tmp",
+ "$file_path/is_executable9.tmp",
+ "$file_path/is_executable10.tmp",
+);
+$counter = 1;
+/* loop through to test each element in the above array
+ is an executable file */
+foreach($files as $file) {
+ echo "-- Iteration $counter --\n";
+ var_dump( is_executable($file) );
+ $counter++;
+ clearstatcache();
+}
+
+// change all file's permissions to 777 before deleting
+change_file_perms($file_path, 10, 0777, $name_prefix);
+delete_files($file_path, 10, $name_prefix);
+
+$file_handle = fopen(__FILE__, "r");
+unset($file_handle);
+
+echo "\n*** Testing is_executable() on invalid files ***\n";
+$invalid_files = array(
+ 0,
+ 1234,
+ -2.34555,
+ "string",
+ TRUE,
+ FALSE,
+ NULL,
+ @array(),
+ @$file_handle
+);
+/* loop through to test each element in the above array
+ is an executable file */
+foreach( $invalid_files as $invalid_file ) {
+ var_dump( is_executable($invalid_file) );
+ clearstatcache();
+}
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__)."/is_executable/bar.tmp");
+rmdir(dirname(__FILE__)."/is_executable/");
+?>
+--EXPECTF--
+*** Testing is_executable(): usage variations ***
+-- Iteration 1 --
+bool(false)
+-- Iteration 2 --
+bool(false)
+-- Iteration 3 --
+bool(false)
+-- Iteration 4 --
+bool(false)
+-- Iteration 5 --
+bool(false)
+-- Iteration 6 --
+bool(true)
+-- Iteration 7 --
+bool(true)
+-- Iteration 8 --
+bool(false)
+-- Iteration 9 --
+bool(true)
+-- Iteration 10 --
+bool(true)
+
+*** Testing is_executable() on directory without execute permission ***
+bool(false)
+
+*** Testing miscelleneous input for is_executable() function ***
+-- Iteration 1 --
+bool(true)
+-- Iteration 2 --
+bool(true)
+-- Iteration 3 --
+bool(true)
+-- Iteration 4 --
+bool(true)
+-- Iteration 5 --
+bool(false)
+-- Iteration 6 --
+bool(true)
+-- Iteration 7 --
+bool(true)
+-- Iteration 8 --
+bool(true)
+-- Iteration 9 --
+bool(false)
+-- Iteration 10 --
+bool(true)
+
+*** Testing is_executable() on invalid files ***
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test is_readable() function: usage variations
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip.. only for LINUX');
+}
+?>
+--FILE--
+<?php
+/* Prototype: bool is_readable ( string $filename );
+ Description: Tells whether the filename is readable.
+*/
+
+require dirname(__FILE__).'/file.inc';
+echo "*** Testing is_readable(): usage variations ***\n";
+
+$file_path = dirname(__FILE__);
+mkdir("$file_path/is_readable");
+
+// create a new temporary file
+$fp = fopen("$file_path/is_readable/bar.tmp", "w");
+fclose($fp);
+
+/* array of files to be tested if they are readable by using
+ is_readable() function */
+$files_arr = array(
+ "$file_path/is_readable/bar.tmp",
+
+ /* Testing a file trailing slash */
+ "$file_path/is_readable/bar.tmp/",
+
+ /* Testing file with double slashes */
+ "$file_path/is_readable//bar.tmp",
+ "$file_path//is_readable//bar.tmp",
+ "$file_path/is_readable/*.tmp",
+ "$file_path/is_readable/b*.tmp",
+
+ /* Testing Binary safe */
+ "$file_path/is_readable".chr(0)."bar.tmp",
+ "$file_path".chr(0)."is_readable/bar.tmp",
+ "$file_path".chr(0)."is_readable/bar.tmp",
+
+ /* Testing directories */
+ ".", // current directory, exp: bool(true)
+ "$file_path/is_readable" // temp directory, exp: bool(true)
+);
+$counter = 1;
+/* loop through to test each element in the above array
+ is a writable file */
+foreach($files_arr as $file) {
+ echo "-- Iteration $counter --\n";
+ var_dump( is_readable($file) );
+ $counter++;
+ clearstatcache();
+}
+
+echo "\n*** Testing is_readable() on directory without read permission ***\n";
+chmod("$file_path/is_readable", 0001);
+var_dump( is_readable("$file_path/is_readable") ); // exp: bool(false)
+chmod("$file_path/is_readable", 0777); // chmod to enable deletion of directory
+
+echo "\n*** Testing miscelleneous input for is_readable() function ***\n";
+$name_prefix = "is_readable";
+create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
+create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
+create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
+create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4);
+create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
+create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
+create_files(dirname(__FILE__), 1, "text", 0411, 1, "w", $name_prefix, 7);
+create_files(dirname(__FILE__), 1, "numeric", 0444, 1, "w", $name_prefix, 8);
+create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
+create_files(dirname(__FILE__), 1, "text", 0422, 1, "w", $name_prefix, 10);
+
+$files = array (
+ "$file_path/is_readable1.tmp",
+ "$file_path/is_readable2.tmp",
+ "$file_path/is_readable3.tmp",
+ "$file_path/is_readable4.tmp",
+ "$file_path/is_readable5.tmp",
+ "$file_path/is_readable6.tmp",
+ "$file_path/is_readable7.tmp",
+ "$file_path/is_readable8.tmp",
+ "$file_path/is_readable9.tmp",
+ "$file_path/is_readable10.tmp"
+);
+$counter = 1;
+/* loop through to test each element in the above array
+ is a readable file */
+foreach($files as $file) {
+ echo "-- Iteration $counter --\n";
+ var_dump( is_readable($file) );
+ $counter++;
+ clearstatcache();
+}
+
+// change all file's permissions to 777 before deleting
+change_file_perms($file_path, 10, 0777, $name_prefix);
+delete_files($file_path, 10, $name_prefix);
+
+$file_handle = fopen(__FILE__, "r");
+unset($file_handle);
+
+echo "\n*** Testing is_readable() on miscelleneous filenames ***\n";
+$misc_files = array(
+ 0,
+ 1234,
+ -2.34555,
+ "string",
+ TRUE,
+ FALSE,
+ NULL,
+ @array(),
+ @$file_handle
+);
+/* loop through to test each element in the above array
+ is a readable file */
+foreach( $misc_files as $misc_file ) {
+ var_dump( is_readable($misc_file) );
+ clearstatcache();
+}
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__)."/is_readable/bar.tmp");
+rmdir(dirname(__FILE__)."/is_readable/");
+?>
+--EXPECTF--
+*** Testing is_readable(): usage variations ***
+-- Iteration 1 --
+bool(true)
+-- Iteration 2 --
+bool(false)
+-- Iteration 3 --
+bool(true)
+-- Iteration 4 --
+bool(true)
+-- Iteration 5 --
+bool(false)
+-- Iteration 6 --
+bool(false)
+-- Iteration 7 --
+bool(true)
+-- Iteration 8 --
+bool(true)
+-- Iteration 9 --
+bool(true)
+-- Iteration 10 --
+bool(true)
+-- Iteration 11 --
+bool(true)
+
+*** Testing is_readable() on directory without read permission ***
+bool(false)
+
+*** Testing miscelleneous input for is_readable() function ***
+-- Iteration 1 --
+bool(true)
+-- Iteration 2 --
+bool(true)
+-- Iteration 3 --
+bool(true)
+-- Iteration 4 --
+bool(true)
+-- Iteration 5 --
+bool(false)
+-- Iteration 6 --
+bool(true)
+-- Iteration 7 --
+bool(true)
+-- Iteration 8 --
+bool(true)
+-- Iteration 9 --
+bool(true)
+-- Iteration 10 --
+bool(true)
+
+*** Testing is_readable() on miscelleneous filenames ***
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test is_writable() and its alias is_writeable() function: usage variations
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip.. only on LINUX');
+}
+?>
+--FILE--
+<?php
+/* Prototype: bool is_writable ( string $filename );
+ Description: Tells whether the filename is writable.
+
+ is_writeable() is an alias of is_writable()
+*/
+
+require dirname(__FILE__).'/file.inc';
+echo "*** Testing is_writable(): usage variations ***\n";
+
+$file_path = dirname(__FILE__);
+mkdir("$file_path/is_writable");
+
+// create a new temporary file
+$fp = fopen("$file_path/is_writable/bar.tmp", "w");
+fclose($fp);
+
+/* array of files to be tested to check if they are writable
+ using is_writable() function */
+$files_arr = array(
+ "$file_path/is_writable/bar.tmp",
+
+ /* Testing a file trailing slash */
+ "$file_path/is_writable/bar.tmp/",
+
+ /* Testing file with double slashes */
+ "$file_path/is_writable//bar.tmp",
+ "$file_path//is_writable//bar.tmp",
+ "$file_path/is_writable/*.tmp",
+ "$file_path/is_writable/b*.tmp",
+
+ /* Testing Binary safe */
+ "$file_path/is_writable".chr(0)."bar.tmp",
+ "$file_path".chr(0)."is_writable/bar.tmp",
+ "$file_path".chr(0)."is_writable/bar.tmp",
+
+ /* Testing directories */
+ ".", // current directory, exp: bool(true)
+ "$file_path/is_writable" // temp directory, exp: bool(true)
+);
+$counter = 1;
+/* loop through to test each element in the above array
+ is a writable file */
+foreach($files_arr as $file) {
+ echo "-- Iteration $counter --\n";
+ var_dump( is_writable($file) );
+ var_dump( is_writeable($file) );
+ $counter++;
+ clearstatcache();
+}
+
+echo "\n*** Testing is_writable() on directory without write permission ***\n";
+chmod("$file_path/is_writable", 0004);
+var_dump( is_writable("$file_path/is_writable") ); // exp: bool(false)
+var_dump( is_writeable("$file_path/is_writable") ); // exp: bool(false)
+chmod("$file_path/is_writable", 0777); // chmod to enable deletion of directory
+
+echo "\n*** Testing miscelleneous input for is_writable() function ***\n";
+$name_prefix = "is_writable";
+create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $name_prefix, 1);
+create_files(dirname(__FILE__), 1, "text", 0755, 1, "w", $name_prefix, 2);
+create_files(dirname(__FILE__), 1, "empty", 0755, 1, "w", $name_prefix, 3);
+create_files(dirname(__FILE__), 1, "numeric", 0555, 1, "w", $name_prefix, 4);
+create_files(dirname(__FILE__), 1, "text", 0222, 1, "w", $name_prefix, 5);
+create_files(dirname(__FILE__), 1, "numeric", 0711, 1, "w", $name_prefix, 6);
+create_files(dirname(__FILE__), 1, "text", 0114, 1, "w", $name_prefix, 7);
+create_files(dirname(__FILE__), 1, "numeric", 0244, 1, "w", $name_prefix, 8);
+create_files(dirname(__FILE__), 1, "text", 0421, 1, "w", $name_prefix, 9);
+create_files(dirname(__FILE__), 1, "text", 0422, 1, "w", $name_prefix, 10);
+
+$misc_files = array (
+ "$file_path/is_writable1.tmp",
+ "$file_path/is_writable2.tmp",
+ "$file_path/is_writable3.tmp",
+ "$file_path/is_writable4.tmp",
+ "$file_path/is_writable5.tmp",
+ "$file_path/is_writable6.tmp",
+ "$file_path/is_writable7.tmp",
+ "$file_path/is_writable8.tmp",
+ "$file_path/is_writable9.tmp",
+ "$file_path/is_writable10.tmp"
+);
+
+$counter = 1;
+/* loop through to test each element in the above array
+ is a writable file */
+foreach($misc_files as $misc_file) {
+ echo "-- Iteration $counter --\n";
+ var_dump( is_writable($misc_file) );
+ var_dump( is_writeable($misc_file) );
+ $counter++;
+ clearstatcache();
+}
+
+// change all file's permissions to 777 before deleting
+change_file_perms($file_path, 10, 0777, $name_prefix);
+delete_files($file_path, 10, $name_prefix);
+
+$file_handle = fopen(__FILE__, "r");
+unset($file_handle);
+
+clearstatcache();
+echo "\n*** Testing is_writable() on miscelleneous filenames ***\n";
+$misc_files = array(
+ 0,
+ 1234,
+ -2.34555,
+ "string",
+ TRUE,
+ FALSE,
+ NULL,
+ @array(),
+ @$file_handle
+);
+/* loop through to test each element in the above array
+ is a writable file */
+foreach( $misc_files as $misc_file ) {
+ var_dump( is_writable($misc_file) );
+ var_dump( is_writeable($misc_file) );
+ clearstatcache();
+}
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__)."/is_writable/bar.tmp");
+rmdir(dirname(__FILE__)."/is_writable/");
+?>
+--EXPECTF--
+*** Testing is_writable(): usage variations ***
+-- Iteration 1 --
+bool(true)
+bool(true)
+-- Iteration 2 --
+bool(false)
+bool(false)
+-- Iteration 3 --
+bool(true)
+bool(true)
+-- Iteration 4 --
+bool(true)
+bool(true)
+-- Iteration 5 --
+bool(false)
+bool(false)
+-- Iteration 6 --
+bool(false)
+bool(false)
+-- Iteration 7 --
+bool(true)
+bool(true)
+-- Iteration 8 --
+bool(true)
+bool(true)
+-- Iteration 9 --
+bool(true)
+bool(true)
+-- Iteration 10 --
+bool(true)
+bool(true)
+-- Iteration 11 --
+bool(true)
+bool(true)
+
+*** Testing is_writable() on directory without write permission ***
+bool(false)
+bool(false)
+
+*** Testing miscelleneous input for is_writable() function ***
+-- Iteration 1 --
+bool(true)
+bool(true)
+-- Iteration 2 --
+bool(true)
+bool(true)
+-- Iteration 3 --
+bool(true)
+bool(true)
+-- Iteration 4 --
+bool(false)
+bool(false)
+-- Iteration 5 --
+bool(true)
+bool(true)
+-- Iteration 6 --
+bool(true)
+bool(true)
+-- Iteration 7 --
+bool(false)
+bool(false)
+-- Iteration 8 --
+bool(true)
+bool(true)
+-- Iteration 9 --
+bool(false)
+bool(false)
+-- Iteration 10 --
+bool(false)
+bool(false)
+
+*** Testing is_writable() on miscelleneous filenames ***
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+bool(false)
+bool(false)
+Done